소스 검색

Collector 76: write pidfile before we daemonize.

Chris McDonough 19 년 전
부모
커밋
040a05df56
2개의 변경된 파일12개의 추가작업 그리고 11개의 파일을 삭제
  1. 0 6
      TODO.txt
  2. 12 5
      src/supervisor/supervisord.py

+ 0 - 6
TODO.txt

@@ -40,12 +40,6 @@
 
 - stop logging all RPC requests in info mode when we ship
 
-- Collector issue 75:
-
-  If the pid file isn't writable, it dies silently. When I ran it with
-  --nodaemon this became clear, but nothing about the error goes into
-  the log file or console when daemonizing.
-
 - Collector issue 76:
 
   Adding -c to the shell script also drove me nuts for a while, since

+ 12 - 5
src/supervisor/supervisord.py

@@ -648,15 +648,22 @@ class Supervisor:
             name = program.name
             self.processes[name] = Subprocess(self.options, program)
         try:
+            pid = os.getpid()
+            try:
+                f = open(self.options.pidfile, 'w')
+                f.write('%s\n' % pid)
+                f.close()
+            except (IOError, os.error):
+                self.options.logger.critical('could not write pidfile %s' %
+                                             self.options.pidfile)
+            else:
+                self.options.logger.info('supervisord started with pid %s' %
+                                         pid)
+                
             self.openhttpserver()
             self.setsignals()
             if not self.options.nodaemon:
                 self.daemonize()
-            pid = os.getpid()
-            f = open(self.options.pidfile, 'w')
-            f.write('%s\n' % pid)
-            f.close()
-            self.options.logger.info('supervisord started with pid %s' % pid)
             self.runforever(test)
         finally:
             try: