From cc3c54b3fe6a569cc86dd4f63118959209845879 Mon Sep 17 00:00:00 2001 From: Ozan Turkyilmaz Date: Thu, 18 Dec 2008 22:31:22 +0000 Subject: [PATCH] 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 --- game/startup.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 game/startup.py diff --git a/game/startup.py b/game/startup.py new file mode 100755 index 000000000..67bcdc4b6 --- /dev/null +++ b/game/startup.py @@ -0,0 +1,62 @@ +#!/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:])