背景
之前手动编写了一个X11VNC的服务,方便远程连接我的linux桌面环境,但发现每次注销后这个vnc服务就停掉了,没有自己起来,只有重启开机才能正常启动,于是就想着需要改造一下。
原版服务内容
[Unit]
Description=Remote desktop service (VNC)
Requires=display-manager.service
After=display-manager.service
[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -forever -rfbauth /etc/x11vnc.pass -rfbport 5900 -shared
ExecStop=/usr/bin/killall x11vnc
[Install]
WantedBy=multi-user.target
但上面这个服务是没法在注销后重启服务的。
改造版本
[Unit]
Description=Remote desktop service (VNC)
Requires=display-manager.service
After=display-manager.service
[Service]
Type=forking
ExecStart=/usr/bin/x11vnc -auth guess -forever -rfbauth /etc/x11vnc.pass -rfbport 5900 -shared
ExecStop=/usr/bin/killall x11vnc
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
这里主要做了两个更改:
-
将服务类型(Type)从 "simple" 改为 "forking"。这样,服务将作为一个守护进程运行,并且 systemd 将等待该进程创建子进程后认为服务已经启动完成。
-
添加了两行新设置:
Restart=always
:这将指示 systemd 在服务意外退出时自动重新启动它。
RestartSec=3
:这将设置在重新启动服务之前等待的时间间隔(以秒为单位)。在这个例子中,设置为 3 秒。
保存更改后,重新加载 systemd 配置并重新启动服务:
通过日志验证注销后的重启
journalctl -fu x11vnc.service
上述命令可以查看服务的实时日志信息。
- -f 是实时查看日志的参数
- -u 后面接服务名称,就是查看该服务的日志信息
通过下面的日志可以看到注销后服务能正常自启了
deepin@deepin-PC:~$ sudo journalctl -fu x11vnc.service
Verify your face or password:
验证成功
Apr 24 11:43:15 deepin-PC x11vnc[11194]: 24/04/2024 11:43:15
Apr 24 11:43:15 deepin-PC x11vnc[11194]: The VNC desktop is: deepin-PC:0
Apr 24 11:43:15 deepin-PC x11vnc[11194]: PORT=5900
Apr 24 11:43:15 deepin-PC x11vnc[11194]: ******************************************************************************
Apr 24 11:43:15 deepin-PC x11vnc[11194]: Have you tried the x11vnc '-ncache' VNC client-side pixel caching feature yet?
Apr 24 11:43:15 deepin-PC x11vnc[11194]: The scheme stores pixel data offscreen on the VNC viewer side for faster
Apr 24 11:43:15 deepin-PC x11vnc[11194]: retrieval. It should work with any VNC viewer. Try it by running:
Apr 24 11:43:15 deepin-PC x11vnc[11194]: x11vnc -ncache 10 ...
Apr 24 11:43:15 deepin-PC x11vnc[11194]: One can also add -ncache_cr for smooth 'copyrect' window motion.
Apr 24 11:43:15 deepin-PC x11vnc[11194]: More info: http://www.karlrunge.com/x11vnc/faq.html#faq-client-caching
Apr 24 11:44:37 deepin-PC x11vnc[11194]: caught XIO error:
Apr 24 11:44:37 deepin-PC x11vnc[11194]: 24/04/2024 11:44:37 deleted 79 tile_row polling images.
Apr 24 11:44:37 deepin-PC systemd[1]: x11vnc.service: Control process exited, code=exited, status=3/NOTIMPLEMENTED
Apr 24 11:44:37 deepin-PC systemd[1]: x11vnc.service: Failed with result 'exit-code'.
Apr 24 11:44:37 deepin-PC systemd[1]: Failed to start x11vnc.service - Remote desktop service (VNC).
Apr 24 11:44:40 deepin-PC systemd[1]: x11vnc.service: Scheduled restart job, restart counter is at 19.
Apr 24 11:44:40 deepin-PC systemd[1]: Starting x11vnc.service - Remote desktop service (VNC)...
Apr 24 11:44:40 deepin-PC x11vnc[11895]: 24/04/2024 11:44:40 passing arg to libvncserver: -rfbauth
Apr 24 11:44:40 deepin-PC x11vnc[11895]: 24/04/2024 11:44:40 passing arg to libvncserver: /etc/x11vnc.pass
Apr 24 11:44:40 deepin-PC x11vnc[11895]: 24/04/2024 11:44:40 passing arg to libvncserver: -rfbport
Apr 24 11:44:40 deepin-PC x11vnc[11895]: 24/04/2024 11:44:40 passing arg to libvncserver: 5900
Apr 24 11:44:40 deepin-PC x11vnc[11895]: 24/04/2024 11:44:40 x11vnc version: 0.9.16 lastmod: 2019-01-05 pid: 11895
Apr 24 11:44:40 deepin-PC x11vnc[11939]: xauth: unable to generate an authority file name
Apr 24 11:44:40 deepin-PC x11vnc[11895]: 24/04/2024 11:44:40 -auth guess: using 'XAUTHORITY=/var/run/lightdm/root/:0' for disp='unset'
Apr 24 11:44:40 deepin-PC x11vnc[11895]: 24/04/2024 11:44:40 XOpenDisplay("") failed.
Apr 24 11:44:40 deepin-PC x11vnc[11895]: 24/04/2024 11:44:40 Trying again with XAUTHLOCALHOSTNAME=localhost ...
Apr 24 11:44:40 deepin-PC x11vnc[11895]: [21B blob data]
Apr 24 11:44:40 deepin-PC x11vnc[11895]: 24/04/2024 11:44:40 *** XOpenDisplay failed. No -display or DISPLAY.
Apr 24 11:44:40 deepin-PC x11vnc[11895]: 24/04/2024 11:44:40 *** Trying ":0" in 4 seconds. Press Ctrl-C to abort.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:40 *** 1 2 3 4
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 *** XOpenDisplay of ":0" successful.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 Using X display :0
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 rootwin: 0x653 reswin: 0xc00001 dpy: 0xe07eded0
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 ------------------ USEFUL INFORMATION ------------------
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 X DAMAGE available on display, using it for polling hints.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 To disable this behavior use: '-noxdamage'
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 Most compositing window managers like 'compiz' or 'beryl'
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 cause X DAMAGE to fail, and so you may not see any screen
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 updates via VNC. Either disable 'compiz' (recommended) or
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 supply the x11vnc '-noxdamage' command line option.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 Wireframing: -wireframe mode is in effect for window moves.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 If this yields undesired behavior (poor response, painting
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 errors, etc) it may be disabled:
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 - use '-nowf' to disable wireframing completely.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 - use '-nowcr' to disable the Copy Rectangle after the
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 moved window is released in the new position.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 Also see the -help entry for tuning parameters.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 You can press 3 Alt_L's (Left "Alt" key) in a row to
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 repaint the screen, also see the -fixscreen option for
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 periodic repaints.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 XFIXES available on display, resetting cursor mode
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 to: '-cursor most'.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 to disable this behavior use: '-cursor arrow'
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 or '-noxfixes'.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 using XFIXES for cursor drawing.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 GrabServer control via XTEST.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 Scroll Detection: -scrollcopyrect mode is in effect to
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 use RECORD extension to try to detect scrolling windows
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 (induced by either user keystroke or mouse input).
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 If this yields undesired behavior (poor response, painting
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 errors, etc) it may be disabled via: '-noscr'
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 Also see the -help entry for tuning parameters.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 You can press 3 Alt_L's (Left "Alt" key) in a row to
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 repaint the screen, also see the -fixscreen option for
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 periodic repaints.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 XKEYBOARD: number of keysyms per keycode 7 is greater
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 than 4 and 51 keysyms are mapped above 4.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 Automatically switching to -xkb mode.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 If this makes the key mapping worse you can
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 disable it with the "-noxkb" option.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 Also, remember "-remap DEAD" for accenting characters.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 X FBPM extension not supported.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 X display is capable of DPMS.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 --------------------------------------------------------
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 Default visual ID: 0x21
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 Read initial data from X display into framebuffer.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 initialize_screen: fb_depth/fb_bpp/fb_Bpl 24/32/10080
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 X display :0 is 32bpp depth=24 true color
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 Listening for VNC connections on TCP port 5900
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 Listening for VNC connections on TCP6 port 5900
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 listen6: bind: Address already in use
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 Not listening on IPv6 interface.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 Xinerama is present and active (e.g. multi-head).
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 Xinerama: number of sub-screens: 1
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 Xinerama: no blackouts needed (only one sub-screen)
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 fb read rate: 897 MB/sec
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 fast read: reset -wait ms to: 10
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 fast read: reset -defer ms to: 10
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 The X server says there are 10 mouse buttons.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44 screen setup finished.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: 24/04/2024 11:44:44
Apr 24 11:44:44 deepin-PC x11vnc[11895]: The VNC desktop is: deepin-PC:0
Apr 24 11:44:44 deepin-PC x11vnc[11895]: PORT=5900
Apr 24 11:44:44 deepin-PC x11vnc[11895]: ******************************************************************************
Apr 24 11:44:44 deepin-PC x11vnc[11895]: Have you tried the x11vnc '-ncache' VNC client-side pixel caching feature yet?
Apr 24 11:44:44 deepin-PC x11vnc[11895]: The scheme stores pixel data offscreen on the VNC viewer side for faster
Apr 24 11:44:44 deepin-PC x11vnc[11895]: retrieval. It should work with any VNC viewer. Try it by running:
Apr 24 11:44:44 deepin-PC x11vnc[11895]: x11vnc -ncache 10 ...
Apr 24 11:44:44 deepin-PC x11vnc[11895]: One can also add -ncache_cr for smooth 'copyrect' window motion.
Apr 24 11:44:44 deepin-PC x11vnc[11895]: More info: http://www.karlrunge.com/x11vnc/faq.html#faq-client-caching
标签:24,11,服务,44,x11vnc,deepin,PC,自启,Linux
From: https://www.cnblogs.com/babyfengfjx/p/18154742