首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能将x11vnc作为服务运行

不能将x11vnc作为服务运行
EN

Ask Ubuntu用户
提问于 2022-08-24 09:48:26
回答 1查看 910关注 0票数 0

我试图在Ubuntu20.04上配置一个x11vnc服务器。当我使用命令从终端启动它时:

代码语言:javascript
复制
x11vnc -noxdamage -display :0 -rfbport 5900 -rfbauth /home/km/.vnc/passwd -forever -loop

这是没有问题的,服务器启动,我可以从另一台机器连接。

在本例中,我希望在系统启动时启动该服务,因此我创建了一个包含以下内容的文件/lib/systems/system/x1vnc.service

代码语言:javascript
复制
[Unit].
Description=x11vnc service
After=display-manager.service network.target syslog.target

[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -noxdamage -display :0 -rfbport 5900 -rfbauth /home/km/.vnc/passwd -forever -loop
ExecStop=/usr/bin/killall x11vnc
Restart=on-failure

[Install]
WantedBy=multi-user.target

但是,当我通过sudo systemctl start x11vnc.service启动此服务时,我可以看到服务器试图在循环中不间断地启动,并且无法连接到它,示例状态输出:

代码语言:javascript
复制
km@km-Z97-HD3:~$ sudo systemctl status x11vnc.service
● x11vnc.service - x11vnc service
     Loaded: loaded (/lib/systemd/system/x11vnc.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-08-24 11:24:22 CEST; 19min ago
   Main PID: 71782 (x11vnc)
      Tasks: 1 (limit: 38269)
     Memory: 1.2M
     CGroup: /system.slice/x11vnc.service
             └─71782 /usr/bin/x11vnc -noxdamage -display :0 -rfbport 5900 -rfbauth /home/km/.vnc/passwd -forever -loop

sie 24 11:43:27 km-Z97-HD3 x11vnc[72438]:    Sometimes the command "ps wwwwaux | grep auth" can reveal the file location.
sie 24 11:43:27 km-Z97-HD3 x11vnc[72438]:    Starting with x11vnc 0.9.9 you can have it try to guess by using:
sie 24 11:43:27 km-Z97-HD3 x11vnc[72438]: -auth guess
sie 24 11:43:27 km-Z97-HD3 x11vnc[72438]: (see also the x11vnc -findauth option.).
sie 24 11:43:27 km-Z97-HD3 x11vnc[72438]:    Only root will have read permission for the file, and so x11vnc must be run
sie 24 11:43:27 km-Z97-HD3 x11vnc[72438]: as root (or copy it).  The random characters in the filenames will of course
sie 24 11:43:27 km-Z97-HD3 x11vnc[72438]: change and the directory the cookie file resides in is system dependent.
sie 24 11:43:27 km-Z97-HD3 x11vnc[72438]: See also: http://www.karlrunge.com/x11vnc/faq.html
sie 24 11:43:27 km-Z97-HD3 x11vnc[71782]: --- x11vnc loop: sleeping 2000 ms ---.
sie 24 11:43:29 km-Z97-HD3 x11vnc[71782]: --- x11vnc loop: 457 ---

怎么处理这事?

EN

回答 1

Ask Ubuntu用户

发布于 2022-09-02 21:13:00

问题在于Xauthority。您是否尝试过输出中提到的-auth猜测。我猜这也行不通。我运行Kubuntu22.04,并有一个解决方案,为它工作,但很可能不在Gnome上。我从bash脚本开始:

代码语言:javascript
复制
#!/bin/sh

# Restart the x11vnc service
restartx11vnc () {
    /usr/bin/systemctl restart x11vnc
}

# Log a message to the system log
logtosyslog () {
    /usr/bin/logger -t startx11vnc $1
}

# Log startup
logtosyslog "x11vnc starting"

# Start up x11vnc in the background. If it exits (-loop exits) then we'll try to recover by restarting.
# The & at the end lets the first line run in the background. Restarting the service will kill it. Commands are
# chained with  ;  because we want all the commands to be executed if x11vnc exitsno matter what the return status.
# Putting the commands in the next 3 lines between parentheses allows the & at the end run all the commands in a
# subshell as a group which also allows the second part of the script to go ahead and run.
( /usr/bin/x11vnc -auth /var/run/sddm/* -loop -forever -repeat -shared -display :0 -rfbauth /etc/x11vnc.pass -rfbport 5900 -oa /var/log/x11vnc.log ; \
logtosyslog "x11vnc exited, restarting" ; \
restartx11vnc ) &

# A second thread is started because of the & at the end of the last line and this thread will wait for a new file
# to be created in /var/run/sddm. This indicates that a user has logged off and a new Xauthority has been generated
/usr/bin/inotifywait -qq -e create /var/run/sddm

# Wait to make sure the new Xauthority is fully set up
/usr/bin/sleep 2

# Log the change
logtosyslog "The Xauthority file changed, restartting x11vnc"

# Restart the x11vnc service so that the new Xauthority is used
restartx11vnc

我的服务文件是这样的:

代码语言:javascript
复制
[Unit]
Description=Run x11vnc at startup
After=multi-user.target

[Service]
#If you start x11vnc this way, every time a user logs off he won’t be able to log back in until the service is restarted 
#ExecStart=/bin/bash -c "/usr/bin/x11vnc -auth /var/run/sddm/* -forever -loop -repeat -noxdamage -shared -display :0 -rfbauth /etc/x11vnc.pass -rfbport 5900 -o /var/log/x11vnc.log"
ExecStart=/bin/bash /usr/bin/startx11vnc

Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

/var/run/sddm/当您的迎接器开始时,它可能在Xauthority所在的位置,也可能不在。它适用于KDE和SDDM。脚本中的其余代码考虑到了这样一个事实,即当您注销Xauthority文件时,更改和x11vnc必须重新加载才能使用新的令牌。哦,你还需要安装inotify-tools,sudo apt安装inotify-工具来检测文件更改。祝好运!

票数 0
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1425393

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档