Skip to content

Commit

Permalink
Improve shutdown detection
Browse files Browse the repository at this point in the history
Signed-off-by: Ethan Dye <mrtops03@gmail.com>
  • Loading branch information
ecdye committed Dec 18, 2024
1 parent 7be095e commit bd54bfc
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions zram-config
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -375,7 +375,7 @@ case "$1" in
TARGET_DIR="$5"
BIND_DIR="$6"
OLDLOG_DIR="$7"
serviceConfiguration "stop"
[[ -z $SHUTDOWN ]] && serviceConfiguration "stop"
createZdir
;;
esac
Expand Down Expand Up @@ -420,7 +420,7 @@ case "$1" in
ZRAM_DEV="$2"
TARGET_DIR="$3"
BIND_DIR="$4"
[[ -z $SHUTDOWN ]] && serviceConfiguration "stop"
serviceConfiguration "stop"
removeZdir
;;
esac
Expand Down

0 comments on commit bd54bfc

Please sign in to comment.