comparison supervisoradmin/add.py @ 6:a1e06f4a8076

last minute tweaks
author Jeff Hammel <k0scist@gmail.com>
date Mon, 13 Apr 2015 13:04:11 -0700
parents d638b8578c78
children
comparison
equal deleted inserted replaced
5:d638b8578c78 6:a1e06f4a8076
19 19
20 template = """[program:{name}] 20 template = """[program:{name}]
21 command={command} 21 command={command}
22 autorestart=true 22 autorestart=true
23 redirect_stderr=true 23 redirect_stderr=true
24 startretries=3 24 startretries={retries}
25 stopasgroup=true 25 stopasgroup=true
26 stopwaitsecs=180 26 stopwaitsecs=180
27 user={user} 27 user={user}
28 """ 28 """
29 29
38 argparse.ArgumentParser.__init__(self, **kwargs) 38 argparse.ArgumentParser.__init__(self, **kwargs)
39 self.add_argument('command', 39 self.add_argument('command',
40 help="command to add") 40 help="command to add")
41 self.add_argument('-n', '--name', dest='name', 41 self.add_argument('-n', '--name', dest='name',
42 help="name of program; by default taken from command") 42 help="name of program; by default taken from command")
43 self.add_argument('-u', '--user', dest='user', default='ubuntu', 43 self.add_argument('-u', '--user', dest='user', default='root',
44 help="run program as this user [DEFAULT: %(default)s]") 44 help="run program as this user [DEFAULT: %(default)s]")
45 self.add_argument('--retries', dest='retries',
46 type=int, default=100,
47 help="number of retries [DEFAULT: %(default)s]")
45 self.add_argument('-o', '--output', dest='output', 48 self.add_argument('-o', '--output', dest='output',
46 type=argparse.FileType('w'), 49 type=argparse.FileType('w'),
47 nargs='?', 50 nargs='?',
48 const=sys.stdout, 51 const=sys.stdout,
49 help="output configuration and exit [DEFAULT: %(default)s]") 52 help="output configuration and exit [DEFAULT: %(default)s]")
76 # output configuration file 79 # output configuration file
77 output = options.output or open(os.path.join(SUPERVISOR_CONF, '{}.conf'.format(name)), 'w') 80 output = options.output or open(os.path.join(SUPERVISOR_CONF, '{}.conf'.format(name)), 'w')
78 81
79 output.write(template.format(name=name, 82 output.write(template.format(name=name,
80 user=options.user, 83 user=options.user,
84 retries=options.retries,
81 command=options.command)) 85 command=options.command))
82 output.close() 86 output.close()
83 87
84 if options.output is None: 88 if options.output is None:
85 # update the supervisor state 89 # update the supervisor state