You are not logged in.

#1 2010-10-28 22:53:13

Demon
Member
From: Republic of Srpska, BA
Registered: 2008-03-02
Posts: 246

[SOLVED] Need help with custom made daemon script

Hello. I have made a script which needs to be "daemonized". But the daemon can only be started, not stopped. Don't know why, really.

This is the daemon script:

mladen ~  $  cat /etc/rc.d/cipcd                                                                                       
#!/bin/bash


. /etc/rc.conf
. /etc/rc.d/functions

PID=`pidof -o %PPID /usr/bin/cipcd`
case "$1" in
  start)
    stat_busy "Starting CIPC Daemon"
    [ -z "$PID" ] && /usr/bin/cipcd 2>&1 &
    if [ $? -gt 0 ]; then
      stat_fail
    else
      add_daemon cipcd
      stat_done
    fi
    ;;
  stop)
    stat_busy "Stopping CIPC Daemon"
    [ ! -z "$PID" ]  && kill $PID &>/dev/null
    if [ $? -gt 0 ]; then
      stat_fail
    else
      rm_daemon cipcd
      stat_done
    fi
    ;;
  restart)
    $0 stop
    sleep 1
    $0 start
    ;;
  *)                                                                                                                   
    echo "usage: $0 {start|stop|restart}"                                                                               
esac                                                                                                                   
exit 0

This is the script which does the job (checks if my IP address has changed, and if it is, update it on the free domain server):

mladen ~  $  cat /usr/bin/cipcd                                                                                         
#!/bin/bash                                                                                                             
                                                                                                                       
interval=600                                                                                                           
                                                                                                           
sip=`lynx -dump 'http://192.168.1.1:8080/rpServiceStatus.html' -auth=admin:admin | grep 'PVC-0' | cut -d ' ' -f7`       
while :                                                                                                                 
do                                                                                                                     
cip=`lynx -dump 'http://192.168.1.1:8080/rpServiceStatus.html' -auth=admin:admin | grep 'PVC-0' | cut -d ' ' -f7`;     
if (test "$sip" != "$cip") then                                                                                         
`lynx -dump 'http://www.some address.com/blah blah'`&>/dev/null                   
sip=$cip;                                                                                                               
fi                                                                                                                     
sleep "$interval"s ;                                                                                                   
done

Any help appreciated...

Last edited by Demon (2010-10-30 10:03:32)

Offline

#2 2010-10-29 05:52:31

moniker117
Member
Registered: 2010-06-18
Posts: 7

Re: [SOLVED] Need help with custom made daemon script

I believe the following line is failing:

PID=`pidof -o %PPID /usr/bin/cipcd`

Have you tried echoing the value of PID to see what value it has?  I don't think it's returning a value.

Offline

#3 2010-10-30 10:02:32

Demon
Member
From: Republic of Srpska, BA
Registered: 2008-03-02
Posts: 246

Re: [SOLVED] Need help with custom made daemon script

Thank you, moniker117, I've fixed the daemon script, now everything is ok. smile

In case someone is interested:

mladen ~  $  cat /etc/rc.d/cipcd
#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

#PID="$(cat /var/run/cipcd.pid 2>/dev/null)"
PID="$(ps -A | grep cipcb | cut -d ' ' -f2)"

case "$1" in
  start)
    stat_busy "Starting CIPC Daemon"
    [ -z "$PID" ] && /usr/bin/cipcb 2>/dev/null &
    if [ $? -gt 0 ]; then
      stat_fail
    else
      add_daemon cipcd
      stat_done
    fi
    ;;
  stop)
    stat_busy "Stoping CIPC Daemon"
    [ ! -z "$PID" ]  && kill $PID &> /dev/null
    if [ $? -gt 0 ]; then
      stat_fail
    else
      rm_daemon cipcd
      stat_done
    fi
    ;;
  restart)
    $0 stop
    sleep 1
    $0 start
    ;;                                                                                                       
  status)                                                                                                     
    if [ ! -z "$PID" ]; then                                                                                 
    echo "The script is running."                                                                             
    else                                                                                                     
    echo "The script is not running."                                                                         
    fi                                                                                                       
    ;;                                                                                                       
  *)                                                                                                         
    echo "usage: $0 {start|stop|restart}"                                                                     
esac                                                                                                         
exit 0

mladen ~  $  cat /usr/bin/cipcb                                                                               
#!/bin/bash

interval=600

#IP address check - HUAWEI SmartAX MT882 ADSL modem
sip=`lynx -dump 'http://192.168.1.1:8080/rpServiceStatus.html' -auth=admin:admin | grep 'PVC-0' | cut -d ' ' -f7`

while :
do
cip=`lynx -dump 'http://192.168.1.1:8080/rpServiceStatus.html' -auth=admin:admin | grep 'PVC-0' | cut -d ' ' -f7`;

if (test "$sip" != "$cip") then
`lynx -dump 'http://www.freedomain.co.nr/dyna.php?do … ass=******'`&>/dev/null         
sip=$cip;
fi
sleep "$interval"s ;
done

Offline

Board footer

Powered by FluxBB