From 6ef38bd28f0d9169c10ee919c014f51df2b41df8 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Mon, 19 Apr 2004 05:05:53 +0000 Subject: [PATCH] Added pidFile support and a signal handler for SIGTERM (the default for kill). --- scripts/supybot | 24 ++++++++++++++++++++++-- src/conf.py | 11 ++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/scripts/supybot b/scripts/supybot index 28341958d..47de4e478 100755 --- a/scripts/supybot +++ b/scripts/supybot @@ -40,11 +40,17 @@ import os import sys import atexit import shutil +import signal if sys.version_info < (2, 3, 0): sys.stderr.write('This program requires Python >= 2.3.0\n') sys.exit(-1) +def signalHandler(signalNumber, stackFrame): + raise SystemExit, 'Signal #%s' % signalNumber + +signal.signal(signal.SIGTERM, signalHandler) + import time import optparse @@ -71,7 +77,10 @@ def main(): except KeyboardInterrupt: log.info('Exiting due to Ctrl-C.') break - except SystemExit: + except SystemExit, e: + s = str(e) + if s: + log.info('Exiting due to %s', s) break except: try: # Ok, now we're *REALLY* paranoid! @@ -282,7 +291,18 @@ if __name__ == '__main__': import conf import world world.starting = True - + + # Let's write the PID file. + pidFile = conf.supybot.pidFile() + if pidFile: + try: + fd = file(pidFile, 'w') + pid = os.getpid() + fd.write('%s\n' % pid) + fd.close() + except EnvironmentError, e: + log.error('Error opening pid file %s: %s', pidFile, e) + def closeRegistry(): # We only print if world.dying so we don't see these messages during # upkeep. diff --git a/src/conf.py b/src/conf.py index 1a204fe76..7bdf27d9e 100644 --- a/src/conf.py +++ b/src/conf.py @@ -437,8 +437,13 @@ the default timeout for socket objects will be. This means that *all* sockets will timeout when this many seconds has gone by (unless otherwise modified by the author of the code that uses the sockets).""")) +supybot.register('pidFile', registry.String('', """Determines what file the bot +should write its PID (Process ID) to, so you can kill it more easily. If it's +left unset (as is the default) then no PID file will be written. A restart is +required for changes to this variable to take effect.""")) + ### -# Driver stuff. +# supybot.drivers. For stuff relating to Supybot's drivers (duh!) ### supybot.register('drivers') supybot.drivers.register('poll', registry.Float(1.0, """Determines the default @@ -468,6 +473,10 @@ you can nest the former value and add a new one. E.g. you can say: bot: 'config supybot.directories.plugins [config supybot.directories.plugins], newPluginDirectory'.""")) + +### +# supybot.databases. For stuff relating to Supybot's databases (duh!) +### supybot.register('databases') supybot.databases.register('users') supybot.databases.users.register('filename', registry.String('users.conf', """