Running check (#3)
* Check if the daemon is running by querying the PIDs on the system instead of a marker file * code folded for better visibility * code folded for better visibility * adjust to naming conventions * remove unused code * make the `daemon running` warning more simple Co-authored-by: Velimir <vivel@users.noreply.github.com>
This commit is contained in:
parent
0f25cca1ba
commit
83b4ed1c41
|
@ -35,9 +35,6 @@ bat_state = p.sensors_battery().power_plugged
|
||||||
# auto-cpufreq log file
|
# auto-cpufreq log file
|
||||||
auto_cpufreq_log_file = "/var/log/auto-cpufreq.log"
|
auto_cpufreq_log_file = "/var/log/auto-cpufreq.log"
|
||||||
|
|
||||||
# daemon deployment marker
|
|
||||||
daemon_marker = "/etc/opt/auto-cpufreq"
|
|
||||||
|
|
||||||
# deploy cpufreqctl script
|
# deploy cpufreqctl script
|
||||||
def cpufreqctl():
|
def cpufreqctl():
|
||||||
# deploy cpufreqctl script (if missing)
|
# deploy cpufreqctl script (if missing)
|
||||||
|
@ -355,20 +352,27 @@ def read_log():
|
||||||
print("ERROR: auto-cpufreq log is missing.\n\nMake sure to run: \"python3 auto-cpufreq.py --install\" first")
|
print("ERROR: auto-cpufreq log is missing.\n\nMake sure to run: \"python3 auto-cpufreq.py --install\" first")
|
||||||
footer(79)
|
footer(79)
|
||||||
|
|
||||||
def marker_check():
|
def running_check():
|
||||||
if os.path.isfile(daemon_marker):
|
daemon_marker = False
|
||||||
|
for proc in p.process_iter():
|
||||||
|
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
|
||||||
|
|
||||||
|
if daemon_marker:
|
||||||
print("\n" + "-" * 25 + " detected auto-cpufreq daemon" + "-" * 25 + "\n")
|
print("\n" + "-" * 25 + " detected auto-cpufreq daemon" + "-" * 25 + "\n")
|
||||||
print("ERROR: prevention from running multiple instances")
|
print("ERROR: prevention from running multiple instances")
|
||||||
print("\nIt seems like auto-cpufreq daemon is already running.\n\nTo view live log run:\nauto-cpufreq --log")
|
print("\nIt seems like auto-cpufreq daemon is already running.\n")
|
||||||
print("\nTo disable and remove auto-cpufreq daemon, run:\nsudo auto-cpufreq --remove")
|
print("----")
|
||||||
|
print("\nTo view live log run:\n\tauto-cpufreq --log")
|
||||||
footer(79)
|
footer(79)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
def marker_create(f):
|
|
||||||
f = open(f, "w")
|
|
||||||
f.write("auto-cpufreq daemon intsall marker")
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
# cli
|
# cli
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option("--monitor", is_flag=True, help="Monitor and suggest CPU optimizations")
|
@click.option("--monitor", is_flag=True, help="Monitor and suggest CPU optimizations")
|
||||||
|
@ -399,7 +403,7 @@ def cli(monitor, live, daemon, install, log):
|
||||||
subprocess.call("clear")
|
subprocess.call("clear")
|
||||||
elif monitor:
|
elif monitor:
|
||||||
while True:
|
while True:
|
||||||
marker_check()
|
running_check()
|
||||||
root_check()
|
root_check()
|
||||||
gov_check()
|
gov_check()
|
||||||
cpufreqctl()
|
cpufreqctl()
|
||||||
|
@ -409,7 +413,7 @@ def cli(monitor, live, daemon, install, log):
|
||||||
subprocess.call("clear")
|
subprocess.call("clear")
|
||||||
elif live:
|
elif live:
|
||||||
while True:
|
while True:
|
||||||
marker_check()
|
running_check()
|
||||||
root_check()
|
root_check()
|
||||||
gov_check()
|
gov_check()
|
||||||
cpufreqctl()
|
cpufreqctl()
|
||||||
|
@ -420,11 +424,10 @@ def cli(monitor, live, daemon, install, log):
|
||||||
elif log:
|
elif log:
|
||||||
read_log()
|
read_log()
|
||||||
elif install:
|
elif install:
|
||||||
marker_check()
|
running_check()
|
||||||
root_check()
|
root_check()
|
||||||
gov_check()
|
gov_check()
|
||||||
deploy()
|
deploy()
|
||||||
marker_create(daemon_marker)
|
|
||||||
elif remove:
|
elif remove:
|
||||||
root_check()
|
root_check()
|
||||||
remove()
|
remove()
|
||||||
|
|
Loading…
Reference in New Issue