更新 vnc/create_vnc_autostarrt.sh
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user