znuff's notepad

OSCam Startup Script for Ubuntu and other linux distros (systemd compatible)

Updated on 14.05.2017

Create a file called /etc/init.d/oscam with the following contents:

#!/bin/sh
### BEGIN INIT INFO
# Provides: oscam
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop service oscam
# Description: oscam
### END INIT INFO

DAEMON=/usr/local/bin/oscam
PIDFILE=/var/run/oscam.pid
DAEMON_OPTS="-p 4096 -r 2 -B ${PIDFILE} -c /usr/local/etc/ -t /tmp/.oscam"

test -x ${DAEMON} || exit 0

. /lib/lsb/init-functions

case "$1" in
  start)
    log_daemon_msg "Starting OScam..."
    /sbin/start-stop-daemon --start --quiet --background --name oscam --exec ${DAEMON} -- ${DAEMON_OPTS}
    log_end_msg $?
    ;;
  stop)
    log_daemon_msg "Stopping OScam..."
    /sbin/start-stop-daemon -R 5 --stop --name oscam --exec ${DAEMON}
    log_end_msg $?
    ;;
  restart)
    $0 stop
    $0 start
    ;;
  force-reload)
    $0 stop
    /bin/kill -9 `pidof oscam`
    /usr/bin/killall -9 oscam
    $0 start
    ;;
  *)
    echo "Usage: /etc/init.d/oscam {start|stop|restart|force-reload}"
    exit 1
    ;;
esac

This assumes that you have the oscam binary located in /usr/local/bin/oscam. Remember you have to create this file as the root user.

To “enable” the script and the starting up of oscam on reboot, use the following commands on Ubuntu/Debian:

sudo chmod +x /etc/init.d/oscam
sudo update-rc.d oscam defaults

systemd compatibility

The script will also work on systemd systems (like Ubuntu 16.04 and so on).

To force systemd to detect the service, you have to do:

systemctl daemon-reload

To enable the system to start at boot:

systemctl enable oscam

crontab checks

Furthermore, for a simple crontab script to check if oscam has crashed and didn’t restart by itself, let’s create a file and call it /usr/local/bin/oscamchk:

#!/bin/bash
PIDFILE=/var/run/oscam.pid
if (kill -0 `cat $PIDFILE`)
   then
      echo "it's alive!" > /dev/null
   else
      rm $PIDFILE
      /etc/init.d/oscam start > /dev/null
      echo "OSCAM restarted at `date`" >> /var/log/oscam-crash.log
fi

And let’s make this run every minute:

sudo chmod +x /usr/local/bin/oscamchk
sudo crontab -e

Once the crontab editor has started, add the following line:

* * * * * /usr/local/bin/oscamchk >/dev/null 2>&1
Exit mobile version