2018-12-02 02:41:25 -06:00
|
|
|
#!/bin/bash
|
|
|
|
### BEGIN INIT INFO
|
2022-01-23 04:29:53 -06:00
|
|
|
# Provides: shlink_openswoole
|
2018-12-02 02:41:25 -06:00
|
|
|
# Required-Start: $local_fs $network $named $time $syslog
|
|
|
|
# Required-Stop: $local_fs $network $named $time $syslog
|
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
2022-01-23 04:29:53 -06:00
|
|
|
# Description: Shlink non-blocking server with openswoole
|
2018-12-02 02:41:25 -06:00
|
|
|
### END INIT INFO
|
|
|
|
|
2021-01-14 13:19:38 -06:00
|
|
|
SCRIPT=/path/to/shlink/vendor/bin/laminas\ mezzio:swoole:start
|
2018-12-02 02:41:25 -06:00
|
|
|
RUNAS=root
|
|
|
|
|
2022-01-23 04:29:53 -06:00
|
|
|
PIDFILE=/var/run/shlink_openswoole.pid
|
2018-12-02 02:41:25 -06:00
|
|
|
LOGDIR=/var/log/shlink
|
2022-01-23 04:29:53 -06:00
|
|
|
LOGFILE=${LOGDIR}/shlink_openswoole.log
|
2018-12-02 02:41:25 -06:00
|
|
|
|
|
|
|
start() {
|
|
|
|
if [[ -f "$PIDFILE" ]] && kill -0 $(cat "$PIDFILE"); then
|
2022-01-23 04:29:53 -06:00
|
|
|
echo 'Shlink with openswoole already running' >&2
|
2018-12-02 02:41:25 -06:00
|
|
|
return 1
|
|
|
|
fi
|
2022-01-23 04:29:53 -06:00
|
|
|
echo 'Starting shlink with openswoole' >&2
|
2018-12-02 02:41:25 -06:00
|
|
|
mkdir -p "$LOGDIR"
|
|
|
|
touch "$LOGFILE"
|
|
|
|
local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
|
|
|
|
su -c "$CMD" $RUNAS > "$PIDFILE"
|
|
|
|
echo 'Shlink started' >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
if [[ ! -f "$PIDFILE" ]] || ! kill -0 $(cat "$PIDFILE"); then
|
2022-01-23 04:29:53 -06:00
|
|
|
echo 'Shlink with openswoole not running' >&2
|
2018-12-02 02:41:25 -06:00
|
|
|
return 1
|
|
|
|
fi
|
2022-01-23 04:29:53 -06:00
|
|
|
echo 'Stopping shlink with openswoole' >&2
|
2018-12-02 02:41:25 -06:00
|
|
|
kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
|
|
|
|
echo 'Shlink stopped' >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
stop
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Usage: $0 {start|stop|restart}"
|
|
|
|
esac
|