disable running multiple instances (needs improvements on snap)

This commit is contained in:
Adnan Hodzic 2020-02-08 17:04:43 +01:00
parent 71a8b92e04
commit 33837c97a3
2 changed files with 28 additions and 25 deletions

View File

@ -41,7 +41,6 @@ def main(monitor, live, daemon, install, log):
countdown(5)
subprocess.call("clear")
elif os.getenv("PKG_MARKER") != "SNAP":
# ToDo: disable running daemon without install (like on snap)
while True:
root_check()
gov_check()
@ -57,9 +56,8 @@ def main(monitor, live, daemon, install, log):
exit(1)
elif monitor:
while True:
# ToDo: doesn't work on snap
running_check()
root_check()
running_daemon() # doesn't work on snap
gov_check()
cpufreqctl()
sysinfo()
@ -68,9 +66,8 @@ def main(monitor, live, daemon, install, log):
subprocess.call("clear")
elif live:
while True:
# ToDo: doesn't work on snap
running_check()
root_check()
running_daemon() # doesn't work on snap
gov_check()
cpufreqctl()
sysinfo()
@ -82,15 +79,15 @@ def main(monitor, live, daemon, install, log):
read_log()
elif install:
if os.getenv('PKG_MARKER') == "SNAP":
running_check()
root_check()
running_daemon() # doesn't work on snap
gov_check()
s.run("snapctl set daemon=enabled", shell=True)
s.run("snapctl start --enable auto-cpufreq", shell=True)
deploy_complete_msg()
else:
running_check()
root_check()
running_daemon() # doesn't work on snap
gov_check()
deploy()
deploy_complete_msg()

View File

@ -388,23 +388,29 @@ def read_log():
print("ERROR: auto-cpufreq log is missing.\n\nMake sure to run: \"auto-cpufreq --install\" first")
footer(79)
def running_check():
daemon_marker = False
for proc in p.process_iter():
# check if program (argument) is running
def is_running(program, argument):
# iterate over all process id's found by psutil
for pid in psutil.pids():
try:
pinfo = proc.as_dict(attrs=['pid', 'name', 'cmdline'])
except p.NoSuchProcess:
pass
else:
if pinfo['name'] == 'python3' and \
'/usr/bin/auto-cpufreq' in pinfo['cmdline'] and '--daemon' in pinfo['cmdline']:
daemon_marker = True
# requests the process information corresponding to each process id
p = psutil.Process(pid)
# check if value of program-variable that was used to call the function matches the name field of the plutil.Process(pid) output
if program in p.name():
# check output of p.name(), output name of program
# p.cmdline() - echo the exact command line via which p was called.
for arg in p.cmdline():
if argument in str(arg):
return True
else:
pass
else:
pass
except:
continue
if daemon_marker:
print("\n" + "-" * 25 + " detected auto-cpufreq daemon" + "-" * 25 + "\n")
print("ERROR: prevention from running multiple instances")
print("\nIt seems like auto-cpufreq daemon is already running.\n")
print("----")
print("\nTo view live log run:\n\tauto-cpufreq --log")
footer(79)
sys.exit()
# check if auto-cpufreq --daemon is running
def running_daemon():
if is_running('auto-cpufreq', '--daemon'):
deploy_complete_msg()
exit(1)