systemd script for OSCam

OSCam as it stands uses the old sysinit (/etc/init.d/oscam) script to control its daemon. I wanted to leverage a bit of functionality within systemd, the ability to automatically start a crashed process, so decided to convert the “old” init.d script into a systemd script. Starting and stopping the OSCam daemon is no different to the old sysinit scripts, as most distros are guiding people towards systemd by outputting the equivalent systemd command when you start or stop a service. For example, if I run the following on my Debian box;

/etc/init.d/oscam stop

Systemd intervenes and shows me how I should control the daemon;

systemctl restart oscam

So even though no systemd script exists for OSCam on my box, Debian treats the sysinit script as a systemd script, but only as far as starting and stopping the script goes – it does not give the extra benefits of systemd which as above include automatic restart of failed services.

So, below is a systemd script which can control OSCam – you might need to change the binary and PID file paths but this works on my system. Simply create a new systemd script;

sudo nano /etc/systemd/system/oscam.service

…and add the following content…


ExecStart=/usr/local/bin/oscam -b -B /var/run/
ExecStop=/usr/bin/rm /var/run/


This will start OSCam in daemon mode (the -b flag) and then create a PID file for the deamon (-B) at /var/run/ – as mentioned above, you might need to alter the paths but this is the basic systemd service required to control OSCam.

Once you’ve created the service, you need to reload the systemd daemons by issuing;

sudo systemctl daemon-reload

…then you can simply start the OSCam daemon by issuing;

sudo systemctl start oscam

You can check OSCam is running by visiting the web interface or by running;

sudo systemctl status oscam

…where you should see something like this;

 oscam.service - OScam
   Loaded: loaded (/etc/systemd/system/oscam.service; disabled; vendor preset: enabled)
   Active: active (running) since Fri 2016-09-30 11:40:30 BST; 10min ago
  Process: 21828 ExecStop=/usr/bin/rm /var/run/ (code=exited, status=203/EXEC)
  Process: 24126 ExecStart=/usr/local/bin/oscam -b -B /var/run/ (code=exited, status=0/SUCCESS)
 Main PID: 24131 (oscam)
   CGroup: /system.slice/oscam.service
           ├─24130 /usr/local/bin/oscam -b -B /var/run/
           └─24131 /usr/local/bin/oscam -b -B /var/run/

One final thing is to ensure OSCam starts on boot, to do that, issue the following command;

sudo systemctl enable oscam.service

And that’s it!

Happy viewing!

Tagged with: , , , , ,