为什么即使我以root身份运行文件,Java也无法访问文件?

时间:2019-07-12 07:22:47

标签: java bash permissions

我在尝试设置代理服务器时遇到一些问题,一切正常,但无法编写任何内容。

Ubuntu 18.04 / Java 8

这是运行jar的脚本

#!/bin/sh
SERVICE_NAME=BungeeCord
PATH_TO_JAR=/root/bungee
PID_PATH_NAME=/tmp/Bungeecord-pid
case $1 in
    start)
        echo "Starting $SERVICE_NAME ..."
        if [ ! -f $PID_PATH_NAME ]; then
        cd $PATH_TO_JAR
            nohup java -Xmx512M -Xms512M -XX:ParallelGCThreads=8 -XX:+AggressiveOpts -XX:+UseFastAccessorMethods -XX:+UseParallelGC -jar BungeeCord.jar
            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 ..."
            cd $PATH_TO_JAR
            nohup java -Xmx512M -Xms512M -XX:ParallelGCThreads=8 -XX:+AggressiveOpts -XX:+UseFastAccessorMethods -XX:+UseParallelGC -jar BungeeCord.jar
            echo "$SERVICE_NAME started ..."
        else
            echo "$SERVICE_NAME is not running ..."
        fi
    ;;
esac

当我在终端中手动运行它时,它工作正常,但是当它由脚本运行时,它没有写权限。脚本由root用户/服务执行。我几乎尝试了所有可能解决的方法,但是我真的不知道问题出在哪里。

0 个答案:

没有答案