- Timestamp:
- 07/19/07 18:17:48 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
projects/twisted-goodies/trunk/misc/etc_init.d_simpleserver
r27 r38 1 1 #! /bin/sh 2 ### BEGIN INIT INFO 3 # Provides: simpleserver 4 # Required-Start: $local_fs $remote_fs 5 # Required-Stop: $local_fs $remote_fs 6 # Default-Start: 2 3 4 5 7 # Default-Stop: S 0 1 6 8 # Short-Description: Twisted Internet Servers 9 # Description: Dirt-Simple Twisted-Based Internet Servers 10 ### END INIT INFO 11 12 # Author: Ed Suominen <ed@eepatents.com> 2 13 # 3 # skeleton example file to build /etc/init.d/ scripts. 4 # This file should be used to construct scripts for /etc/init.d. 5 # 6 # Written by Miquel van Smoorenburg <miquels@cistron.nl>. 7 # Modified for Debian GNU/Linux 8 # by Ian Murdock <imurdock@gnu.ai.mit.edu>. 9 # 10 # Version: @(#)skeleton 1.9.1 08-Apr-2002 miquels@cistron.nl 11 # 14 # Please remove the "Author" lines above and replace them 15 # with your own name if you copy and modify this script. 12 16 13 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 17 # Do NOT "set -e" 18 19 # PATH should only include /usr/* if it runs after the mountnfs.sh script 20 PATH=/usr/sbin:/usr/bin:/sbin:/bin 21 DESC="Simpleserver" 22 NAME=simpleserver 14 23 DAEMON=/usr/bin/twistd 15 NAME=simpleserver 16 DESC="Simple, Twisted-Based Internet Servers" 17 LOG=/var/log/simpleserver.log 24 TACFILE=/etc/$NAME/server.tac 25 LOGFILE=/var/log/$NAME.log 26 PIDFILE=/var/run/$NAME.pid 27 SCRIPTNAME=/etc/init.d/$NAME 18 28 19 test -x $DAEMON || exit 0 20 set -e 29 # Exit if the package is not installed 30 [ -x "$DAEMON" ] || exit 0 21 31 22 SERVERS="www" 23 #SERVERS="www www-dn" 32 # Read configuration variable file if it is present 33 [ -r /etc/default/$NAME ] && . /etc/default/$NAME 34 35 # Load the VERBOSE setting and other rcS variables 36 [ -f /etc/default/rcS ] && . /etc/default/rcS 24 37 25 38 26 function start () { 27 cd /var/$1 28 $DAEMON --quiet --no_save --logfile /var/log/$1/access.log \ 29 --pidfile /var/run/$1.pid --python $(pwd)/site.tac 39 log_daemon_msg () { 40 echo -e "${1}..." 30 41 } 31 42 32 function start_all () { 33 echo "Starting $DESC:" 34 for SERVER in $SERVERS 35 do 36 echo -n " $SERVER ... " 37 start $SERVER 38 if [ $? -eq 0 ] 39 then 40 echo "OK" 41 else 42 echo "FAIL" 43 fi 44 done 43 log_end_msg () { 44 if [ $1 -eq 0 ] 45 then 46 echo "[OK]" 47 else 48 echo "[Fail]" 49 fi 45 50 } 46 51 47 function stop_all () { 48 echo "Stopping $DESC:" 49 for SERVER in $SERVERS 50 do 51 echo -n " $SERVER ... " 52 PIDFILE=/var/run/$SERVER.pid 53 if [ -f $PIDFILE ] 54 then 55 PID=$(cat $PIDFILE) 56 kill $PID 57 kill $PID 2>/dev/null || kill -9 $PID 58 rm $PIDFILE 59 echo "OK" 52 isrunning () { 53 if [ ! -f $PIDFILE ] 54 then 55 false 56 else 57 DAEMONPID=$(cat $PIDFILE) 58 if expr "$(cat /proc/$DAEMONPID/cmdline 2> /dev/null)" : "$DAEMON" > /dev/null 2>&1 59 then 60 true 60 61 else 61 echo "not running" 62 false 62 63 fi 63 done 64 fi 65 } 66 67 68 # 69 # Function that starts the daemon/service 70 # 71 do_start() 72 { 73 # Return 74 # 0 if daemon has been started 75 # 1 if daemon was already running 76 # 2 if daemon could not be started 77 isrunning && return 1 78 $DAEMON --python=$TACFILE --logfile=$LOGFILE --pidfile=$PIDFILE || return 2 79 } 80 81 # 82 # Function that stops the daemon/service 83 # 84 do_stop() 85 { 86 # Return 87 # 0 if daemon has been stopped 88 # 1 if daemon was already stopped 89 # 2 if daemon could not be stopped 90 # other if a failure occurred 91 isrunning && return 1 92 cat $PIDFILE |xargs kill 93 RETVAL="$?" 94 [ "$RETVAL" = 0 ] || return 2 95 return "$RETVAL" 64 96 } 65 97 66 98 case "$1" in 67 start) 68 start_all 99 start) 100 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" 101 do_start 102 case "$?" in 103 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 104 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; 105 esac 69 106 ;; 70 stop) 71 stop_all 107 stop) 108 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" 109 do_stop 110 case "$?" in 111 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 112 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; 113 esac 72 114 ;; 73 115 restart|force-reload) 74 echo "Restarting $DESC: $NAME" 75 stop_all 76 sleep 1 77 start_all 116 log_daemon_msg "Restarting $DESC" "$NAME" 117 do_stop 118 case "$?" in 119 0|1) 120 do_start 121 case "$?" in 122 0) log_end_msg 0 ;; 123 1) log_end_msg 1 ;; # Old process is still running 124 *) log_end_msg 1 ;; # Failed to start 125 esac 126 ;; 127 *) 128 # Failed to stop 129 log_end_msg 1 130 ;; 131 esac 78 132 ;; 79 133 *) 80 N=/etc/init.d/$NAME 81 echo "Usage: $N {start|stop|restart|force-reload}" >&2 82 exit 1 134 echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 135 exit 3 83 136 ;; 84 137 esac 85 138 86 exit 0 87 88 89 90 139 :
