community-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1728844 - in /comdev/projects.apache.org/scripts/cronjobs: pubsubber.py pubsubber.sh
Date Sat, 06 Feb 2016 15:03:13 GMT
Author: sebb
Date: Sat Feb  6 15:03:13 2016
New Revision: 1728844

URL: http://svn.apache.org/viewvc?rev=1728844&view=rev
Log:
Add logging for the daemon process

Modified:
    comdev/projects.apache.org/scripts/cronjobs/pubsubber.py
    comdev/projects.apache.org/scripts/cronjobs/pubsubber.sh

Modified: comdev/projects.apache.org/scripts/cronjobs/pubsubber.py
URL: http://svn.apache.org/viewvc/comdev/projects.apache.org/scripts/cronjobs/pubsubber.py?rev=1728844&r1=1728843&r2=1728844&view=diff
==============================================================================
--- comdev/projects.apache.org/scripts/cronjobs/pubsubber.py (original)
+++ comdev/projects.apache.org/scripts/cronjobs/pubsubber.py Sat Feb  6 15:03:13 2016
@@ -6,6 +6,7 @@ from threading import Thread
 from datetime import datetime
 import os
 import sys
+import logging
 
 version = 2
 if sys.hexversion < 0x03000000:
@@ -19,6 +20,7 @@ else:
 
 
 debug = False
+logger = None
 watching={} # dict: key = path to watch, value = set() of paths to update on match
 
 ###########################################################
@@ -29,7 +31,12 @@ class daemon:
 
         Usage: subclass the daemon class and override the run() method."""
 
-        def __init__(self, pidfile): self.pidfile = pidfile
+        def __init__(self, pidfile, logfile = None):
+            self.pidfile = pidfile
+            if logfile == None:
+                self.logfile = os.devnull
+            else:
+                self.logfile = logfile
         
         def daemonize(self):
                 """Deamonize class. UNIX double fork mechanism."""
@@ -63,8 +70,8 @@ class daemon:
                 sys.stdout.flush()
                 sys.stderr.flush()
                 si = open(os.devnull, 'r')
-                so = open(os.devnull, 'a+')
-                se = open(os.devnull, 'a+')
+                so = open(self.logfile, 'a+')
+                se = open(self.logfile, 'a+')
 
                 os.dup2(si.fileno(), sys.stdin.fileno())
                 os.dup2(so.fileno(), sys.stdout.fileno())
@@ -76,8 +83,10 @@ class daemon:
                 pid = str(os.getpid())
                 with open(self.pidfile,'w+') as f:
                         f.write(pid + '\n')
+                logger.info("Created %s", self.pidfile)
         
         def delpid(self):
+                logger.info("Removing %s", self.pidfile)
                 os.remove(self.pidfile)
 
         def start(self):
@@ -180,6 +189,7 @@ class PubSubClient(Thread):
         self.setDaemon(True)
 
     def run(self):
+        logger.info("Watching %s", watching)
         while True:
             
             self.req = None
@@ -190,8 +200,9 @@ class PubSubClient(Thread):
                     else:
                         self.req = urllib2.urlopen(self.url, None, 30)
                     
+                    logger.info("Connected to %s", self.url)
                 except:
-                    
+                    logger.warn("Failed to connect to %s", self.url)
                     time.sleep(30)
                     continue
                 
@@ -229,8 +240,10 @@ class PubSubClient(Thread):
                                         print("Matched 'r" + str(revision) + "'; would run
'svn up " + filePath + "'")
                                     else:
                                         time.sleep(3)
+                                        logger.info("svn up %s", filePath)
                                         subprocess.call(['svn','up', filePath])
                             else:
+                                logger.debug("Did not match 'r" + str(revision) + "' against
' " + str(watching.keys()) + "'")
                                 if debug:
                                     print("Did not match 'r" + str(revision) + "' against
' " + str(watching.keys()) + "'")
                     
@@ -278,7 +291,7 @@ def main():
         try:
             time.sleep(60)
         except KeyboardInterrupt:
-            print("Detected shutdown interrupt")
+            logger.info("Detected shutdown interrupt")
             pass
 
 ##############
@@ -304,7 +317,15 @@ def handle_args(args):
                 watching[args[i]] = set([args[i+1]])
 
 if __name__ == "__main__":
-        daemon = MyDaemon('/tmp/pubsubber.pid')
+        logger = logging.getLogger('pubsubber')
+        logger.setLevel(logging.INFO)
+        formatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s')
+        ch = logging.StreamHandler()
+        ch.setFormatter(formatter)
+        logger.addHandler(ch)
+        logfile = os.environ.get('LOGFILE')
+        logger.info("LOGFILE=%s", logfile)
+        daemon = MyDaemon('/tmp/pubsubber.pid', logfile)
         if len(sys.argv) >= 2:
                 if 'start' == sys.argv[1]:
                     handle_args(sys.argv[2:])

Modified: comdev/projects.apache.org/scripts/cronjobs/pubsubber.sh
URL: http://svn.apache.org/viewvc/comdev/projects.apache.org/scripts/cronjobs/pubsubber.sh?rev=1728844&r1=1728843&r2=1728844&view=diff
==============================================================================
--- comdev/projects.apache.org/scripts/cronjobs/pubsubber.sh (original)
+++ comdev/projects.apache.org/scripts/cronjobs/pubsubber.sh Sat Feb  6 15:03:13 2016
@@ -12,7 +12,7 @@ echo '>>>'
 echo Starting $SCRIPT at $(date)
 export
 
-ERRTEE=1 python3 -u $SCRIPT start \
+ERRTEE=1 LOGFILE=$LOGDIR/${BASE}_daemon.log python3 -u $SCRIPT start \
    comdev/projects.apache.org /var/www/projects.apache.org/ \
    comdev/reporter.apache.org /var/www/reporter.apache.org/
 



Mime
View raw message