Mercurial > p > roundup > code
comparison roundup/scripts/roundup_server.py @ 3784:93dfda74a763
allow use of roundup-server pidfile without forking [SF#1614753]
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Mon, 18 Dec 2006 03:53:39 +0000 |
| parents | a2d22d0de0bc |
| children | f623bdafe44b |
comparison
equal
deleted
inserted
replaced
| 3783:19d1e674768b | 3784:93dfda74a763 |
|---|---|
| 15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 16 # | 16 # |
| 17 | 17 |
| 18 """Command-line script that runs a server over roundup.cgi.client. | 18 """Command-line script that runs a server over roundup.cgi.client. |
| 19 | 19 |
| 20 $Id: roundup_server.py,v 1.85 2006-11-09 00:36:21 richard Exp $ | 20 $Id: roundup_server.py,v 1.86 2006-12-18 03:53:39 richard Exp $ |
| 21 """ | 21 """ |
| 22 __docformat__ = 'restructuredtext' | 22 __docformat__ = 'restructuredtext' |
| 23 | 23 |
| 24 import errno, cgi, getopt, os, socket, sys, traceback, urllib, time | 24 import errno, cgi, getopt, os, socket, sys, traceback, urllib, time |
| 25 import ConfigParser, BaseHTTPServer, SocketServer, StringIO | 25 import ConfigParser, BaseHTTPServer, SocketServer, StringIO |
| 376 (configuration.NullableOption, "group", "", | 376 (configuration.NullableOption, "group", "", |
| 377 "Group ID as which the server will answer requests.\n" | 377 "Group ID as which the server will answer requests.\n" |
| 378 "In order to use this option, " | 378 "In order to use this option, " |
| 379 "the server must be run initially as root.\n" | 379 "the server must be run initially as root.\n" |
| 380 "Availability: Unix."), | 380 "Availability: Unix."), |
| 381 (configuration.BooleanOption, "nodaemon", "no", | |
| 382 "don't fork (this overrides the pidfile mechanism)'"), | |
| 381 (configuration.BooleanOption, "log_hostnames", "no", | 383 (configuration.BooleanOption, "log_hostnames", "no", |
| 382 "Log client machine names instead of IP addresses " | 384 "Log client machine names instead of IP addresses " |
| 383 "(much slower)"), | 385 "(much slower)"), |
| 384 (configuration.NullableFilePathOption, "pidfile", "", | 386 (configuration.NullableFilePathOption, "pidfile", "", |
| 385 "File to which the server records " | 387 "File to which the server records " |
| 406 "port": "p:", | 408 "port": "p:", |
| 407 "group": "g:", | 409 "group": "g:", |
| 408 "user": "u:", | 410 "user": "u:", |
| 409 "logfile": "l:", | 411 "logfile": "l:", |
| 410 "pidfile": "d:", | 412 "pidfile": "d:", |
| 413 "nodaemon": "D", | |
| 411 "log_hostnames": "N", | 414 "log_hostnames": "N", |
| 412 "multiprocess": "t:", | 415 "multiprocess": "t:", |
| 413 } | 416 } |
| 414 | 417 |
| 415 def __init__(self, config_file=None): | 418 def __init__(self, config_file=None): |
| 635 "port": DEFAULT_PORT, | 638 "port": DEFAULT_PORT, |
| 636 "mp_def": DEFAULT_MULTIPROCESS, | 639 "mp_def": DEFAULT_MULTIPROCESS, |
| 637 "mp_types": ", ".join(MULTIPROCESS_TYPES), | 640 "mp_types": ", ".join(MULTIPROCESS_TYPES), |
| 638 } | 641 } |
| 639 | 642 |
| 643 | |
| 644 def writepidfile(pidfile): | |
| 645 ''' Write a pidfile (only). Do not daemonize. ''' | |
| 646 pid = os.getpid() | |
| 647 if pid: | |
| 648 pidfile = open(pidfile, 'w') | |
| 649 pidfile.write(str(pid)) | |
| 650 pidfile.close() | |
| 640 | 651 |
| 641 def daemonize(pidfile): | 652 def daemonize(pidfile): |
| 642 ''' Turn this process into a daemon. | 653 ''' Turn this process into a daemon. |
| 643 - make sure the sys.std(in|out|err) are completely cut off | 654 - make sure the sys.std(in|out|err) are completely cut off |
| 644 - make our parent PID 1 | 655 - make our parent PID 1 |
| 761 if not hasattr(os, 'fork'): | 772 if not hasattr(os, 'fork'): |
| 762 print _("Sorry, you can't run the server as a daemon" | 773 print _("Sorry, you can't run the server as a daemon" |
| 763 " on this Operating System") | 774 " on this Operating System") |
| 764 sys.exit(0) | 775 sys.exit(0) |
| 765 else: | 776 else: |
| 766 daemonize(config["PIDFILE"]) | 777 if config['NODAEMON']: |
| 778 writepidfile(config["PIDFILE"]) | |
| 779 else: | |
| 780 daemonize(config["PIDFILE"]) | |
| 767 | 781 |
| 768 # create the server | 782 # create the server |
| 769 httpd = config.get_server() | 783 httpd = config.get_server() |
| 770 | 784 |
| 771 if success_message: | 785 if success_message: |
