#!/usr/bin/env nix-shell #!nix-shell -i bash -p s6 -p s6-rc -p systemd action="$1" type="$2" service="$3" checkActive() { case "$type" in systemd) systemctl is-active "$service.service" > /dev/null && echo true || echo false ;; s6) s6-svstat -o wantedup "$XDG_RUNTIME_DIR/s6/live/servicedirs/$service" ;; esac } startService() { case "$type" in systemd) /run/wrappers/bin/sudo systemctl start "$service" ;; s6) s6-rc start "$service" ;; esac } stopService() { case "$type" in systemd) /run/wrappers/bin/sudo systemctl stop "$service" ;; s6) s6-rc stop "$service" ;; esac } case "$action" in print) checkActive ;; toggle) case "$(checkActive)" in false) stopService ;; true) startService ;; esac ;; esac