123456789101112131415161718192021222324252627282930313233 |
- # -*- coding: utf-8 -*-
- import os
- import sys
- import time
- from demeter.core import *
- from daemon import Daemon
- class MyTestDaemon(Daemon):
- def run(self):
- sys.stdout.write('Daemon started with pid {}\n'.format(os.getpid()))
- while True:
- sys.stdout.write('Daemon Alive! {}\n'.format(time.ctime()))
- sys.stdout.flush()
- time.sleep(5)
- if __name__ == '__main__':
- daemon = MyTestDaemon(key='deamon')
- if len(sys.argv) != 2:
- print('Usage: {} [start|stop]'.format(sys.argv[0]), file=sys.stderr)
- raise SystemExit(1)
- if 'start' == sys.argv[1]:
- daemon.start()
- elif 'stop' == sys.argv[1]:
- daemon.stop()
- elif 'restart' == sys.argv[1]:
- daemon.restart()
- else:
- print('Unknown command {!r}'.format(sys.argv[1]), file=sys.stderr)
- raise SystemExit(1)
|