|
|
@@ -3,21 +3,36 @@ def get_form(form):
|
|
|
return form
|
|
|
|
|
|
def submit_form(inp, form):
|
|
|
- from subprocess import run, PIPE
|
|
|
+ from subprocess import run, PIPE, Popen, DEVNULL
|
|
|
+ import signal
|
|
|
resp = {
|
|
|
"ok": True,
|
|
|
+ "out": "",
|
|
|
+ "err": "",
|
|
|
}
|
|
|
try:
|
|
|
service = inp["service"]
|
|
|
action = inp["action"]
|
|
|
- proc = run(["systemctl", action ]+service, stderr=PIPE, stdout=PIPE)
|
|
|
- resp["ok"] = proc.returncode == 0
|
|
|
- resp["err"] = proc.stderr.decode()
|
|
|
- resp["out"] = proc.stdout.decode()
|
|
|
+ async_flag = inp["async_flag"]
|
|
|
+ CMD = ["systemctl", action ]+service
|
|
|
+ if async_flag:
|
|
|
+ def preexec():
|
|
|
+ # os.setpgrp()
|
|
|
+ signal.signal(signal.SIGINT, signal.SIG_IGN)
|
|
|
+
|
|
|
+ proc = Popen(CMD,
|
|
|
+ stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL,
|
|
|
+ preexec_fn=preexec)
|
|
|
+ resp["ok"] = True
|
|
|
+ resp["out"] = "Signal Sent: "+ " ".join(CMD)
|
|
|
+ else:
|
|
|
+ proc = run(CMD, stderr=PIPE, stdout=PIPE)
|
|
|
+ resp["ok"] = proc.returncode == 0
|
|
|
+ resp["err"] = proc.stderr.decode()
|
|
|
+ resp["out"] = proc.stdout.decode()
|
|
|
except Exception as ex:
|
|
|
resp["ok"] = False
|
|
|
resp["err"] = str(ex)
|
|
|
|
|
|
return resp
|
|
|
|
|
|
-
|