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
small typo here:
DEAMON_OPTS=”-b -p 255 -w 5 -r 2″
should be DAEMON_OPTS
Fixed, thanks.
Thank you for the script !!!
I am a total Linux newbie.
I am a bit confused here and I was hoping you could enlighten me.
The binary that I am using for Oscam on my Debian PC is called “Oscam.x86” and not just “oscam”.
Could you please tell me how I should change the script to reflect that ?
The binary I am using is located in the same folder as your binary in your example.
You need to change this line:
DAEMON=/usr/local/bin/oscam
hi… nice script. ty so much. but, what is oscam -b -p 255 -w 5 -r 2 means? thanks for the explaination
Woah, sorry I’m seeing this so late
-b, --daemon | Start in the background as daemon.
-p, --pending-ecm <num> | Set the maximum number of pending ECM packets.
. Default: 32 Max: 255
-w, --wait <secs> | Set how much seconds to wait at startup for the
. system clock to be set correctly. Default: 60
-r, --restart <level> | Set restart level:
. 0 - Restart disabled (exit on restart request).
. 1 - WebIf restart is active (default).
. 2 - Like 1, but also restart on segfaults.
hello my friend,
with putty
type: sudo /etc/init.d/oscam restart
the answer is not good
Here’s what its gives:
root@ubuntu:~# sudo /etc/init.d/oscam restart
* Stopping OScam… [ OK ]
* Starting OScam… [fail]
oscam is blocked !!!!
can correct you this error?
Best regards
I would need more info. Is your oscam binary located at /usr/local/bin/oscam?
can you type /usr/local/bin/oscam –help and see what you get back?
root@tonio:~# /usr/local/bin/oscam –help
___ ____ ___
/ _ / ___| / __|__ _ _ __ ___
| | | ___ | | / _` | ‘_ ` _
| |_| |___) | |_| (_| | | | | | |
___/|____/ _____,_|_| |_| |_|
OSCam cardserver v1.20-unstable_svn, build r9872 (x86_64-linux-gnu)
Copyright (C) 2009-2013 OSCam developers.
This program is distributed under GPLv3.
OSCam is based on Streamboard mp-cardserver v0.9d written by dukat
Visit http://www.streamboard.tv/oscam/ for more details.
ConfigDir : /usr/local/etc
Usage: oscam [parameters]
Directories:
-c, –config-dir | Read configuration files from .
. Default: /usr/local/etc
-t, –temp-dir | Set temporary directory to .
. Default: /tmp/.oscam
Startup:
-b, –daemon | Start in the background as daemon.
-B, –pidfile | Create pidfile when starting.
-r, –restart | Set restart level:
. 0 – Restart disabled (exit on restart request).
. 1 – WebIf restart is active (default).
. 2 – Like 1, but also restart on segfaults.
-w, –wait | Set how much seconds to wait at startup for the
. system clock to be set correctly. Default: 60
Logging:
-I, –syslog-ident | Set syslog ident. Default: oscam
-S, –show-sensitive | Do not filter sensitive info (card serials, boxids)
. from the logs.
-d, –debug | Set debug level mask used for logging:
. 0 – No extra debugging (default).
. 1 – Detailed error messages.
. 2 – ATR parsing info, ECM, EMM and CW dumps.
. 4 – Traffic from/to the reader.
. 8 – Traffic from/to the clients.
. 16 – Traffic to the reader-device on IFD layer.
. 32 – Traffic to the reader-device on I/O layer.
. 64 – EMM logging.
. 128 – DVBAPI logging.
. 256 – Loadbalancer logging.
. 512 – CACHEEX logging.
. 1024 – Client ECM logging.
. 2048 – CSP logging.
. 4096 – CWC logging.
. 65535 – Debug all.
Settings:
-p, –pending-ecm | Set the maximum number of pending ECM packets.
. Default: 32 Max: 4096
-u, –utf8 | Enable WebIf support for UTF-8 charset.
Debug parameters:
-a, –crash-dump | Write oscam.crash file on segfault. This option
. needs GDB to be installed and OSCam executable to
. contain the debug information (run oscam-XXXX.debug)
-s, –capture-segfaults | Capture segmentation faults.
-g, –gcollect | Garbage collector debug mode:
. 1 – Immediate free.
. 2 – Check for double frees.
Information:
-h, –help | Show command line help text.
-V, –build-info | Show OSCam binary configuration and version.
Hello
my oscam bin is in /usr/local/bin/
In your line 29, you have
/usr/bin/killall-9 oscam !!!!
should we put — / usr/local/bin/killall – 9 oscam
regards
If your “killall” is in /usr/local/bin, you have serious issues.
OK, thanks I understood this line
regards
Una vez que el editor de crontab ha comenzado, agregue la siguiente línea: Pero esa linea donde la copio ?? que archivo ?? bueno ojala me puedan ayudar . saludos
1* * * * * /usr/local/bin/oscamchk >/dev/null 2>&1 EsESa linea
No idea what you just said.
Hi
Can You add info please how to start and check 2 instances of oscam .
BR
MB