Welcome!

Welcome to Satlover forums, full of great people, ideas and excitement.

Please register if you would like to take part. link..

Register Now

Alert: Don't Use Hotmail Email Accounts for registration

Collapse

Before Access to all Forums and Trial accounts you must need to activate your account Email address

Tutorial: Oscam keep alive script and start/stop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • supermariocs
    Member
    • Aug 2011
    • 38

    Tutorial: Oscam keep alive script and start/stop

    Hello satlovers.

    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:
    Code:
    /emu/oscam/oscam.x86
    And put your all config files to this same folder:
    Code:
    /emu/oscam
    Don't forget to give 755 permissions to oscam.x86:
    Code:
    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:
    Code:
    vi /emu/oscam/oscript
    and then paste this text to the file:
    Code:
    #!/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:
    Code:
    chmod 755 /emu/oscam/oscript
    Create symbolic link so you can easily use this script from any location:
    Code:
    ln /emu/oscam/oscript /bin/oscript
    Now you can simply start, stop or restart oscam from any directory by simply typing:
    Code:
    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:
    Code:
    vi /emu/oscam/check_os
    Don't forget to give 755 permissions to check_os script:
    Code:
    chmod 755 /emu/oscam/check_os
    and then paste this text to the file:
    Code:
    #!/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:
    Code:
    logfile = /var/log/oscam.log
    Also, every restart by this script will be recorded in this file:
    Code:
    /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:

    Code:
    vi /etc/crontab
    and add this line:
    Code:
    */15 * * * * root /emu/oscam/check_os >/dev/null

    Step 5:

    ENJOY!!!
  • uttnls

    #2
    Re: Tutorial: Oscam keep alive script and start/stop

    Instead of /emu/oscam/oscam.x86 -c /emu/oscam & use /emu/oscam/oscam.x86 -b -c /emu/oscam, in rest everithing looks fine. Using -b option will be better than & command

    Comment

    • supermariocs
      Member
      • Aug 2011
      • 38

      #3
      Re: Tutorial: Oscam keep alive script and start/stop

      Thanx for your suggestion!
      I didn't know about -b. I know -bg (background).
      What is the exact definition of -b?
      THANX!

      Comment

      • erno
        Senior Member
        • Aug 2011
        • 102

        #4
        Re: Tutorial: Oscam keep alive script and start/stop

        That's a brilliant way to operate.
        On dreamboxes, you need to take care of the image type you are using, in order to make a star/stop script visible from the blue panel.

        Best thing to do is to recopy an existing working start/stop script (already visible through blue panel), and integrate your start script.
        Then it should work either with the crontab or with blue panel.

        Comment

        • supermariocs
          Member
          • Aug 2011
          • 38

          #5
          Re: Tutorial: Oscam keep alive script and start/stop

          Thanx for your suggestion erno.
          I didnt test it on dreambox. I dont think it will work properly on Enigma 1, but definitely should work on Enigma 2.
          You can create any script of your own on Dreambox like you said. Just copy one of the existing scripts and change the text inside.

          Comment

          Working...