I don't really like using Launch for all this, since it gets written out by MakeAppWorkDir. I still don't quite understand what Launch is for. I'll just attach it to this email, and maybe people can suggest where it should go. (Also, I don't know if any of this applies to Windows -- probably not)
-- 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)
