From bd54bfc9e83f79b10ad0cad77c91efcde392f807 Mon Sep 17 00:00:00 2001 From: Ethan Dye Date: Tue, 17 Dec 2024 20:53:54 -0700 Subject: [PATCH] Improve shutdown detection Signed-off-by: Ethan Dye --- zram-config | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/zram-config b/zram-config index 13e5859..2ce5883 100755 --- a/zram-config +++ b/zram-config @@ -239,7 +239,7 @@ removeZdir() { removeZswap() { log "INFO" "Beginning removal of swap device." - if [[ -z $SHUTDOWN ]] && swapoff "/dev${ZRAM_DEV}" &> /dev/null; then + if [[ -z $SHUTDOWN ]] && ! swapoff "/dev${ZRAM_DEV}" &> /dev/null; then log "ERROR" "Failed to swapoff /dev${ZRAM_DEV}." return 1 fi @@ -279,7 +279,7 @@ serviceConfiguration() { else if [[ $(systemctl is-active rsyslog.service) == "active" ]]; then export rsyslogActive="true" - if ! systemctl --no-block stop syslog.socket; then + if ! systemctl stop syslog.socket; then log "ERROR" "Failed to stop syslog service." return 1 fi @@ -290,7 +290,7 @@ serviceConfiguration() { log "ERROR" "Failed to flush journal." return 1 fi - if ! systemctl --no-block stop systemd-journald.socket systemd-journald-audit.socket systemd-journald-dev-log.socket; then + if ! systemctl stop systemd-journald.socket systemd-journald-audit.socket systemd-journald-dev-log.socket; then log "ERROR" "Failed to stop journald service." return 1 fi @@ -323,8 +323,8 @@ TMPDIR="/usr/local/lib/zram-config" ZDIR="/opt/zram" ZLOG="/usr/local/share/zram-config/log/zram-config.log" OS="$(grep -o '^ID=.*$' /etc/os-release | cut -d'=' -f2)" -if [[ -s /run/systemd/shutdown/scheduled ]]; then - SHUTDOWN="1" +if systemctl list-jobs | grep -q 'shutdown.target.*start' || systemctl list-jobs | grep -q 'reboot.target.*start'; then + SHUTDOWN=1 fi case "$1" in @@ -375,7 +375,7 @@ case "$1" in TARGET_DIR="$5" BIND_DIR="$6" OLDLOG_DIR="$7" - serviceConfiguration "stop" + [[ -z $SHUTDOWN ]] && serviceConfiguration "stop" createZdir ;; esac @@ -420,7 +420,7 @@ case "$1" in ZRAM_DEV="$2" TARGET_DIR="$3" BIND_DIR="$4" - [[ -z $SHUTDOWN ]] && serviceConfiguration "stop" + serviceConfiguration "stop" removeZdir ;; esac