[Newark] Running a simple script as a service
Craig Lynch
c_lynch87 at outlook.com
Mon Mar 1 15:36:38 UTC 2021
On 21/03/01 12:24pm, Richard M Eggleston via Newark wrote:
> Hi All,
>
> I realise this is fairly low level stuff, and I have spent a fair bit of time on search engines and forums, but my specific question isn’t being addressed
>
>
> I have been running sickgear as a PVR (I know about torrents and copyright breach..don’t @me, I’m a big boy) however it starts by running the following from a command line
>
> Cd /opt/sickgear
> Sudo -u python3 ./sickgear.py
>
> And that works nicely
>
> So being a good soldier,(i.e Lazy) I combined these into a bash script (called runsickgear.sh)
>
> #!/bin/bash
> Cd /opt/sickgear
> Sudo -u python3 ./sickgear.py
>
> Which can be run from CL and works beautifully..
>
> bash runsickgear.sh
>
> Now me, being me, I don’t want the hassle of running no lousy scripts, and I don’t want any untidy terminals left open either (OCD? No not me)
> I would like this to run as a service at boot time, and Be stopped, started and messed around with using
>
> Sudo systemctl sickgear {stop/start/enable/halt & catchfire}
>
> SO I copy the runsickgear.sh script to
>
> /usr/bin/sickgear/runsickgear.sh
>
> Generate a file /etc/systemd/system/sickgear.service
> Which looks like
>
>
> [Unit]
> Description=sickgear service
>
> [Service]
> ExecStart=/usr/bin/sickgear/runsickgear.sh
>
> [Install]
> WantedBy=Multi-User.Target
>
> Now according to Google, etc after I run
> Sudo systemctl daemon-reload
> Then I should be able to do systemctl enable etc
>
> But I can’t,
>
> And the logs seem to give me no insight, and the Ubuntu forums seem more interested in angels dancing on heads of pins or whether
> I am fairly sure this is a syntax error somewhere, but what ever I do, it doesn’t seem to work.. Given my desk and keyboard now have forehead shaped dents in need help. Google has loads o examples, and I have worked through many of them (Mostly look the same as the ones I’ve shown)
>
> Any bright ideas?
>
> Cheers
> Richard
>
> --
> Newark mailing list
> Newark at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/newark
I'd suggest not using the shell script if you're installing as a system service as they typically run with root by default but you can set a user within the service file and setting a working directory under systemd.
So, within your service file:
[Service]
User=<username>
WorkingDirectory=<directory required>
It's also always worth checking journalctl for error reports on services.
C.
More information about the Newark
mailing list