I have a simple java server + a couple of scripts that I want to run and keep alive using systemd (Ubuntu 16.04) I'm new to systemd The service keeps restarting with this log
Nov 16 10:20:12 systemd[1]: app.service: Unit entered failed state.
Nov 16 10:20:12 systemd[1]: app.service: Failed with result 'resources'.
Nov 16 10:29:25 systemd[1]: app.service: State 'stop-sigterm' timed out. Killing.
Nov 16 10:29:25 systemd[1]: app.service: Unit entered failed state.
Nov 16 10:29:25 systemd[1]: app.service: Failed with result 'timeout'.
Nov 16 10:31:06 systemd[1]: app.service: Service hold-off time over, scheduling restart.
I have 2 simple bash script to run/control the server;
Here is my service defination app.service
[Unit]
Description=java server
[Service]
ExecStart=-/home/deploy/server/serverctl.sh start
ExecStop=-/home/deploy/server/serverctl.sh stop
ExecReload=-/home/deploy/server/serverctl.sh restart
SyslogIdentifier=my-app
User=deploy
Restart=always
RestartSec=100
Type=simple
[Install]
WantedBy=multi-user.target
My start.sh
#!/bin/bash
cd "$(dirname "$0")"
java -mx500m -cp lib/* mylcass -port 8080 -arg val > server.log 2>&1 & echo $!
it runs the server and returns the PID
I have a control script to start/stop/status restart the server, which works fine
#!/bin/bash
PID_FILE='/tmp/myserver.pid'
# ***********************************************
start() {
PID=`/path/to/server-start.sh`
}
case "$1" in
start)
if [ -f $PID_FILE ]; then
PID=`cat $PID_FILE`
if [ -z "`ps axf | grep -w ${PID} | grep -v grep`" ]; then
start
else
exit 0
fi
else
start
fi
if [ -z $PID ]; then
exit 3
else
echo $PID > $PID_FILE
exit 0
fi
;;
status)
echo "status"
if [ -f $PID_FILE ]; then
PID=`cat $PID_FILE`
if [ -z "`ps axf | grep -w ${PID} | grep -v grep`" ]; then
echo "Not running (process dead but pidfile exists)"
exit 1
else
echo "Running [$PID]"
exit 0
fi
else
echo "Not running"
exit 3
fi
;;
stop)
if [ -f $PID_FILE ]; then
PID=`cat $PID_FILE`
if [ -z "`ps axf | grep -w ${PID} | grep -v grep`" ]; then
exit 1
else
PID=`cat $PID_FILE`
kill -HUP $PID
rm -f $PID_FILE
exit 0
fi
else
exit 3
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {status|start|stop|restart}"
exit 1
esac
Any ideas? How can i get systemd to ensure the server is up and running ?