更新 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"
|
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"
|
cat <<EOF > "$SERVICE_FILE"
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=VNC Server for $username on display $DISPLAY_NUM
|
Description=Remote desktop service (VNC)
|
||||||
After=syslog.target network.target
|
After=syslog.target network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=forking
|
Type=forking
|
||||||
User=$username
|
|
||||||
Group=$username
|
# Clean any existing files in /tmp/.X11-unix environment
|
||||||
WorkingDirectory=/home/$username
|
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"
|
||||||
ExecStartPre=-/usr/bin/vncserver -kill :$DISPLAY_NUM > /dev/null 2>&1
|
PIDFile=/home/$username/.vnc/%H$DISPLAY_NUM.pid
|
||||||
# 启动 VNC 服务 (可根据需要调整分辨率 -geometry)
|
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill :$DISPLAY_NUM > /dev/null 2>&1 || :'
|
||||||
ExecStart=/usr/bin/vncserver :$DISPLAY_NUM -geometry 1280x720 -depth 24
|
|
||||||
ExecStop=/usr/bin/vncserver -kill :$DISPLAY_NUM
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|||||||
Reference in New Issue
Block a user