Created
January 31, 2019 11:00
-
-
Save ruan65/ae0217e964d02da7ea680f41a2f4bcd9 to your computer and use it in GitHub Desktop.
service file maxidemon in /etc/init.d & maxidaemon.sh in /opt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cd /home/dev/maxidroid/ | |
su -c '( | |
until java -Xms512m -Xmx1024m -jar maxidroid_asio*.jar --jar.name=`ls | grep maxidroid_asio` --app.started=`date "+%d.%m.%Y_at_%H:%M:%S"` ; do | |
echo "Application crashed with exit code $?. Respawning... " >&2 | |
sleep 5 | |
done | |
) &' dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### BEGIN INIT INFO | |
# Provides: maxidaemon | |
# Required-Start: | |
# Required-Stop: | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: MaxiDroid Daemon for Android App | |
# Source function library located on the first uncommented string | |
# Works in Debian and Deb-Based (Ubuntu etc) | |
### END INIT INFO | |
. /etc/rc.d/init.d/functions | |
#. /lib/lsb/init-functions | |
case "$1" in | |
start) | |
echo "$(date) service maxidaemon started" >>/var/log/maxidaemon.log | |
/opt/maxidaemon.sh & | |
echo $! + 5 | bc >/var/run/maxidaemon.pid | |
;; | |
stop) | |
echo "$(date) service maxidaemon stopped" >>/var/log/maxidaemon.log | |
kill -15 `cat /var/run/maxidaemon.pid` | |
kill -15 `ps aux | grep 'maxidroid-0.0.1-SNAPSHOT.jar' | awk '{print $2}'` | |
rm /var/run/maxidaemon.pid | |
;; | |
restart) | |
$0 stop | |
$0 start | |
;; | |
status) | |
if [ -e /var/run/maxidaemon.pid ]; then | |
echo maxidaemon is running, pid=`cat /var/run/maxidaemon.pid` | |
else | |
echo maxidaemon is not running | |
exit 1 | |
fi | |
;; | |
*) | |
echo "Usage: $0 {start|stop|status|restart}" | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment