feat: add support for init.d and OpenRC service management #335, #988

This commit is contained in:
Jacky 2025-05-07 10:52:47 +08:00
parent db29f2e9c5
commit 5fdd85a302
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
4 changed files with 329 additions and 35 deletions

View file

@ -0,0 +1,67 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: nginx-ui
# Required-Start: $network $remote_fs $local_fs
# Required-Stop: $network $remote_fs $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start or stop the Nginx UI
### END INIT INFO
NAME="nginx-ui"
DAEMON="/usr/local/bin/$NAME"
PIDFILE="/var/run/$NAME.pid"
CONFIG="/usr/local/etc/nginx-ui/app.ini"
[ -x "$DAEMON" ] || exit 0
start() {
echo "Starting $NAME..."
start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --exec $DAEMON -- $CONFIG
echo "$NAME started"
}
stop() {
echo "Stopping $NAME..."
start-stop-daemon --stop --pidfile $PIDFILE --retry 10
rm -f $PIDFILE
echo "$NAME stopped"
}
status() {
if [ -f $PIDFILE ]; then
PID=$(cat $PIDFILE)
if kill -0 $PID > /dev/null 2>&1; then
echo "$NAME is running (PID: $PID)"
exit 0
else
echo "$NAME is not running (stale PID file)"
exit 1
fi
else
echo "$NAME is not running"
exit 3
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0

View file

@ -0,0 +1,39 @@
#!/sbin/openrc-run
name="nginx-ui"
description="Nginx UI - Yet another WebUI for Nginx"
supervisor=supervise-daemon
command="/usr/local/bin/nginx-ui"
command_args="-config /usr/local/etc/nginx-ui/app.ini"
pidfile="/run/${RC_SVCNAME}.pid"
command_user="root:root"
extra_commands="status"
depend() {
need net
after logger firewall
use dns
after nginx
}
start_pre() {
checkpath --directory --owner $command_user --mode 0755 /run
checkpath --directory --owner $command_user --mode 0755 /usr/local/etc/nginx-ui
}
status() {
if [ -f "${pidfile}" ]; then
PID=$(cat "${pidfile}")
if kill -0 $PID >/dev/null 2>&1; then
einfo "${name} is running (PID: $PID)"
return 0
else
ewarn "${name} is not running (stale PID file)"
return 1
fi
else
einfo "${name} is not running"
return 3
fi
}

View file

@ -0,0 +1,16 @@
[Unit]
Description=Yet another WebUI for Nginx
Documentation=https://github.com/0xJacky/nginx-ui
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/nginx-ui --config /usr/local/etc/nginx-ui/app.ini
RuntimeDirectory=nginx-ui
WorkingDirectory=/var/run/nginx-ui
Restart=on-failure
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target