From d716edc007ebc57433d5fec12a2a42dae80eca4b Mon Sep 17 00:00:00 2001 From: Ethan Dye Date: Sun, 27 Dec 2020 17:30:37 -0700 Subject: [PATCH] Fix shutdown service Fixes: #51 Signed-off-by: Ethan Dye --- zram-config | 15 +++++++++++++-- zram-config.service | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/zram-config b/zram-config index 1295c2f..dbe3e29 100755 --- a/zram-config +++ b/zram-config @@ -223,6 +223,9 @@ serviceConfiguration() { ZSHARE="/usr/local/share/zram-config" ZLOG="${ZSHARE}/log/zram-config.log" ZDIR="/opt/zram" +if [[ $2 == "shutdown" ]]; then + SERVICE="1" +fi if [[ -f /boot/cmdline.txt ]] && grep -qs "init=/bin/ro-root.sh" /boot/cmdline.txt; then ZEPHEMERAL="true" else @@ -282,6 +285,7 @@ case "$1" in TARGET_DIR="$5" BIND_DIR="$6" if [[ $ZEPHEMERAL == "false" ]]; then + serviceConfiguration "stop" createZdir fi ;; @@ -339,6 +343,9 @@ case "$1" in TARGET_DIR="$3" BIND_DIR="$4" if [[ $ZEPHEMERAL == "false" ]]; then + if [[ -z $SERVICE ]]; then + serviceConfiguration "stop" + fi removeZdir fi ;; @@ -348,7 +355,9 @@ case "$1" in TARGET_DIR="$3" BIND_DIR="$4" if [[ $ZEPHEMERAL == "false" ]]; then - serviceConfiguration "stop" + if [[ -z $SERVICE ]]; then + serviceConfiguration "stop" + fi removeZdir fi ;; @@ -372,4 +381,6 @@ case "$1" in exit 1 ;; esac -serviceConfiguration "start" +if [[ -z $SERVICE ]]; then + serviceConfiguration "start" +fi diff --git a/zram-config.service b/zram-config.service index d24aa48..b473565 100644 --- a/zram-config.service +++ b/zram-config.service @@ -8,7 +8,7 @@ Type=simple TimeoutSec=300 RemainAfterExit=yes ExecStart=/usr/local/sbin/zram-config "start" -ExecStop=/usr/local/sbin/zram-config "stop" +ExecStop=/usr/local/sbin/zram-config "stop" "shutdown" [Install] WantedBy=basic.target