LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-29-2011, 04:12 AM   #1
wazzgod
LQ Newbie
 
Registered: Oct 2011
Posts: 1

Rep: Reputation: Disabled
Question 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
 
Old 10-29-2011, 06:36 AM   #2
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
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.

Last edited by eSelix; 10-29-2011 at 06:37 AM.
 
Old 10-29-2011, 10:06 AM   #3
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
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,
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
/sbin/init: Kernel panic - not syncing: Attempted to kill init! jalejo08 Linux - Kernel 7 07-02-2009 01:16 PM
usr/sbin/adsl-start: line 217: 3165 Terminated kitty07 Linux - Networking 2 11-23-2008 01:38 AM
Starting sshd: /etc/init.d/sshd: line 113: /usr/sbin/sshd: Permission denied sumanc Linux - Server 5 03-28-2008 04:59 AM
Chkroot scan - /sbin/init & /sbin/ifconfig INFECTED bicoba Linux - Security 4 06-07-2006 09:16 AM
/sbin/adsl-start: line 215: 5543 Terminated $CONNECT "$@" >/dev/null 2> ciberrust Linux - Hardware 3 03-27-2005 10:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration