小编Hen*_*nok的帖子

在Linux Ubuntu上将jar文件作为Daemon运行

我想在我的Teamspeak3上安装一个bot,并在启动时将该bot作为守护进程运行.我编写了自己的脚本并将其复制到init.d,然后将其添加update-rc.d到默认值.

#!/bin/sh
#
# JTS3ServerBot Script
#
USER="ts"
NAME="jts3"
DIR="/home/ts/jts3/"
case $1 in
    start)
        echo "Starting ${NAME} ..."
        if [ ! -f $DIR/pid ]; then
            sudo -u $USER -c nohup java -jar $DIR/JTS3ServerMod.jar $DIR 2>> /dev/null >> /dev/null &
            echo $! > $DIR/pid
            echo "${NAME} started ..."
        else
            echo "${NAME} is already running ..."
        fi
    ;;
    stop)
        if [ -f $DIR/pid ]; then
            PID=$(cat $DIR/pid);
            echo "Stopping ${NAME} ..."
            kill $PID;
            echo "${NAME} stopped ..."
            rm $DIR/pid
        else …
Run Code Online (Sandbox Code Playgroud)

linux bash shell daemon jar

3
推荐指数
1
解决办法
6871
查看次数

标签 统计

bash ×1

daemon ×1

jar ×1

linux ×1

shell ×1