Screen 需要使用 systemd 服务的模式 777

Screen 需要使用 systemd 服务的模式 777

我正在尝试设置 Minecraft 在启动时在屏幕会话中运行。但使用以下服务文件,下面是我的服务状态。

我是使用 Systemd 启动服务的新手,因此如果能得到任何帮助我都会很感激。

minecraft.service - Minecraft Server
Loaded: loaded (/home/matt/minecraft.service; enabled; vendor preset: enabled)
Active: active (exited) since Fri 2016-12-16 14:17:59 GMT; 6min ago
Process: 15942 ExecStopPost=/usr/bin/screen -X -S Minecraft exit (code=exited, status=1/FAILURE)
Process: 15940 ExecStop=/var/minecraft/mcrcon -H localhost -P 8101 -p drwho stop (code=exited, status=255)
Process: 15990 ExecStart=/usr/bin/screen -X -S Minecraft /usr/bin/java -Xmx1024M -Xms1024M -jar spigot.jar (code=exited, status=1/FAILURE)
Process: 15985 ExecStartPre=/usr/bin/screen -dmS Minecraft (code=exited, status=1/FAILURE)
Main PID: 15990 (code=exited, status=1/FAILURE)

Dec 16 14:17:59 TheCyberman systemd[1]: Starting Minecraft Server...
Dec 16 14:17:59 TheCyberman screen[15985]: Directory '/var/run/screen' must have mode 777.
Dec 16 14:17:59 TheCyberman systemd[1]: Started Minecraft Server.
Dec 16 14:17:59 TheCyberman screen[15990]: Directory '/var/run/screen' must have mode 777.

这是我的服务文件

[Unit]
Description=Minecraft Server
Documentation=

Wants=network.target
After=network.target

[Service]
User=minecraft
Group=minecraft
Nice=5
EnvironmentFile=-/var/minecraft/unit.conf
KillMode=none
SuccessExitStatus=0 1
RemainAfterExit=yes

ProtectHome=true
ProtectSystem=full
PrivateDevices=true
NoNewPrivileges=true
PrivateTmp=true
InaccessibleDirectories=/root /sys /srv -/opt /media -/lost+found
ReadWriteDirectories=/var/minecraft/server /usr/bin/screen
WorkingDirectory=/var/minecraft/server
ExecStartPre= /usr/bin/screen -dmS Minecraft 
ExecStart= /usr/bin/screen -X -S Minecraft '/usr/bin/java -Xmx1024M -Xms1024M -jar spigot.jar'
ExecStop=/var/minecraft/mcrcon -H localhost -P 8101 -p drwho stop
ExecStopPost= /usr/bin/screen -X -S Minecraft 'exit'
ExecReload=/var/minecraft/mcrcon -H localhost -P 8101 -p drwho reload
Restart=on-failure

[Install]
WantedBy=multi-user.target

答案1

该目录需要完全的读取、写入和执行权限。

你可以执行这个命令chmod -R 777 /var/run/screen

这将递归地将所有文件夹/文件的权限更改为 777,但通常不太安全。

您还可以运行sudo chown -R $USER:$USER /var/run/screen

这将允许典型用户/或组完全访问,并且更加安全。

答案2

更改NoNewPrivileges=trueNoNewPrivileges=false。这将允许 screen 以 setgid 模式运行,就像它通常做的那样,所以它不会要求 777 权限。

相关内容