Commit cf2a5c34 authored by Pavel Vainerman's avatar Pavel Vainerman

added support for parameter '-r','--run'

parent bf981df4
......@@ -11,17 +11,18 @@ Depends
Usage
-----
prunner -p pid [-d dir | -f file]
prunner -p pid [-d dir | -f file | -r '[params]prog args..']
Help
----
-d | --run-from-dir dir - run programm from directory
-f | --run-from-file file - run programm from file
-p | --monitor-pid pid - pid of main process (for monitoring)
-v | --verbose - Print info messages
--disable-monitor - only run process
-c | --check-period sec - period for check processes. Default: 5 sec
-t | --terminate-timeout sec - timeout for teminate processes (then the processes will be killed). Default: 5 sec
-d | --run-from-dir dir - run programm from directory
-f | --run-from-file file - run programm from file
-r | --run '[params]prog args..' - run programm from command line"
-p | --monitor-pid pid - pid of main process (for monitoring)
-v | --verbose - Print info messages
--disable-monitor - only run process
-c | --check-period sec - period for check processes. Default: 5 sec
-t | --terminate-timeout sec - timeout for teminate processes (then the processes will be killed). Default: 5 sec
Example 1 (run from directory)
------------------------------
......@@ -40,13 +41,13 @@ Example 2 (run from file)
-------------------------
cat runlist.txt
[restart] prog1
[restart] prog1 arg1 arg2
# comment 1
[ignore_fail,restart] prog2
[ignore_fail,restart] prog2 arg1 arg2
# comment 2
[verbose,shell=False] prog3
prog4
prog5
prog4 arg1 arg2
prog5 arg1
prunner -p PID -f ./runlist.txt
......@@ -76,7 +77,12 @@ Example 2 (run from file)
"restart=1,ignore_fail=1" - игнорировать неудачные запуски, но пытаться снова перезапускать
</code>
Example 3
Example 3 (run from command line)
---------------------------------
prunner -p PID -r '[restart] prog1 arg1 arg2' -r '[restart=0,verbose] prog2 arg1 arg2' --run '[shell=0,ignore_fail=0] prog3 arg1 arg2'
Example 4
---------
prunner -p PID -d ./child.d -f runlist.txt
Т.е. можно указывать и каталог и файл одновременно
prunner -p PID -d ./child.d -f runlist.txt -r '[restart] prog1 arg1 arg2'
Т.е. можно указывать и каталог и файл и -r одновременно
......@@ -262,15 +262,11 @@ def read_from_file(fname):
if len(line) == 0 or line.startswith("#"):
continue
p = None
if line.startswith("["):
cmd, params = parse_run_parameters(line)
p = ChildProc(cmd=cmd, params=params)
if not p:
p = ChildProc(cmd=line)
run_list.append(p)
run_list.append(ChildProc(cmd=cmd, params=params))
else:
run_list.append(ChildProc(cmd=line))
return run_list
......@@ -281,10 +277,8 @@ def read_from_dir(dname):
:param dname: directory name (path)
:return: list of 'ChildProc' objects
"""
ret = list()
if not os.path.exists(dname):
return ret
return list()
plist = list()
for f in os.listdir(dname):
......@@ -294,14 +288,49 @@ def read_from_dir(dname):
return plist
def read_from_commandline(param):
params = list()
if isinstance(param, list):
params = param
else:
params.append(param)
plist = list()
skip = False
for i in range(0, len(sys.argv)):
if skip:
skip = False
continue
if sys.argv[i] in params:
if i + 1 >= len(sys.argv):
break
arg = sys.argv[i + 1]
if arg.startswith('-') or arg.startswith('--'):
log_info("(read_from_commandline): ignore '%s' because an argument is required..." % sys.argv[i])
continue
skip = True
if arg.startswith("["):
cmd, params = parse_run_parameters(arg)
plist.append(ChildProc(cmd=cmd, params=params))
else:
plist.append(ChildProc(cmd=arg))
return plist
def usage():
print "-d|--run-from-dir dir - run programm from directory"
print "-f|--run-from-file file - run programm from file"
print "-p|--monitor-pid pid - pid of main process (for monitoring)"
print "-v|--verbose - Print info messages"
print "--disable-monitor - only run process"
print "-c|--check-period sec - period for check processes. Default: %s" % check_alive_period
print "-t|--terminate-timeout sec - timeout for teminate processes (then the processes will be killed). Default: %s" % timeout_for_terminate
print "[-d|--run-from-dir] dir - run programm from directory"
print "[-f|--run-from-file] file - run programm from file"
print "[-r|--run] '[params]prog' - run programm from command line"
print "[-p|--monitor-pid] pid - pid of main process (for monitoring)"
print "[-v|--verbose] - Print info messages"
print "--disable-monitor - only run process"
print "[-c|--check-period] sec - period for check processes. Default: %s" % check_alive_period
print "[-t|--terminate-timeout] sec - timeout for teminate processes (then the processes will be killed). Default: %s" % timeout_for_terminate
if __name__ == "__main__":
......@@ -335,6 +364,8 @@ if __name__ == "__main__":
if len(from_dir):
run_list = run_list + read_from_dir(from_dir)
run_list = run_list + read_from_commandline(['-r', '--run'])
if len(run_list) == 0:
log_error("not found run list. Use -h for help")
exit(1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment