Skip to content
This repository
Browse code

Merge pull request #2 from jaekwon/master

allows lamson to be run as a normal (nondaemon) process
  • Loading branch information...
commit 1cb3f2c73d05afdac61e368466888c00cbdb6e93 2 parents a6ff7a6 + 3bb3263
Zed A. Shaw authored

Showing 2 changed files with 17 additions and 6 deletions. Show diff stats Hide diff stats

  1. +4 4 lamson/commands.py
  2. +13 2 lamson/utils.py
8 lamson/commands.py
@@ -39,7 +39,7 @@
39 39
40 40 def log_command(port=8825, host='127.0.0.1', chroot=False,
41 41 chdir=".", uid=False, gid=False, umask=False, pid="./run/log.pid",
42   - FORCE=False):
  42 + FORCE=False, debug=False):
43 43 """
44 44 Runs a logging only server on the given hosts and port. It logs
45 45 each message it receives and also stores it to the run/queue
@@ -59,7 +59,7 @@ def log_command(port=8825, host='127.0.0.1', chroot=False,
59 59 uid or gid without doing the priv drop operation.
60 60 """
61 61 loader = lambda: utils.make_fake_settings(host, port)
62   - utils.start_server(pid, FORCE, chroot, chdir, uid, gid, umask, loader)
  62 + utils.start_server(pid, FORCE, chroot, chdir, uid, gid, umask, loader, debug)
63 63
64 64
65 65 def send_command(port=8825, host='127.0.0.1', username=False, password=False,
@@ -110,7 +110,7 @@ def sendmail_command(port=8825, host='127.0.0.1', debug=0, TRAILING=None):
110 110
111 111
112 112 def start_command(pid='./run/smtp.pid', FORCE=False, chroot=False, chdir=".",
113   - boot="config.boot", uid=False, gid=False, umask=False):
  113 + boot="config.boot", uid=False, gid=False, umask=False, debug=False):
114 114 """
115 115 Runs a lamson server out of the current directory:
116 116
@@ -118,7 +118,7 @@ def start_command(pid='./run/smtp.pid', FORCE=False, chroot=False, chdir=".",
118 118 -umask False -uid False -gid False -boot config.boot
119 119 """
120 120 loader = lambda: utils.import_settings(True, from_dir=os.getcwd(), boot_module=boot)
121   - utils.start_server(pid, FORCE, chroot, chdir, uid, gid, umask, loader)
  121 + utils.start_server(pid, FORCE, chroot, chdir, uid, gid, umask, loader, debug)
122 122
123 123
124 124 def stop_command(pid='./run/smtp.pid', KILL=False, ALL=False):
15 lamson/utils.py
@@ -95,14 +95,15 @@ def check_for_pid(pid, force):
95 95 os.unlink(pid)
96 96
97 97
98   -def start_server(pid, force, chroot, chdir, uid, gid, umask, settings_loader):
  98 +def start_server(pid, force, chroot, chdir, uid, gid, umask, settings_loader, debug):
99 99 """
100 100 Starts the server by doing a daemonize and then dropping priv
101 101 accordingly. It will only drop to the uid/gid given if both are given.
102 102 """
103 103 check_for_pid(pid, force)
104 104
105   - daemonize(pid, chdir, chroot, umask, files_preserve=[])
  105 + if not debug:
  106 + daemonize(pid, chdir, chroot, umask, files_preserve=[])
106 107
107 108 sys.path.append(os.getcwd())
108 109
@@ -114,3 +115,13 @@ def start_server(pid, force, chroot, chdir, uid, gid, umask, settings_loader):
114 115 logging.warning("You probably meant to give a uid and gid, but you gave: uid=%r, gid=%r. Will not change to any user.", uid, gid)
115 116
116 117 settings.receiver.start()
  118 +
  119 + if debug:
  120 + print "Lamson started in debug mode. ctrl-c to quit..."
  121 + import time
  122 + try:
  123 + while True:
  124 + time.sleep(100000)
  125 + except KeyboardInterrupt:
  126 + # hard quit, since receiver starts a new thread. dirty but works
  127 + os._exit(1)

0 comments on commit 1cb3f2c

Please sign in to comment.
Something went wrong with that request. Please try again.