bash 找不到套接字:启动时调用的屏幕脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21029426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 09:12:35  来源:igfitidea点击:

No Sockets found: screen script called on startup

linuxbashshellsocketsstartup

提问by Joel

I have added a script called screen_tronserver.sh to the /etc/init.d/ directory. I have set the permissions so it is executable and called

我在 /etc/init.d/ 目录中添加了一个名为 screen_tronserver.sh 的脚本。我已经设置了权限,所以它是可执行的并被调用

update-rc.d /etc/init.d/screen_tronserver.sh defaults 100

to add the script to startup. Inside the file is the following:

将脚本添加到启动。文件内部如下:

#!/bin/bash
echo "creating screen and starting tron server..."
screen -S tronserver -m /home/pi/programming/tronserver/a.out

The a.out file is a compiled program which runs a server I have created. Now when I call

a.out 文件是运行我创建的服务器的编译程序。现在当我打电话

screen -ls

It says no sockets found. However, I have tried connecting to the server and it is successful, indicating the screen/socket is there somewhere, running in the background.

它说没有找到套接字。但是,我尝试连接到服务器并且成功,表明屏幕/套接字在某处,在后台运行。

So why can I not see this mystical socket!?

那为什么我看不到这个神秘的插座!?

回答by Christian Fritz

As Andrew is already alluding to, init scripts are run as root, and screens belong to different users. When you type screen -lsyou will see the screens of the current user, not all screens on the system.

正如 Andrew 已经暗示的那样,init 脚本以 root 身份运行,屏幕属于不同的用户。当您键入时,screen -ls您将看到当前用户的屏幕,而不是系统上的所有屏幕。

So yes, sudo screen -lsor sudo screen -rwill do the trick.

所以是的,sudo screen -ls或者sudo screen -r会成功。

Edit(for completeness and future reference): as pointed out by the OP, it is necessary to also add the -dflag to the screen command to detach right away in the init script, or else the screen will remain attached.

编辑(为了完整性和将来参考):正如 OP 所指出的,还需要将-d标志添加到屏幕命令中以立即在初始化脚本中分离,否则屏幕将保持连接状态。