mirror of https://github.com/Mikaela/Limnoria.git
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 sys
|
||||||
import atexit
|
import atexit
|
||||||
import shutil
|
import shutil
|
||||||
|
import signal
|
||||||
|
|
||||||
if sys.version_info < (2, 3, 0):
|
if sys.version_info < (2, 3, 0):
|
||||||
sys.stderr.write('This program requires Python >= 2.3.0\n')
|
sys.stderr.write('This program requires Python >= 2.3.0\n')
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
def signalHandler(signalNumber, stackFrame):
|
||||||
|
raise SystemExit, 'Signal #%s' % signalNumber
|
||||||
|
|
||||||
|
signal.signal(signal.SIGTERM, signalHandler)
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import optparse
|
import optparse
|
||||||
|
|
||||||
|
@ -71,7 +77,10 @@ def main():
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
log.info('Exiting due to Ctrl-C.')
|
log.info('Exiting due to Ctrl-C.')
|
||||||
break
|
break
|
||||||
except SystemExit:
|
except SystemExit, e:
|
||||||
|
s = str(e)
|
||||||
|
if s:
|
||||||
|
log.info('Exiting due to %s', s)
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
try: # Ok, now we're *REALLY* paranoid!
|
try: # Ok, now we're *REALLY* paranoid!
|
||||||
|
@ -283,6 +292,17 @@ if __name__ == '__main__':
|
||||||
import world
|
import world
|
||||||
world.starting = True
|
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():
|
def closeRegistry():
|
||||||
# We only print if world.dying so we don't see these messages during
|
# We only print if world.dying so we don't see these messages during
|
||||||
# upkeep.
|
# 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
|
will timeout when this many seconds has gone by (unless otherwise modified by
|
||||||
the author of the code that uses the sockets)."""))
|
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.register('drivers')
|
||||||
supybot.drivers.register('poll', registry.Float(1.0, """Determines the default
|
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],
|
'config supybot.directories.plugins [config supybot.directories.plugins],
|
||||||
newPluginDirectory'."""))
|
newPluginDirectory'."""))
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
# supybot.databases. For stuff relating to Supybot's databases (duh!)
|
||||||
|
###
|
||||||
supybot.register('databases')
|
supybot.register('databases')
|
||||||
supybot.databases.register('users')
|
supybot.databases.register('users')
|
||||||
supybot.databases.users.register('filename', registry.String('users.conf', """
|
supybot.databases.users.register('filename', registry.String('users.conf', """
|
||||||
|
|
Loading…
Reference in New Issue