简体   繁体   English

屏幕不是从 rc.local 开始的

[英]Screen not starting from rc.local

I have a problem where I am unable to start a screen session at boot using the rc.local file.我有一个问题,我无法使用 rc.local 文件在启动时启动屏幕会话。 The specific screen I am starting is for a spigot minecraft server.我正在启动的特定屏幕是用于 spigot minecraft 服务器的。

This is my rc.local file:这是我的 rc.local 文件:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

/home/pi/Documents/bootlog.sh
/home/spigot1_12/startspigot.sh
exit 0

This is the startspigot.sh script (with chmod u+x):这是 startspigot.sh 脚本(使用 chmod u+x):

#!/bin/bash

cd /home/spigot1_12

boot=$(date)

echo "Starting spigot server in screen \"minecraft\" @  $boot " >> /home/pi/Documents/minecraftlog


screen -S minecraft java -Xms512M -Xmx1008M -jar /home/spigot1_12/spigot-1.12.jar nogui

The minecraftlog file does update at each boot, so the script is run. minecraftlog 文件会在每次启动时更新,因此脚本会运行。

When I run the command "sudo sh startspigot.sh", everything works perfectly.当我运行命令“sudo sh startspigot.sh”时,一切正常。 The screen is started and the minecraftlog file is updated.屏幕启动并更新 minecraftlog 文件。 I can find the screen again with "sudo screen -ls"我可以用“sudo screen -ls”再次找到屏幕

At boot, however, both "sudo screen -ls" and "screen -ls" return no sockets.然而,在启动时,“sudo screen -ls”和“screen -ls”都不返回套接字。

What can be causing this?什么可能导致这种情况? The only two users are "pi" and root.只有两个用户是“pi”和root。

Thanks in advance!提前致谢!

Starting a script in a new detached screen as current user (rc.local = root):以当前用户身份在新的分离屏幕中启动脚本(rc.local = root):

screen -dmS <session name> <command> , example: screen -dmS <session name> <command> ,示例:

screen -dmS screenName bash /home/user/run.sh


Starting a script from rc.local as user :user身份从 rc.local 启动脚本:

runuser -l user -c 'screen -dmS screenName bash /home/user/run.sh'

Running screen in detached mode (when you do not have active terminal, like in rc.local or crontab):在分离模式下运行屏幕(当您没有活动终端时,如在 rc.local 或 crontab 中):

screen -dm -S <session name> <command>

-d -m Start screen in "detached" mode -d -m 以“分离”模式启动屏幕

-S When creating a new session, this option can be used to specify a meaningful name for the session. -S 创建新会话时,此选项可用于为会话指定一个有意义的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM