Comment créer un script d'init pour une application java.
EDIT : ce truc n'a pas marché pour moi :
s=ps -C 'java -jar /path/to/application.jar' -o pid h
Du coup, j'ai remplacé par :
s=$(pgrep --full 'une string unique qui identifie la command line pour lancer mon jar')
#
#
#
check_status() {
s=ps -C 'java -jar /path/to/application.jar' -o pid h
if [ $s ] ; then
return $s
fi
return 0
}
start() {
check_status
pid=$?
if [ $pid -ne 0 ] ; then
echo "The application is already started"
exit 1
fi
echo -n "Starting application: "
java -jar /path/to/application.jar >> /path/to/logfile 2>&1 &
echo "OK"
}
stop() {
check_status
pid=$?
if [ $pid -eq 0 ] ; then
echo "Application is already stopped"
exit 1
fi
echo -n "Stopping application: "
kill -9 $pid &
echo "OK"
}
status() {
check_status
if [ $? -ne 0 ] ; then
echo "Application is started"
else
echo "Application is stopped"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart|reload)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0