Ofline
Hello Linux lovers
I decided to write a small tutorial and show you my method of starting and stopping the Oscam in my Linux. And also a script that will keep it alive in case it crashes or shows one of 2 known errors (ins_40 and deadlock).
You are free to change the script and improve it. I would be glad to implement some new stuff to it. I am using this method for long time and it works great for me!!
Paths and file names are used as sample only. You can change it.
This was tested on Debian Linux, but it should work on others too.
Step 1:
Put your oscam binary to this path and name it like this:
And put your all config files to this same folder:
Don't forget to give 755 permissions to oscam.x86:
Step 2:
Create a script that will easily control start/stop of your oscam and name it oscript. I am using vi as editor. You can use any editor you wish:
and then paste this text to the file:
* I prefer to run kill command before starting the oscam. Just in case oscam is already running when you execute start command.
Don't forget to give 755 permissions to oscript:
Create symbolic link so you can easily use this script from any location:
Now you can simply start, stop or restart oscam from any directory by simply typing:
Step 3:
Now you need a script that will control your Oscam and keep it running all the time. Create the script and name it check_os:
Don't forget to give 755 permissions to check_os script:
and then paste this text to the file:
As you can see in the text, my oscam log is located in /var/log directory.
This means that you need this line in your "oscam.config" file:
Also, every restart by this script will be recorded in this file:
It will include time stamp and reason for restart so you can have trace of it.
Step 4:
Now you need a crontab entry that will run all the time in the background and check your oscam status. I prefer to run it every 15 minutes, but you can change it of course:
and add this line:
Step 5:
Add this line to your startup file. In Debian it is "/etc/rc.local"
Step 6:
ENJOY!!!
I decided to write a small tutorial and show you my method of starting and stopping the Oscam in my Linux. And also a script that will keep it alive in case it crashes or shows one of 2 known errors (ins_40 and deadlock).
You are free to change the script and improve it. I would be glad to implement some new stuff to it. I am using this method for long time and it works great for me!!
Paths and file names are used as sample only. You can change it.
This was tested on Debian Linux, but it should work on others too.
Step 1:
Put your oscam binary to this path and name it like this:
/emu/oscam/oscam.x86
And put your all config files to this same folder:
/emu/oscam
Don't forget to give 755 permissions to oscam.x86:
chmod 755 /emu/oscam/oscam.x86
Step 2:
Create a script that will easily control start/stop of your oscam and name it oscript. I am using vi as editor. You can use any editor you wish:
vi /emu/oscam/oscript
and then paste this text to the file:
#!/bin/sh
CAMNAME="Oscam Server"
# end
# This method starts Oscam
start_cam ()
{
pkill -9 oscam.x86
sleep 2
/emu/oscam/oscam.x86 -c /emu/oscam &
}
# This method stops Oscam
stop_cam ()
{
pkill -9 oscam.x86
}
case "$1" in
start)
echo "[SCRIPT] $1: $CAMNAME"
start_cam
;;
stop)
echo "[SCRIPT] $1: $CAMNAME"
stop_cam
;;
restart)
echo "Restaring $CAMNAME"
stop_cam
sleep 7
start_cam
;;
*)
"$0" stop
exit 1
;;
esac
exit 0
* I prefer to run kill command before starting the oscam. Just in case oscam is already running when you execute start command.
Don't forget to give 755 permissions to oscript:
chmod 755 /emu/oscam/oscript
Create symbolic link so you can easily use this script from any location:
ln /emu/oscam/oscript /bin/oscript
Now you can simply start, stop or restart oscam from any directory by simply typing:
oscript start
oscript stop
oscript restart
Step 3:
Now you need a script that will control your Oscam and keep it running all the time. Create the script and name it check_os:
vi /emu/oscam/check_os
Don't forget to give 755 permissions to check_os script:
chmod 755 /emu/oscam/check_os
and then paste this text to the file:
#!/bin/bash
if ! ps x |grep -v grep |grep -c /emu/oscam/oscam.x86 >/dev/null
then
oscript start
echo `date "+%d/%m/%y %R process was not working"` >> /var/log/oscam_restart_log
# This part above will check if there is NO oscam process running.
# And if this condition it truth, it will start it and write to log.
# Log entry will contain time stamp and reason of execution (process not working)
# If first condition in not truth (oscam was running), go further to next condition.
elif
tail -8 /var/log/oscam.log |grep -v grep |grep -c ins40 >/dev/null
then
oscript restart
echo `date "+%d/%m/%y %R ins40 error detected"` >> /var/log/oscam_restart_log
elif
tail -8 /var/log/oscam.log |grep -v grep |grep -c deadlock >/dev/null
then
oscript restart
echo `date "+%d/%m/%y %R deadlock error detected"` >> /var/log/oscam_restart_log
# Those 2 conditions will look for 2 common errors in Oscam: "ins40" and "deadlock"
# If last 8 lines of your oscam.log contain any of those errors, it will restart oscam.
# Log entries will include the exact reason of restart.
# ins40 error is random error that will keep oscam running but no CWs returned.
# deadlock is older error that appear if you use CCcam protocol in oscam.server
else
echo "ok"
# If oscam passes all conditions and all is OK, it will simply echo "ok" :-)
fi
# ENJOY - supermariocs
As you can see in the text, my oscam log is located in /var/log directory.
This means that you need this line in your "oscam.config" file:
logfile = /var/log/oscam.log
Also, every restart by this script will be recorded in this file:
/var/log/oscam_restart_log
It will include time stamp and reason for restart so you can have trace of it.
Step 4:
Now you need a crontab entry that will run all the time in the background and check your oscam status. I prefer to run it every 15 minutes, but you can change it of course:
vi /etc/crontab
and add this line:
*/15 * * * * root /emu/oscam/check_os >/dev/null
Step 5:
Add this line to your startup file. In Debian it is "/etc/rc.local"
/bin/oscript start &
Step 6:
ENJOY!!!