0

我正在尝试通过在 Ubuntu 机器中执行 jar 文件来创建服务。我用下面的代码创建了一个包装器

#!/bin/sh
SERVICE_NAME=MyService
PATH_TO_JAR=/home/nani/Documents/My_Build_executable/My_Build-12-06.jar
PID_PATH_NAME=/tmp/MyService-pid
case $1 in
    start)
        echo "Starting $SERVICE_NAME ..."
        if [ ! -f $PID_PATH_NAME ]; then
            nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
                        echo $! > $PID_PATH_NAME
            echo "$SERVICE_NAME started ..."
        else
            echo "$SERVICE_NAME is already running ..."
        fi
    ;;
    stop)
        if [ -f $PID_PATH_NAME ]; then
            PID=$(cat $PID_PATH_NAME);
            echo "$SERVICE_NAME stoping ..."
            kill $PID;
            echo "$SERVICE_NAME stopped ..."
            rm $PID_PATH_NAME
        else
            echo "$SERVICE_NAME is not running ..."
        fi
    ;;
    restart)
        if [ -f $PID_PATH_NAME ]; then
            PID=$(cat $PID_PATH_NAME);
            echo "$SERVICE_NAME stopping ...";
            kill $PID;
            echo "$SERVICE_NAME stopped ...";
            rm $PID_PATH_NAME
            echo "$SERVICE_NAME starting ..."
            nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
                        echo $! > $PID_PATH_NAME
            echo "$SERVICE_NAME started ..."
        else
            echo "$SERVICE_NAME is not running ..."
        fi
    ;;
esac

但我坚持使用PID_PATH_NAME. 这个PID是什么,我需要做什么来配置/创建/修改这个?请帮我。

4

1 回答 1

1

该术语PID代表进程标识符,是每个进程获得的唯一编号。通过将 PID 保存到文件中,系统稍后可以找到服务的 PID,并且能够在服务应该停止时向服务发送停止信号。

于 2015-06-18T10:35:33.747 回答