Ubuntu 16.04에서 서비스를 시작하기 위한 init.d 스크립트:

Ubuntu 16.04에서 서비스를 시작하기 위한 init.d 스크립트:

Java 애플리케이션을 호출하는 Ubuntu 16.04에서 서비스를 시작, 중지 및 다시 시작하기 위해 이 스크립트를 만들었습니다. 우분투 버전입니다

사용 가능한 LSB 모듈이 없습니다. 게시자 ID: Ubuntu 설명: Ubuntu 16.04.4 LTS 버전: 16.04 코드명: xenial

#!/bin/bash
# menu-core-prices-update daemon
# description: daemon for the Java app. that will update the ccy prices every 5 min.
# processname: menu-core-prices-update

DAEMON_PATH="/opt/menu/core-price-update"
DAEMON="java -jar menu-core-prices-update-0.0.1-SNAPSHOT.jar"
DAEMONOPTS=""
NAME=menu-core-prices-update
DESC="menu Core Prices daemon. Java process."
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

case "$1" in
start)
    printf "%-50s" "Starting $NAME..."
    cd $DAEMON_PATH
    PID=`$DAEMON $DAEMONOPTS > /dev/null 2>&1 & echo $!`
    #echo "Saving PID" $PID " to " $PIDFILE
        if [ -z $PID ]; then
            printf "%s\n" "Fail"
        else
            echo $PID > $PIDFILE
            printf "%s\n" "Ok"
        fi
;;
status)
        printf "%-50s" "Checking $NAME..."
        if [ -f $PIDFILE ]; then
            PID=`cat $PIDFILE`
            if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
                printf "%s\n" "Process dead but pidfile exists"
            else
                echo "Running"
            fi
        else
            printf "%s\n" "Service not running"
        fi
;;
stop)
        printf "%-50s" "Stopping $NAME"
            PID=`cat $PIDFILE`
            cd $DAEMON_PATH
        if [ -f $PIDFILE ]; then
            kill -HUP $PID
            printf "%s\n" "Ok"
            rm -f $PIDFILE
        else
            printf "%s\n" "pidfile not found"
        fi
;;
restart)
    $0 stop
    sleep 1
    $0 start
;;
*)
        echo "Usage: $0 {status|start|stop|restart}"
        exit 1
esac

서비스를 시작하면 콘솔에 메시지가 표시되지 않으며 상태를 확인하면 서비스가 시작되고 중지되는 것 같습니다.

canperis@localhost:/usr/local/bin$ sudo systemctl start menu-core-prices-update.service
canperis@localhost:/usr/local/bin$ sudo systemctl status menu-core-prices-update.service
● menu-core-prices-update.service - core-price-update daemon
   Loaded: loaded (/lib/systemd/system/menu-core-prices-update.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Wed 2018-07-25 12:11:02 UTC; 10s ago
  Process: 4482 ExecStop=/usr/local/bin/menu-core-prices-update.sh stop (code=exited, status=0/SUCCESS)
  Process: 4479 ExecStart=/usr/local/bin/menu-core-prices-update.sh start (code=exited, status=0/SUCCESS)
 Main PID: 4479 (code=exited, status=0/SUCCESS)

Jul 25 12:11:02 localhost systemd[1]: Started core-price-update daemon.
Jul 25 12:11:02 localhost menu-core-prices-update.sh[4479]: Starting menu-core-prices-update...            Ok
Jul 25 12:11:02 localhost menu-core-prices-update.sh[4482]: Stopping menu-core-prices-update...            Ok
canperis@localhost:/usr/local/bin$ 

관련 정보