[Newark] Running a simple script as a service

Richard M Eggleston Richard at richardeggleston.co.uk
Mon Mar 1 21:39:05 UTC 2021


Hi Guys,
Well it turned out it was a permissions thing, Using chmod u+x on the file worked (As well as a bit of swearing and a silent prayer to St Linus of Helsinki 
I had a play with Craigs suggestions and it also seems to work, but I am unclear about the advantages.
Thanks for the help..and if anyone is into watching torrented TV, I can recommend this as away to do it lazily

Cheers

Richard


> On 1 Mar 2021, at 15:36, Craig Lynch via Newark <newark at mailman.lug.org.uk> wrote:
> 
> 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.
> 
> -- 
> Newark mailing list
> Newark at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/newark




More information about the Newark mailing list