evennia/game/startup.py
Ozan Turkyilmaz cc3c54b3fe start-up stript in python. for stoping the server on nt we have to use win32 api which i have no idea.
if it does not work, let me now

next thing to do is use subprogress.

Ozan
2008-12-18 22:31:22 +00:00

62 lines
1.9 KiB
Python
Executable file

#!/usr/bin/env python
import getopt # for parsing command line arguments
import os # for OS related fonctions
import sys # for getting command line arguments
def init():
"""main fonction for configuring tne system for start-up"""
print 'Configuring evirontment variables'
os.putenv('PYTHONPATH','..')
os.putenv('DJANGO_SETTINGS_MODULE','game.settings')
print 'Renaming old logs as .old'
os.rename('logs/evennia.log','logs/evennia.log.old')
# no error checking for rename for now
def start_daemon():
"""start the server in daemon mode by using os.sysytem to run twistd"""
print 'Starting in Daemon Modea'
os.system('twistd --logfile=logs/evennia.log --python=../src/server.py')
def start_interactive():
"""start in inretactive mode by using os.sysytem to run twistd. this is default for windows for now"""
print 'Starting in Interactive Mode'
os.system('twistd --logfile=logs/evennia.log --python=../src/server.py')
def stop_server():
"""kill the running server this fonction is unix only,
windows impletation will come with subprocess module for everything."""
if os.name == 'posix':
print 'Stoping The Server'
os.system('kill `cat twistd.pid`')
elif os.name == 'nt':
print 'TODO not implented'
else:
print 'Unknown OS delected, can not kill'
def usage():
print 'Sets the appropriate environmental variables and launches the server\nprocess. Run without flags for daemon mode.\n\nFLAGS\n -i Interactive mode\n -d Daemon mode\n -s Stop the running server\n -h Show help display\n, No Default Behavour Exits',
def main(argv):
""" main program body """
try:
opts, args = getopt.getopt(argv, "hids",[help])
except getopt.getopterror:
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ("-h","--help"):
usage()
sys.exit()
elif opt == '-i':
start_interactive()
elif opt == '-d':
start_daemon()
elif opt == '-s':
stop_server()
else:
usage()
if __name__ == '__main__':
main(sys.argv[1:])