systemd working with proper logging functionality

This commit is contained in:
Adnan Hodzic 2020-01-03 14:09:07 +01:00
parent aab5f17d9c
commit 2490de007a
4 changed files with 85 additions and 27 deletions

View File

@ -76,7 +76,10 @@ def deploy():
os.system("cp auto-cpufreq.py /usr/bin/auto-cpufreq") os.system("cp auto-cpufreq.py /usr/bin/auto-cpufreq")
print("\n* Deploy auto-cpufreq daemon deploy script") print("\n* Deploy auto-cpufreq daemon deploy script")
os.system("cp scripts/auto-cpufreq-daemon.sh /usr/bin/auto-cpufreq-daemon") os.system("cp scripts/auto-cpufreq-deploy.sh /usr/bin/auto-cpufreq-deploy")
#print("\n* Deploy auto-cpufreq daemon run script")
#os.system("cp scripts/auto-cpufreq-run.sh /usr/bin/auto-cpufreq-run")
print("\n* Deploy auto-cpufreq daemon removal script") print("\n* Deploy auto-cpufreq daemon removal script")
os.system("cp scripts/auto-cpufreq-remove.sh /usr/bin/auto-cpufreq-remove") os.system("cp scripts/auto-cpufreq-remove.sh /usr/bin/auto-cpufreq-remove")
@ -85,13 +88,13 @@ def deploy():
os.system("cp scripts/auto-cpufreq.service /lib/systemd/system/auto-cpufreq.service") os.system("cp scripts/auto-cpufreq.service /lib/systemd/system/auto-cpufreq.service")
# run auto-cpufreq daemon deploy script # run auto-cpufreq daemon deploy script
s.call("/usr/bin/auto-cpufreq-daemon", shell=True) s.call("/usr/bin/auto-cpufreq-deploy", shell=True)
print("auto-cpufreq daemon started and will automatically start at boot time.") #print("auto-cpufreq daemon started and will automatically start at boot time.")
print("\nTo disable and remove auto-cpufreq daemon, run:\nsudo auto-cpufreq --remove") #print("\nTo disable and remove auto-cpufreq daemon, run:\nsudo auto-cpufreq --remove")
print("\nTo view live auto-cpufreq daemon logs, run:\nauto-cpufreq --log") #print("\nTo view live auto-cpufreq daemon logs, run:\nauto-cpufreq --log")
footer(79) #footer(79)
# remove auto-cpufreq daemon # remove auto-cpufreq daemon
def remove(): def remove():
@ -102,7 +105,8 @@ def remove():
#if os.path.exists(auto_cpufreq_log_file): #if os.path.exists(auto_cpufreq_log_file):
# os.remove(auto_cpufreq_log_file) # os.remove(auto_cpufreq_log_file)
# delete /var/log/auto-cpufreq.log file # delete /var/log/auto-cpufreq.log file
os.remove(auto_cpufreq_log_file) #print("\n* Delete log file")
#os.remove(auto_cpufreq_log_file)
print("* Turn on bluetooth on boot") print("* Turn on bluetooth on boot")
btconf="/etc/bluetooth/main.conf" btconf="/etc/bluetooth/main.conf"
@ -115,20 +119,35 @@ def remove():
f.truncate() f.truncate()
f.write(content.replace(change_set, orig_set)) f.write(content.replace(change_set, orig_set))
except: except:
print("\nERROR:\nWas unable to turn off bluetooth on boot") print("\nERROR:\nWas unable to turn on bluetooth on boot")
print("\n* Remove auto-cpufreq daemon deploy script") #f os.path("/usr/bin/auto-cpufreq-deploy"):
os.remove("/usr/bin/auto-cpufreq-daemon") ## print("\n* Remove auto-cpufreq daemon deploy script")
# os.remove("/usr/bin/auto-cpufreq-deploy")
#if os.path("/usr/bin/auto-cpufreq-run"):
# print("\n* Remove auto-cpufreq daemon run script")
# os.remove("/usr/bin/auto-cpufreq-run")
# run auto-cpufreq daemon deploy script # run auto-cpufreq daemon deploy script
s.call("/usr/bin/auto-cpufreq-remove", shell=True) s.call("/usr/bin/auto-cpufreq-remove", shell=True)
if os.path.isfile("/lib/systemd/system/auto-cpufreq.service"): #if os.path("/usr/bin/auto-cpufreq-remove"):
print("\n* Remove auto-cpufreq systemd unit file") # print("\n* Remove auto-cpufreq-remove script")
os.remove("/lib/systemd/system/auto-cpufreq.service") # os.remove("/usr/bin/auto-cpufreq-remove")
print("\n* Remove auto-cpufreq binary") #if os.path.isfile("/lib/systemd/system/auto-cpufreq.service"):
os.remove("/usr/bin/auto-cpufreq") # print("\n* Remove auto-cpufreq systemd unit file")
# os.remove("/lib/systemd/system/auto-cpufreq.service")
#if os.path("/usr/bin/auto-cpufreq"):
# print("\n* Remove auto-cpufreq binary")
# os.remove("/usr/bin/auto-cpufreq")
# delete /var/log/auto-cpufreq.log if it exists
#if os.path.exists(auto_cpufreq_log_file):
# print("\n* Delete log file")
# os.remove(auto_cpufreq_log_file)
print("\nauto-cpufreq daemon removed") print("\nauto-cpufreq daemon removed")
@ -157,12 +176,17 @@ def root_check():
# refresh countdown # refresh countdown
def countdown(s): def countdown(s):
# Fix for wrong log output and "TERM environment variable not set"
os.environ['TERM'] = 'xterm'
for remaining in range(s, 0, -1): for remaining in range(s, 0, -1):
sys.stdout.write("\r") sys.stdout.write("\r")
sys.stdout.write("\t\t\t\"auto-cpufreq\" refresh in:{:2d}".format(remaining)) sys.stdout.write("\t\t\t\"auto-cpufreq\" refresh in:{:2d}".format(remaining))
sys.stdout.flush() sys.stdout.flush()
time.sleep(1) time.sleep(1)
#sys.stdout.write("\rComplete! \n")
# set powersave and enable turbo # set powersave and enable turbo
def set_powersave(): def set_powersave():
print("Setting to use: powersave") print("Setting to use: powersave")
@ -368,6 +392,7 @@ def sysinfo():
#print("\nCPU fan speed:", current_fans, "RPM") #print("\nCPU fan speed:", current_fans, "RPM")
def read_log(): def read_log():
# deploy cpufreqctl script (if missing) # deploy cpufreqctl script (if missing)
if os.path.isfile(auto_cpufreq_log_file): if os.path.isfile(auto_cpufreq_log_file):
# read /var/log/auto-cpufreq.log # read /var/log/auto-cpufreq.log
@ -386,6 +411,10 @@ def log_check():
footer(79) footer(79)
sys.exit() sys.exit()
def trunk():
with open(auto_cpufreq_log_file, 'w'):
pass
# 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")
@ -416,7 +445,7 @@ def cli(monitor, live, daemon, log):
subprocess.call("clear") subprocess.call("clear")
elif live: elif live:
while True: while True:
log_check() #log_check()
root_check() root_check()
gov_check() gov_check()
cpufreqctl() cpufreqctl()

View File

@ -11,7 +11,7 @@ then
exit 1 exit 1
fi fi
logs_file="/var/log/auto-cpufreq.log" #touch /var/log/auto-cpufreq.log
echo -e "\n* Reloading systemd manager configuration" echo -e "\n* Reloading systemd manager configuration"
systemctl daemon-reload systemctl daemon-reload
@ -22,10 +22,10 @@ systemctl stop auto-cpufreq
echo -e "\n* Starting auto-cpufreq systemd service" echo -e "\n* Starting auto-cpufreq systemd service"
systemctl start auto-cpufreq systemctl start auto-cpufreq
echo -e "\n* Enabling auto-cpufreq systemd service at boot" #echo -e "\n* Enabling auto-cpufreq systemd service at boot"
systemctl enable auto-cpufreq #systemctl enable auto-cpufreq
echo -e "\n* Running auto-cpufreq binary" #echo -e "\n* Running auto-cpufreq binary"
#/usr/bin/python3 /usr/bin/auto-cpufreq --live > $logs_file 2>&1 & #/usr/bin/python3 /usr/bin/auto-cpufreq --live > $logs_file 2>&1 &
echo -e "\n------\n" echo -e "\n------\n"

View File

@ -11,11 +11,42 @@ then
exit 1 exit 1
fi fi
echo -e "\n* Disabling auto-cpufreq systemd service at boot"
systemctl disable auto-cpufreq
echo -e "\n* Stopping auto-cpufreq systemd service" echo -e "\n* Stopping auto-cpufreq systemd service"
systemctl stop auto-cpufreq systemctl stop auto-cpufreq
echo -e "\n* Disabling auto-cpufreq systemd service at boot"
systemctl disable auto-cpufreq
#if [ -f /lib/systemd/system/auto-cpufreq.service ];
#then
# rm /lib/systemd/system/auto-cpufreq.service
# systemctl daemon-reload
#if [ -f /etc/systemd/system/auto-cpufreq.service ];
#then
# rm /etc/systemd/system/auto-cpufreq.service
# systemctl daemon-reload
rm /lib/systemd/system/auto-cpufreq.service
rm /etc/systemd/system/auto-cpufreq.service
echo -e "\n* Reloading systemd manager configuration" echo -e "\n* Reloading systemd manager configuration"
systemctl daemon-reload systemctl daemon-reload
echo -e "reset failed"
systemctl reset-failed
echo -e "\n* Removing auto-cpufreq daemon deploy script"
rm /usr/bin/auto-cpufreq-deploy
echo -e "\n* Removing auto-cpufreq daemon run script"
rm /usr/bin/auto-cpufreq-run
echo -e "\n* Removing auto-cpufreq binary"
rm /usr/bin/auto-cpufreq
echo -e "\n* Removing auto-cpufreq log file"
rm /var/log/auto-cpufreq.log
echo "kill any remaining instances"
pkill -f auto-cpufreq

View File

@ -5,9 +5,7 @@ After=network.target network-online.target
[Service] [Service]
Type=simple Type=simple
User=root User=root
#ExecStart=/bin/bash /usr/bin/auto-cpufreq-daemon
# ToDo: new script which just starts auto-cpufreq (no systemd)
ExecStart=/usr/bin/python3 /usr/bin/auto-cpufreq --live ExecStart=/usr/bin/python3 /usr/bin/auto-cpufreq --live
StandardOutput=file:/var/log/auto-cpufreq.log
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target