[Erp5-report] r11445 - /erp5/trunk/utils/oood/runserw.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Nov 22 17:31:28 CET 2006
Author: kevin
Date: Wed Nov 22 17:31:27 2006
New Revision: 11445
URL: http://svn.erp5.org?rev=11445&view=rev
Log:
Use a lock file to not run multiple servers and save the pid
Modified:
erp5/trunk/utils/oood/runserw.py
Modified: erp5/trunk/utils/oood/runserw.py
URL: http://svn.erp5.org/erp5/trunk/utils/oood/runserw.py?rev=11445&r1=11444&r2=11445&view=diff
==============================================================================
--- erp5/trunk/utils/oood/runserw.py (original)
+++ erp5/trunk/utils/oood/runserw.py Wed Nov 22 17:31:27 2006
@@ -2,7 +2,8 @@
##############################################################################
#
# Copyright (c) 2002, 2006 Nexedi SARL and Contributors. All Rights Reserved.
-# Jean-Paul Smets-Solanes <jp at nexedi.com>
+# Jean-Paul Smets-Solanes <jp at nexedi.com>
+# Kevin Deldycke <kevin_AT_nexedi_DOT_com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
@@ -28,23 +29,53 @@
##############################################################################
import sys
+import atexit
from serw import *
if __name__ == '__main__':
+
+ # Start the server core
proc = Procesor()
+
+ # Debug mode or not ?
try:
debug = (sys.argv[1] == 'debug')
except IndexError:
debug = False
if debug:
+ lib.log("Server - Started in debug mode", 1)
+
+ # Create a lock file to not run more than one server and to save the pid
+ lock_file_path = os.path.join(config.pid_dir, 'server_pid.lock')
+ if os.path.exists(lock_file_path):
+ lib.log("Server - Can't start a new server, there is already one running", 2)
+ sys.exit(1)
+ lock_file = open(lock_file_path, 'w')
+ server_pid = os.getpid()
+ lock_file.write(str(server_pid))
+ lock_file.close()
+ lib.log("Server - Started as pid %s" % server_pid, 0)
+
+ # Clean the lock file before exit
+ def cleanLock(file=lock_file_path):
+ if os.path.exists(file):
+ os.remove(file)
+ atexit.register(cleanLock)
+
+ # Some debug stuff
+ if debug:
d = open('test.odt').read()
print proc.run_makepdf('test.odt', base64.encodestring(d))[0]
#d=open('doc/test.doc').read()
#print proc.run_setmetadata('test.odt',base64.encodestring(d),{'title':'zz'})[0]
- else:
- ser = MySerw((config.server_host, config.server_port), allow_none = True)
- ser.register_instance(proc)
- ser.serve_forever()
+ sys.exit(0)
-# vim: shiftwidth=2
+ # Run the server forever
+ ser = MySerw((config.server_host, config.server_port), allow_none = True)
+ ser.register_instance(proc)
+ ser.serve_forever()
+
+ # Clean up before exit
+ cleanLock()
+ sys.exit(0)
More information about the Erp5-report
mailing list