From ea687deb20e984a1b22cdb4561dd46833cbd0782 Mon Sep 17 00:00:00 2001 From: Adnan Hodzic Date: Wed, 5 Feb 2020 21:03:29 +0100 Subject: [PATCH] start snap systemd service if DAEMON env var set to ENABLED --- bin/auto-cpufreq | 55 +++++++++++++++++++++++++++++++++++---------- scripts/daemon.sh | 3 --- snap/snapcraft.yaml | 17 ++------------ 3 files changed, 45 insertions(+), 30 deletions(-) delete mode 100755 scripts/daemon.sh diff --git a/bin/auto-cpufreq b/bin/auto-cpufreq index fbdda36..024de77 100755 --- a/bin/auto-cpufreq +++ b/bin/auto-cpufreq @@ -29,14 +29,27 @@ def main(monitor, live, daemon, install, log): footer(79) else: if daemon: - while True: - root_check() - gov_check() - cpufreqctl() - sysinfo() - set_autofreq() - countdown(5) - subprocess.call("clear") + if os.getenv("PKG_MARKER") == "SNAP" and os.getenv("DAEMON") == "ENABLED": + while True: + root_check() + gov_check() + cpufreqctl() + sysinfo() + set_autofreq() + countdown(5) + subprocess.call("clear") + elif os.getenv("PKG_MARKER") != "SNAP": + while True: + root_check() + gov_check() + cpufreqctl() + sysinfo() + set_autofreq() + countdown(5) + subprocess.call("clear") + else: + sys.exit("Daemon non ENABLED") + exit(1) elif monitor: while True: running_check() @@ -61,11 +74,29 @@ def main(monitor, live, daemon, install, log): # ToDo: fail if log is missing or empty (on) read_log() elif install: - running_check() - root_check() - gov_check() - deploy() + if os.getenv('PKG_MARKER') == "SNAP": + os.environ["DAEMON"] = "ENABLED" + print(os.environ["DAEMON"]) + running_check() + root_check() + gov_check() + # ToDo: + # implement option to restart snap service? + else: + running_check() + root_check() + gov_check() + deploy() + # ToDo: add remove for snap elif remove: + if os.getenv('PKG_MARKER') == "SNAP": + root_check() + # ToDo: remove if not needed? + #kill_process("auto-cpufreq --daemon") + # ToDo: + # implement option to stop and restart snap service? + + else: root_check() remove() diff --git a/scripts/daemon.sh b/scripts/daemon.sh deleted file mode 100755 index d8eebfd..0000000 --- a/scripts/daemon.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -auto-cpufreq --daemon 2>&1 | tee -a /var/log/auto-cpufreq.log diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index a6012f9..48cd7e4 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -17,14 +17,6 @@ parts: plugin: python python-version: python3 source: . - #stage-packages: - # - python3-pip - # - python3-dev - #python-packages: - # - psutil - # - click - # - distro - # - power deploy-cpufrectl: plugin: dump @@ -32,13 +24,6 @@ parts: organize: cpufreqctl.sh: usr/bin/cpufreqctl -# ToDo: remove scripts/daemon - # deploy-demon: - # plugin: dump - # source: scripts - # organize: - # daemon.sh: usr/bin/daemon - apps: auto-cpufreq: command: bin/auto-cpufreq @@ -46,11 +31,13 @@ apps: LC_ALL: C.UTF-8 LANG: C.UTF-8 PKG_MARKER: SNAP + DAEMON: DISABLED auto-cpufreq-service: command: bin/auto-cpufreq --daemon 2>&1 | tee -a /var/log/auto-cpufreq.log environment: LC_ALL: C.UTF-8 LANG: C.UTF-8 PKG_MARKER: SNAP + DAEMON: DISABLED daemon: simple \ No newline at end of file