On the general subject of a launch script, I've attached a Launch.py
replacement that I've been using. I'm not using it much anymore, since
I'm not using Webware (at least this version of Webware), but it's
worked okay in the past (maybe the attempt to kill existing app servers
is too aggressive, though). I don't have time to integrate it, but here
it is for someone who is interested...
--
Ian Bicking / [EMAIL PROTECTED] / http://blog.ianbicking.org
#!/usr/local/bin/python2.2
import os, sys, signal
webwarePath = '/usr/local/share/webware'
appWorkPath = '%%APP_WORK_DIR%%'
sys.path.extend([%%APP_PYTHON_PATH%%])
def main(args):
global webwarePath, appWorkPath
logFile = uid = gid = pidFile = None
newArgs = []
# @@: This really should be using getopt or something
for arg in args:
if arg.startswith('--webware-path='):
webwarePath = arg[15:]
elif arg.startswith('--working-path='):
appWorkPath = arg[15:]
elif arg.startswith('--log-file='):
logFile = arg[len('--log-file='):]
elif arg.startswith('--user='):
uid = arg[len('--user='):]
elif arg.startswith('--group='):
gid = arg[len('--group='):]
elif arg.startswith('--pid-file='):
pidFile = arg[len('--pid-file='):]
else:
newArgs.append(arg)
if uid:
try:
uid = int(uid)
except ValueError:
import pwd
try:
entry = pwd.getpwnam(uid)
except KeyError:
raise KeyError, "Bad username: %r; no such user
exists" % uid
if not gid:
gid = entry[3]
uid = entry[2]
if gid:
try:
gid = int(gid)
except ValueError:
import grp
try:
entry = grp.getgrnam(gid)
except KeyError:
raise KeyError, "Bad group: %r; no such group
exists" % gid
gid = entry[2]
if pidFile:
if os.path.exists(pidFile):
f = open(pidFile)
pid = int(f.read())
f.close()
print 'PID file (%s) contains PID %s; killing...' %
(pidFile, pid),
try:
os.kill(pid, signal.SIGKILL)
except OSError, e:
if e.errno == 3: # No such process
print 'PID file was stale, continuing
with startup.'
else:
raise
else:
print 'Signal sent, waiting for exit...',
try:
os.waitpid(pid, 0)
except OSError, e:
if e.errno == 10: # No such process
pass
else:
raise
print 'done.'
f = open(pidFile, 'w')
f.write(str(os.getpid()))
f.close()
if gid:
os.setgid(gid)
if uid:
os.setuid(uid)
#print 'Setting uid: %s; gid: %s' % (uid, gid)
if logFile:
f = open(logFile, 'a', 1) # 1==line buffered
sys.stdout = sys.stderr = f
pass
args = newArgs
# ensure Webware is on sys.path
sys.path.insert(0, webwarePath)
# import the master launcher
import WebKit.Launch
if len(args) < 2:
WebKit.Launch.usage()
# Go!
WebKit.Launch.launchWebKit(args[1], appWorkPath, args[2:])
if __name__=='__main__':
main(sys.argv)
#!/usr/local/bin/bash
#
# Startup script for WebKit on UNIX systems.
#
# See Webware/WebKit/Docs/InstallGuide.html for instructions.
# chkconfig: 2345 75 25
# description: WebKit is a Python application server, part of Webware.
# Configuration section
WEBKIT_DIR=%%APP_WORK_DIR%%
PID_FILE=/var/run/%%APP_NAME%%/%%APP_NAME%%.pid
LOG=/var/log/%%APP_NAME%%/%%APP_NAME%%.log
PYTHONPATH=
WEBWARE_USER=%%APP_USER%%
# end configuration section
# Source function library.
# Use the funtions provided by Red Hat or use our own
if [ -f /etc/rc.d/init.d/functions ]
then
. /etc/rc.d/init.d/functions
else
function action {
echo "$1"
shift
$@
}
function success {
echo -n "Success"
}
function failure {
echo -n "Failed"
}
fi
[ -x $WEBKIT_DIR/AppServer ] || exit 0
case "$1" in
start)
echo -n "Starting WebKit: "
pushd $WEBKIT_DIR > /dev/null
LAUNCH="./AppServer --user=$WEBWARE_USER --group=$WEBWARE_USER
--log-file=$LOG --pid-file=$PID_FILE"
$LAUNCH &
echo $! > $PID_FILE
popd > /dev/null
success "Starting WebKit"
echo
;;
stop)
echo -n "Shutting down WebKit: "
if test -f "$PID_FILE" ; then
PID=`cat $PID_FILE`
if kill $PID >> $LOG 2>&1 ; then
/bin/rm $PID_FILE
success "Shutting down WebKit"
else
echo ""
echo "Could not kill process $PID named in
$PID_FILE. Check tail of $LOG."
failure "Shutting down WebKit"
fi
else
echo ""
echo "No WebKit pid file found. Looked for $PID_FILE."
failure "No WebKit pid file found. Looked for
$PID_FILE."
fi
echo
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: webkit {start|stop|restart}"
exit 1
esac
exit 0