#!/bin/bash
#
# osyw Startup script for the osyw HTTP Server
#
# chkconfig: - 88 18
# description: osyw
# processname: osyw
# config:
# config: /home/bottle/osyw/
# pidfile: /var/run/osyw.pid
#
### BEGIN INIT INFO
# Provides: osyw
# Short-Description: start and stop osyw HTTP Server
# Description: The osyw HTTP Server is an extensible server
# implementing the current HTTP standards.
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
# Path to the apachectl script, server binary, and short-form for messages.
port_list=(8811 8812 8813) #设置了3个端口
#pidfile='/var/run/osyw.pid'
pro_path='/var/www/osyw/osyw.py' #程序路径
log_path='/var/www/osyw/log/access.log' #访问日志路径
RETVAL=0
start() {
for i in ${port_list
}
do
p=`/usr/sbin/lsof -i :${i} |wc -l`
if [ ${p} -ge 2 ]
then
action "osyw ${i} already exists !" /bin/false
else
/usr/bin/python ${pro_path} ${i} &>> ${log_path}
RETVAL=$?
if [ ${RETVAL} == 0 ]
then
action "osyw ${i} start ..." /bin/true
else
action "osyw ${i} start ..." /bin/false
fi
fi
done
return $RETVAL
}
stop() {
for i in ${port_list
}
do
pidfile="/var/run/osyw_${i}.pid"
if [ -f ${pidfile} ]
then
pid=`cat ${pidfile}`
kill -9 ${pid}
RETVAL=$?
if [ ${RETVAL} == 0 ]
then
action "osyw ${i} stop ..." /bin/true
else
action "osyw ${i} stop ..." /bin/false
fi
rm -f ${pidfile}
else
action "osyw ${i} Has stopped !" /bin/false
fi
done
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} 'osyw'
RETVAL=$?
;;
restart)
stop
sleep 2
start
;;
condrestart|try-restart)
if status -p ${pidfile} 'osyw' >&/dev/null; then
stop
start
fi
;;
force-reload|reload)
reload
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
RETVAL=2
esac
exit $RETVAL