diff options
Diffstat (limited to 'gmid/files/rc.gmid.new')
-rw-r--r-- | gmid/files/rc.gmid.new | 81 |
1 files changed, 59 insertions, 22 deletions
diff --git a/gmid/files/rc.gmid.new b/gmid/files/rc.gmid.new index 33044b7..4b9e006 100644 --- a/gmid/files/rc.gmid.new +++ b/gmid/files/rc.gmid.new @@ -3,54 +3,91 @@ # Startup/shutdown script for the gmid gemini service. # -create_run_dir() { +GMID_USER=${GMID_USER:-root} + +create_gmid_run_dir() { if [ ! -d /run/gmid/ ]; then mkdir -p /run/gmid - chown :gmid /run/gmid - chmod g+wX /run/gmid + chown gmid:gmid /run/gmid fi } -start() { - echo "Starting gmid gemini service" - create_run_dir +gmid_reload() +{ + create_gmid_run_dir + + local pid="$(2>/dev/null cat /run/gmid/gmid.pid)" + + if [ -z "$pid" ] || ! kill -0 "$pid" >/dev/null; then + echo "gmid is not running" + + return + fi + + echo "Reloading gmid configuration" + kill -HUP "$(cat /run/gmid/gmid.pid)" +} + +gmid_start() { + create_gmid_run_dir + + local pid="$(2>/dev/null cat /run/gmid/gmid.pid)" + + if [ -n "$pid" ] || kill -0 "$pid" 2>/dev/null; then + echo "gmid is already running" - sudo -u gmid -- gmid \ - -c /etc/gmid/gmid.conf \ + return + fi + + echo "Starting gmid gemini service" + sudo -u "$GMID_USER" -- gmid \ + -c /etc/gmid.conf \ -P /run/gmid/gmid.pid } -status() { - create_run_dir +gmid_status() { + create_gmid_run_dir - if [ -f /run/gmid/gmid.pid ] && [ kill -0 "$(cat /run/gmid/gmid.pid)" >/dev/null ]; then - echo "gmid is running" - else + local pid="$(2>/dev/null cat /run/gmid/gmid.pid)" + + if [ -z "$pid" ] || ! kill -0 "$pid" 2>/dev/null; then echo "gmid is not running" + + return fi + + echo "gmid is running" } -stop() { +gmid_stop() { echo "Stopping gmid gemini service" - create_run_dir + create_gmid_run_dir - if [ -f /run/gmid/gmid.pid ]; then - sudo -u gmid -- kill -SIGINT "$(cat /run/gmid/gmid.pid)" + local pid="$(2>/dev/null cat /run/gmid/gmid.pid)" + + if [ -z "$pid" ] || ! kill -0 "$pid" 2>/dev/null; then + echo "gmid is not running" + + return fi + + sudo -u "$GMID_USER" -- kill -TERM "$pid" } case "$1" in +reload) + gmid_reload + ;; start) - start + gmid_start ;; status) - status + gmid_status ;; stop) - stop + gmid_stop ;; *) - echo "Usage: $0 {start|stop|status}" + echo "Usage: $0 {reload|start|status|stop}" exit 1 esac - |