LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   init.d script - /sbin/service: line 66: 23002 Terminated (http://www.linuxquestions.org/questions/linux-software-2/init-d-script-sbin-service-line-66-23002-terminated-910754/)

wazzgod 10-29-2011 04:12 AM

init.d script - /sbin/service: line 66: 23002 Terminated
 
i copy init.d script 3proxyx to 3proxy and it should work fine, but it doesnt!

Such a simple task and having mega issues... GRR

[root@enzu2 ~]# cd /etc/init.d
[root@enzu2 init.d]# chmod +x /etc/init.d/3proxyx
[root@enzu2 init.d]# service 3proxyx restart
Stopping 3Proxy
3proxy: no process killed
Starting 3Proxy
[root@enzu2 init.d]# service 3proxyx restart
Stopping 3Proxy
Starting 3Proxy
[root@enzu2 init.d]# cp /etc/init.d/3proxyx /etc/init.d/3proxy
[root@enzu2 init.d]# chmod +x /etc/init.d/3proxy
[root@enzu2 init.d]# service 3proxy restart
Stopping 3Proxy
/sbin/service: line 66: 23299 Terminated env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "${SERVICEDIR}/${SERVICE}" ${OPTIONS}
[root@enzu2 init.d]# service 3proxy start
Starting 3Proxy
[root@enzu2 init.d]# service 3proxy stop
Stopping 3Proxy
/sbin/service: line 66: 23317 Terminated env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "${SERVICEDIR}/${SERVICE}" ${OPTIONS}
[root@enzu2 init.d]# service 3proxy restart
Stopping 3Proxy
/sbin/service: line 66: 23324 Terminated env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "${SERVICEDIR}/${SERVICE}" ${OPTIONS}
[root@enzu2 init.d]# SEE MY ERROR?
-bash: SEE: command not found
[root@enzu2 init.d]#








here is /etc/init.d/3proxyx

Code:

#!/bin/sh
# description: 3Proxy Server
# chkconfig: 2345 99 00

case "$1" in
'start')
        echo Starting 3Proxy
        /usr/sbin/3proxy /etc/opt/3proxy.cfg
        touch /var/lock/subsys/3proxyx
        ;;
'restart')
        echo Stopping 3Proxy
        /usr/bin/killall 3proxy
        rm -f /var/lock/subsys/3proxyx
        echo Starting 3Proxy
        /usr/sbin/3proxy /etc/opt/3proxy.cfg
        touch /var/lock/subsys/3proxyx
        ;;
'stop')
        echo Stopping 3Proxy
        /usr/bin/killall 3proxy
        rm -f /var/lock/subsys/3proxyx
        ;;
*)
        echo "Usage: $0 { start | restart | stop }"
        ;;
esac
exit 0


eSelix 10-29-2011 06:36 AM

I think that your "killall 3proxy" in "stop" command killed your service utility (/etc/init.d/3proxy) which has also name "3proxy". Better is using pids for that.

Nominal Animal 10-29-2011 10:06 AM

I fully agree with eSelix's analysis.

There are two methods I've used in service scripts, to solve the problem (of stopping a service reliably).

First looks up the PIDs using ps -C 3proxy -o pid= , and kills only those:
Code:

CMDNAME=3proxy
DELAY=50

pids=`ps -C $CMDNAME -o pid=`
[ -n "$pids" ] && kill -TERM $pids

while [ $DELAY -gt 0 ] && [ -n "`ps -C $CMDNAME -o pid=`" ]; do
    sleep .1
    DELAY=$((DELAY - 1))
done

pids=`ps -C $CMDNAME -o pid=`
[ -n "$pids" ] && kill -KILL $pids

This works quite well for services that do not create worker processes. The above will first send a TERM signal, then wait up to five seconds (50 deciseconds), and if the processes still exist, it will send a KILL signal. For slow-terminating services I recommend a much longer limit. Half a minute is okay, if the service may have to save a lot of files before exiting.

This procedure lets the service catch the TERM signal, do whatever cleanup it sees necessary, and then exit, by its own volition. The KILL signal will forcibly terminate the process immediately (unless it is blocked in some kernel call).

The other method is the more typical one. The service processes save the main PID in a pid file, usually /var/run/name.pid . (I do not know if 3proxy creates a pid file or not, and I'm too lazy to find out. Sorry.)
The service script should check if that file exists. If not, the service is not running. If the file specifies a PID that is no longer running (or runs a different binary), then the service has crashed. Only if the PID is still running (and has the proper name, since PIDs can be reused after a while), the service is still up. For example, to stop the service, you might use
Code:

CMDNAME=3proxy
PIDFILE=/var/run/$CMDNAME.pid
DELAY=50

pid=`cat "$PIDFILE" 2>/dev/null`
if [ -n "$pid" ]; then
    if [ "`ps -o comm= $pid`" = "$CMDNAME" ]; then
        # Ask process to terminate
        kill -TERM $pid
        while [ $DELAY -gt 0 ] && [ "`ps -o comm= $pid`" = "$CMDNAME" ]; do
            sleep .1
            DELAY=$((DELAY - 1))
        done
        if [ "`ps -o comm= $pid`" = "$CMDNAME" ]; then
            # Forcibly terminate process           
            kill -KILL $pid
        else
            # Process terminated peacefully
        fi
    else
        # Process has already crashed or died
    fi
else
    # Not running
fi

While it is possible for the service script to guess the PID of the main process it started, it is not reliable. For example, if the service daemonizes itself, it will acquire a new PID. Thus, I do not recommend trying to create a PID file for services that do not create one themselves; for those, I just use the first method.

I hope this helps,


All times are GMT -5. The time now is 07:18 PM.