1#!/bin/sh 2# 3# WebKit application server 4# part of Webware for Python 5# 6# /etc/init.d/webkit 7# 8# init.d script for SUSE Linux 9# 10### BEGIN INIT INFO 11# Provides: webkit 12# Required-Start: $local_fs $remote_fs $network $syslog 13# Required-Stop: $local_fs $remote_fs $network $syslog 14# Default-Start: 3 5 15# Default-Stop: 0 1 2 6 16# Description: WebKit Application Server (Webware for Python) 17### END INIT INFO 18 19### START LOCAL CONFIGURATION 20 21# If you store this script in your Webware working directory 22# and create a symlink to it as /etc/init.d/webkit_appname, 23# it will try to guess your configuration parameters. Otherwise 24# you need to hard code the path to the working directory here. 25# You can make changes either directly here in the start script or 26# you can also override the configuration in the Launch.py script. 27 28# The location and name of the start sript: 29START_SCRIPT="$0" 30APP_NAME=`basename "$START_SCRIPT"` 31if [ -h "$START_SCRIPT" ]; then 32 START_SCRIPT=`readlink -f "$START_SCRIPT"` 33fi 34 35# The location of the working directory: 36WORK_DIR=`dirname "$START_SCRIPT"` 37if [ "$WORK_DIR" = "/etc/init.d" ]; then 38 # Put hard coded path to working directory here: 39 WORK_DIR="." 40fi 41 42# Make sure to have the absolute path: 43test -d "$WORK_DIR" || exit 5 44WORK_DIR=`cd "$WORK_DIR" 2>/dev/null && pwd` 45 46# The app server launch script: 47APP_SERVER="$WORK_DIR/AppServer" 48test -x "$APP_SERVER" || exit 5 49 50# The app server configuration: 51APP_SERVER_CONFIG="$WORK_DIR/Configs/AppServer.config" 52test -f "$APP_SERVER_CONFIG" || exit 5 53 54# The WebKit app server log file 55# (you can set this in Launch.py as well): 56#LOG_FILE="/var/log/$APP_NAME.log" 57LOG_FILE="$WORK_DIR/Logs/webkit.log" 58# Use this extension if you want to move the last log away 59# (also consider using logrotate or something similar): 60LOG_OLD=".old" 61 62# The app server process id file 63# (you can set this in Launch.py as well): 64#PID_FILE="/var/run/$APP_NAME.pid" 65PID_FILE="$WORK_DIR/webkit.pid" 66 67# The user and group to run the app server 68# (you can set this in Launch.py as well). 69# If undefined, it will be the user and group 70# running the start script (usually root). 71# You should use a low-privilege account, 72# like the work dir owner, wwwrun or nobody. 73# This will use the owner of the AppServer script: 74WEBWARE_USER=`stat -c "%U" "$APP_SERVER"` 75WEBWARE_GROUP=`stat -c "%G" "$APP_SERVER"` 76 77# Unset the following variable if you want to store the 78# pid and log files as the user running the start script 79# (usually root) or set it if you want these files to be 80# written after switching to WEBWARE_USER:WEBWARE_GROUP. 81LAUNCH_AS_WEBWARE="yes" 82 83# Additional options -u or -O to be passed on to Python: 84PYTHONOPTS= 85# Additional libraries to be included in the Python path: 86PYTHONPATH= 87export PYTHONPATH 88 89### END LOCAL CONFIGURATION 90 91# Source SUSE Linux function library: 92. /etc/rc.status 93 94rc_reset 95 96case "$1" in 97 start) 98 echo -n "Starting $APP_NAME " 99 # Keep backup of last log file: 100 if [ "$LOG_OLD" -a -f "$LOG_FILE" ]; then 101 if [ -s "$LOG_FILE" ]; then 102 mv "$LOG_FILE" "$LOG_FILE$LOG_OLD" 103 else 104 rm "$LOG_FILE" 105 fi 106 fi 107 # Prepare options to set user and group 108 if [ "$WEBWARE_USER" ]; then 109 WEBWARE_USER="-u $WEBWARE_USER" 110 fi 111 if [ "$WEBWARE_GROUP" ]; then 112 WEBWARE_GROUP="-g $WEBWARE_GROUP" 113 fi 114 # Note that the pid file does not record the pid of the 115 # wrapper script, but the pid of the Python app server: 116 if [ "$LAUNCH_AS_WEBWARE" ]; then 117 # Switch user first, then create pid and log files: 118 startproc -f -l /dev/null \ 119 $WEBWARE_USER $WEBWARE_GROUP \ 120 "$APP_SERVER" $PYTHONOPTS \ 121 -i "$PID_FILE" -d "$WORK_DIR" -o "$LOG_FILE" 122 else 123 # Create pid and log files first, then switch user: 124 startproc -f -l "$LOG_FILE" \ 125 "$APP_SERVER" $PYTHONOPTS \ 126 -i "$PID_FILE" -d "$WORK_DIR" \ 127 $WEBWARE_USER $WEBWARE_GROUP 128 fi 129 rc_status -v 130 ;; 131 stop) 132 echo -n "Shutting down $APP_NAME " 133 # Note that we are terminating the Python app server here; 134 # the app server wrapper script will follow automatically: 135 if [ -f "$PID_FILE" ] ; then 136 killproc -p "$PID_FILE" -TERM python 137 else 138 rc_failed 7 139 fi 140 rc_status -v 141 ;; 142 try-restart) 143 "$0" status >/dev/null && "$0" restart 144 rc_status 145 ;; 146 restart) 147 "$0" stop 148 "$0" start 149 rc_status 150 ;; 151 force-reload|reload) 152 echo -n "Reloading $APP_NAME " 153 if [ -f "$PID_FILE" ] ; then 154 killproc -p "$PID_FILE" -HUP python 155 else 156 rc_failed 7 157 fi 158 rc_status -v 159 ;; 160 status) 161 echo -n "Checking for $APP_NAME " 162 if [ -f "$PID_FILE" ] ; then 163 checkproc -p $PID_FILE python 164 else 165 rc_failed 1 166 fi 167 rc_status -v 168 ;; 169 probe) 170 test "$APP_SERVER_CONFIG" -nt "$PID_FILE" && echo reload 171 ;; 172 *) 173 echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}" 174 exit 1 175 ;; 176esac 177 178rc_exit 179