remove Dashboard Views from user admin
[plstackapi.git] / planetstack / planetstack-backend.py
1 #!/usr/bin/env python
2 import os
3 import argparse
4 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "planetstack.settings")
5 from observer.backend import Backend
6 from planetstack.config import Config
7
8 try:
9     from django import setup as django_setup # django 1.7
10 except:
11     django_setup = False
12
13 config = Config()
14
15 # after http://www.erlenstar.demon.co.uk/unix/faq_2.html
16 def daemon():
17     """Daemonize the current process."""
18     if os.fork() != 0: os._exit(0)
19     os.setsid()
20     if os.fork() != 0: os._exit(0)
21     os.umask(0)
22     devnull = os.open(os.devnull, os.O_RDWR)
23     os.dup2(devnull, 0)
24     # xxx fixme - this is just to make sure that nothing gets stupidly lost - should use devnull
25     logdir=os.path.dirname(config.observer_logfile)
26     # when installed in standalone we might not have httpd installed
27     if not os.path.isdir(logdir): os.mkdir(logdir)
28     crashlog = os.open('%s'%config.observer_logfile, os.O_RDWR | os.O_APPEND | os.O_CREAT, 0644)
29     os.dup2(crashlog, 1)
30     os.dup2(crashlog, 2)
31
32 def main():
33     # Generate command line parser
34     parser = argparse.ArgumentParser(usage='%(prog)s [options]')
35     parser.add_argument('-d', '--daemon', dest='daemon', action='store_true', default=False,
36                         help='Run as daemon.')
37     # smbaker: util/config.py parses sys.argv[] directly to get config file name; include the option here to avoid
38     #   throwing unrecognized argument exceptions
39     parser.add_argument('-C', '--config', dest='config_file', action='store', default="/opt/planetstack/plstackapi_config",
40                         help='Name of config file.')
41     args = parser.parse_args()
42
43     if args.daemon: daemon()
44
45     if django_setup: # 1.7
46         django_setup()
47
48     backend = Backend()
49     backend.run()    
50
51 if __name__ == '__main__':
52     
53     main()