log.info('chunked_http_response feature %s' % (conf.DAV.getboolean('chunked_http_response') and 'ON' or 'OFF' )) log.info('http_request_use_iterator feature %s' % (conf.DAV.getboolean('http_request_use_iterator') and 'ON' or 'OFF' )) log.info('http_response_use_iterator feature %s' % (conf.DAV.getboolean('http_response_use_iterator') and 'ON' or 'OFF' )) if daemonize: # check if pid file exists if os.path.exists('/tmp/pydav%s.pid' % counter) and daemonaction not in ['status', 'stop']: log.error( 'Found another instance! Either use -i to specifiy another instance number or remove /tmp/pydav%s.pid!' % counter) sys.exit(3) startstop(stdout='/tmp/pydav%s.log' % counter, stderr='/tmp/pydav%s.err' % counter, pidfile='/tmp/pydav%s.pid' % counter, startmsg='>> Started PyWebDAV (PID: %s)', action=daemonaction) # start now handler = DAVAuthHandler if mysql == True: handler = MySQLAuthHandler # injecting options handler._config = conf runserver(port, host, directory, verbose, noauth, user, password, handler=handler) if __name__ == '__main__':
'http_response_use_iterator feature %s' % (conf.DAV.getboolean('http_response_use_iterator') and 'ON' or 'OFF')) if daemonize: # check if pid file exists if os.path.exists('/tmp/pydav%s.pid' % counter) and daemonaction not in ['status', 'stop']: log.error( 'Found another instance! Either use -i to specifiy another instance number or remove /tmp/pydav%s.pid!' % counter) sys.exit(3) startstop(stdout='/tmp/pydav%s.log' % counter, stderr='/tmp/pydav%s.err' % counter, pidfile='/tmp/pydav%s.pid' % counter, startmsg='>> Started PyWebDAV (PID: %s)', action=daemonaction) # start now handler = DAVAuthHandler if mysql == True: handler = MySQLAuthHandler # injecting options handler._config = conf runserver(port, host, directory, verbose,
ap.add_argument("-l", "--logfile", help="Log file", type=str, default=None) args = ap.parse_args() pwd = os.getcwd() configFileName = os.path.basename(args.config) configDir = os.path.dirname(args.config) if configDir is None or len(configDir) == 0: configDir = pwd configFile = "%s/%s" % (configDir, configFileName) isDaemon = False if args.daemon is not None: pidfile = args.pidfile daemonize.startstop(action=args.daemon, stdout='/dev/null', pidfile=pidfile) isDaemon = True mainParms = { 'startupDirectory': pwd, 'configFile': configFile, 'isDaemon': isDaemon, 'logFile': args.logfile } try: main(mainParms) except Exception as e: print(e) if args.daemon is not None:
#!/usr/bin/python import run_cmd import daemonize import os, os.path, sys from Constants import * LOG_DIR = '/var/log/groupmind' LOG_FILE = join(LOG_DIR, 'gm.log') ERR_FILE = join(LOG_DIR, 'gm.err') PID_FILE = '/var/run/groupmind.pid' # ensure the correct directories exist if not os.path.exists(LOG_DIR): os.makedirs(LOG_DIR) # first fork this process to a daemon daemonize.startstop(stdout=LOG_FILE, stderr=ERR_FILE, pidfile=PID_FILE) # start the server run_cmd.main()
class TestObject: def pow(self, x, y): return pow(x, y) def add(self, x, y): return x + y def divide(self, x, y): return float(x) / float(y) class AsyncXMLRPCServer(SocketServer.ThreadingMixIn, DocXMLRPCServer): def verify_request(self, request, client_address): if client_address[0] in accessList: return 1 else: return 0 from daemonize import startstop if __name__ == '__main__': # daemonize startstop(stdout='/tmp/deamonize.log', pidfile='/tmp/deamonize.pid') server = AsyncXMLRPCServer(('', 8000), DocXMLRPCRequestHandler) server.register_instance(TestObject()) server.serve_forever()
SIGTERM_SENT = False def sigterm_handler(signum, frame): print >>sys.stderr, "SIGTERM handler. Shutting Down." global SIGTERM_SENT if not SIGTERM_SENT: SIGTERM_SENT = True print >>sys.stderr, "Sending TERM to PG" os.killpg(0, signal.SIGTERM) sys.exit() def main(): # set session ID to this process so we can kill group in sigterm handler os.setsid() signal.signal(signal.SIGTERM, sigterm_handler) while 1: print >> sys.stdout, "Hyun Seung Bum" sleep(2) from daemonize import startstop if __name__ == "__main__": startstop(stdout="/tmp/example.log", pidfile="/tmp/example.pid") main()
# 调用命令行,设置看门狗定时器超时时间 cl = wdt_cmd_line % 60 os.system(cl) sys.stdout.flush() else: sys.stdout.write ('Reboot now.\n') sys.stdout.flush() os.system('shutdown -r now') c = c + 1 time.sleep(10) def exit_clean(): ''' 守护进程结束后调用本函数,做清理工作 ''' cl = wdt_cmd_line % 0 os.system(cl) sys.stdout.write('monitor exit.\n') # 主入口函数 if __name__ == "__main__": # startstop函数处理start/stop/restart,其中start/restart将本进程daemon化,stop将发送KILL信号至已启动的进程; startstop(stdout=log_file, pidfile=pid_file) if sys.argv[1] in ('start', 'restart'): main_routine() if sys.argv[1] in ('stop',): exit_clean()