更新 vnc/create_vnc_autostarrt.sh

This commit is contained in:
2026-06-29 11:03:21 +08:00
parent 304e96b2c2
commit c9af5c61aa
+26 -10
View File
@@ -62,22 +62,38 @@ while IFS=':' read -r username password; do
SERVICE_FILE="/etc/systemd/system/vnc-${username}.service"
# 写入专属的 systemd 服务配置
#[Unit]
#Description=VNC Server for $username on display $DISPLAY_NUM
#After=syslog.target network.target
#[Service]
#Type=forking
#User=$username
#Group=$username
#WorkingDirectory=/home/$username
# 启动前清理可能残留的锁文件
#ExecStartPre=-/usr/bin/vncserver -kill :$DISPLAY_NUM > /dev/null 2>&1
# 启动 VNC 服务 (可根据需要调整分辨率 -geometry)
#ExecStart=/usr/bin/vncserver :$DISPLAY_NUM -geometry 1280x720 -depth 24
#ExecStop=/usr/bin/vncserver -kill :$DISPLAY_NUM
#[Install]
#WantedBy=multi-user.target
# 写入专属的 systemd 服务配置
cat <<EOF > "$SERVICE_FILE"
[Unit]
Description=VNC Server for $username on display $DISPLAY_NUM
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
User=$username
Group=$username
WorkingDirectory=/home/$username
# 启动前清理可能残留的锁文件
ExecStartPre=-/usr/bin/vncserver -kill :$DISPLAY_NUM > /dev/null 2>&1
# 启动 VNC 服务 (可根据需要调整分辨率 -geometry)
ExecStart=/usr/bin/vncserver :$DISPLAY_NUM -geometry 1280x720 -depth 24
ExecStop=/usr/bin/vncserver -kill :$DISPLAY_NUM
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :$DISPLAY_NUM > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l $username -c "/usr/bin/vncserver :$DISPLAY_NUM"
PIDFile=/home/$username/.vnc/%H$DISPLAY_NUM.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill :$DISPLAY_NUM > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target