changeset 4:8a6ee9df8ae5

moving towards service restart
author Jeff Hammel <k0scist@gmail.com>
date Mon, 13 Apr 2015 12:04:00 -0700
parents 350e4298e116
children d638b8578c78
files supervisoradmin/add.py
diffstat 1 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/supervisoradmin/add.py	Mon Feb 09 13:11:09 2015 -0800
+++ b/supervisoradmin/add.py	Mon Apr 13 12:04:00 2015 -0700
@@ -15,7 +15,7 @@
 
 # module globals
 __all__ = ['main', 'SupervisorAdminParser']
-SUPERVISOR_CONF_DIR = '/etc/supervisor/conf.d'
+SUPERVISOR_CONF = '/etc/supervisor/conf.d'
 
 template = """[program:{name}]
 command={command}
@@ -27,6 +27,9 @@
 user={user}
 """
 
+def basename(filename):
+    return os.path.splitext(os.path.basename(filename))[0]
+
 class SupervisorAdminParser(argparse.ArgumentParser):
     """CLI option parser"""
     def __init__(self, **kwargs):
@@ -39,6 +42,11 @@
                           help="name of program; by default taken from command")
         self.add_argument('-u', '--user', dest='user', default='ubuntu',
                           help="run program as this user [DEFAULT: %(default)s]")
+        self.add_argument('-o', '--output', dest='output',
+                          type=argparse.FileType('w'),
+                          nargs='?',
+                          const=sys.stdout,
+                          help="output configuration and exit [DEFAULT: %(default)s]")
         self.options = None
 
     def parse_args(self, *args, **kw):
@@ -63,7 +71,10 @@
         parser.error("Please supply a command")
 
     # name
-    name = options.name or os.path.basename(command[0])
+    name = options.name or basename(command[0])
+
+    # output configuration file
+    output = options.output or os.path.join(SUPERVISOR_CONF, '{}.conf'.format(name))
 
     print (template.format(name=name,
                            user=options.user,
@@ -71,5 +82,3 @@
 
 if __name__ == '__main__':
     main()
-
-