nabucco-server/daemon
2023-12-02 01:24:13 +00:00

45 lines
748 B
Bash

#!/bin/bash
function spawn () {
nohup php server.php > daemon.out 2>&1 &
PID=$!
echo $PID > daemon.pid
}
if [ -z $1 ]
then
if [ ! -e daemon.pid ]
then
nohup bash $0 start > /dev/null 2>&1 &
echo "Sock Chat Daemon started."
else
echo "ERROR: Sock Chat Daemon is already running!"
echo "To stop the daemon, use daemon stop"
fi
elif [ $1 = "start" ]
then
if [ ! -e daemon.pid ]
then
spawn
while [ -e daemon.pid ]
do
if ! ps -p $PID > /dev/null
then
echo "Server died unexpectedly! Restarting..."
spawn
fi
sleep 5
done
/bin/kill -s SIGKILL $PID
fi
elif [ $1 = "stop" ]
then
rm daemon.pid
echo "Sock Chat Daemon stopped."
else
echo "SOCK CHAT SERVER DAEMON"
echo
echo "USAGE: daemon [stop]"
fi