Guest User

Angelic Example 0.1

a guest
Dec 17th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import os
  4. import sys
  5. import argparse
  6. from time import sleep
  7.  
  8. from angelic import Daemon
  9.  
  10. if not os.path.exists('./.angelic_example.cfg'):
  11.     with open('./.angelic_example.cfg', 'w') as f:
  12.         f.write('pid_path=./angelic_example.pid\n'
  13.                 'foo=bar\n')
  14.  
  15. daemon = Daemon('angelic_example', debug_log='~/angelic_example_debug.log')
  16. daemon.log.info('Ran the daemon script')
  17.  
  18.  
  19. @daemon.daemonize
  20. def loop(debug=False):
  21.     ct = 0
  22.     while True:
  23.         ct += 1
  24.         if debug:
  25.             sys.stderr.write('%d\t' % ct)
  26.         daemon.log.info('Info logging, count is %d' % ct)
  27.         daemon.log.debug('config value of foo is: %s' % daemon.config['foo'])
  28.         sleep(1)
  29.  
  30.  
  31. @daemon.stop
  32. def its_over():
  33.     daemon.log.info('I was killed! My PID was %s' % str(daemon.get_pid()))
  34.  
  35.  
  36. @daemon.start
  37. def its_begun(debug=False):
  38.     daemon.log.info('It has begun. Debug mode is: %s' % debug)
  39.  
  40.  
  41. parser = argparse.ArgumentParser()
  42. subs = daemon.setup_args(parser)
  43. subs['start'].add_argument('--debug', '-d', action='store_true')
  44. subs['restart'].add_argument('--debug', '-d', action='store_true')
  45. daemon.parse_args(parser)
Advertisement
Add Comment
Please, Sign In to add comment