mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 20:59:27 +01:00
Added pidFile support and a signal handler for SIGTERM (the default for kill).
This commit is contained in:
parent
e63dbb09bf
commit
6ef38bd28f
@ -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.
|
||||
|
11
src/conf.py
11
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', """
|
||||
|
Loading…
Reference in New Issue
Block a user