4259 links
  • Arnaud's links
  • Home
  • RSS Feed
  • Tag cloud
  • Login
search: tag:java tag:init — newest first
  • Writing an init script for a Java application | Gustavo Straube

    [Summary, full note in Shaarli]
    Comment créer un script d'init (/etc/init.d) pour une application Java (java -jar).

    Structure du script (sh) :
    - check_status : trouve le PID de l'appli ; renvoie 0 si elle ne tourne pas.
    - start : si déjà lancée, "already started" et exit 1 ; sinon
    java -jar /path/to/application.jar >> /path/to/logfile 2>&1 &
    - stop : si arrêtée, "already stopped" et exit 1 ; sinon kill -9 $pid
    - status : "Application is started" / "stopped".
    - case "$1" in start|stop|status|restart|reload (= stop puis start), sinon usage : $0 {start|stop|restart|reload|status}.

    EDIT : la recherche de PID de l'article ne marchait pas pour moi :
    s=ps -C 'java -jar /path/to/application.jar' -o pid h
    remplacée par :
    s=$(pgrep --full 'une string unique qui identifie la command line pour lancer mon jar')

    Attention : check_status fait "return $s", donc un PID passe par le code retour (limité à 0-255) ; à corriger si on réutilise le script.

    January 2, 2014 - permalink - http://gustavostraube.wordpress.com/2009/11/05/writing-an-init-script-for-a-java-application/
    init initd jar java script