Autor Subiect: OSCam Startup Script for Ubuntu and other linux distros  (Citit de 866 ori)

0 Membri şi 1 Vizitator vizualizează acest subiect.

Offline catalin

  • Administrator
  • Teacher
  • *****
  • Mesaje postate: 116
  • Karma: +0/-0
  • Gen: Bărbat
    • Filmul Nuntii Tale!
OSCam Startup Script for Ubuntu and other linux distros
« : Iulie 05, 2014, 09:36:51 a.m. »
Create a file called /etc/init.d/oscam with the following contents:

#!/bin/sh
 
DAEMON=/usr/local/bin/oscam
PIDFILE=/var/run/oscam.pid
DAEMON_OPTS="-p 1024 -w 5 -r 2 -B ${PIDFILE}"
 
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  --exec ${DAEMON} -- ${DAEMON_OPTS}
   log_end_msg $?
    ;;
  stop)
   log_daemon_msg "Stopping OScam..."
   /sbin/start-stop-daemon --stop --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

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:

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