|
Hello Cerulean
My init.d startup script is shell script and it is executable. Added the script in startup.
I am calling the Python script using command "python /path_to_server_script" from the init.d scrip.
In the server script i am using #!/usr/bin/env python; which i think is not required. The server script opens a port and keeps listening for req.
I am attaching the init.d script. Please check out and suggest.
Thank you.
My startup script is ...
-------------
# pidfile: /var/run/server_script.pid
# config:
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
RETVAL=0
pidfile="/var/run/server_script.pid"
lockfile="/var/lock/subsys/server_script"
name="server_script"
prog="python /opt/pkg/server_script.py"
start() {
#--------Check if server is already running
if [ -f $pidfile ]; then
pid=cat $pidfile
if [ ]ps -elf
touch $pidfile
touch $lockfile
echo -n "$name (pid `cat $pidfile`) is Running." && success
echo
exit 0
fi
echo -n $"Starting $name: "
$prog& 2>&1 > /dev/null
#--------Check for the success
if [ -z "`/sbin/pidof $prog`" ]; then
failure $"$prog startup"
RETVAL=1
else
pidofproc $prog > $pidfile && touch $lockfile && success $"$prog startup"
RETVAL=0
fi
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $name: "
killproc server_script
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $lockfile && rm -f $pidfile
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
;;
status)
#--------Check status
if [ -n "`/sbin/pidof $prog`" ]; then
pidofproc $prog > $pidfile
touch $lockfile
echo "$name (pid `cat $pidfile`) is Running."
else
echo "$name is not running."
RETVAL=3
fi
;;
*)
echo $"Usage: $0 {start|status|stop|restart|reload}"
exit 1
esac
exit $RETVAL
----------------
|