__author__ = '*****@*****.**' from optparse import OptionParser from performance_server import * from daemonize import * if __name__ == '__main__': parser = OptionParser() parser.add_option("-d", "--daemon", action="store_true", dest="is_daemon", help="Run script in daemon mode.") parser.add_option("-l", "--log", dest="stdout", default='/var/log/counters/counters.log', help="Run script in daemon mode.") (options, args) = parser.parse_args() if options.is_daemon: daemonize(stdout=options.stdout, pidfile='var/run/counters.pid') server = PerformanceCountersServer() server.run()
#/usr/bin/env python # -*- coding: utf-8 -*- #pip install daemonize import daemonize #from daemonize import daemonize import time import sys def mod_5_watcher(): start_time = time.time() end_time = start_time + 20 while time.time() < end_time: now = time.time() if int(now) % 5 == 0: sys.stderr.write('Mod 5 at %s\n' % now) else: sys.stdout.write('No mod 5 at %s\n' % now) if __name__ == '__main__': daemonize(stdout='/tmp/stdout.log', stderr='/tmp/stderr.log') mod_5_watcher()