用service 让Linux系统启动时执行命令

之前搭了个Xfce+VNC的环境,做了个快照保存。每次要用的时候,从快照创建了实例,还要终端登进去跑一句 vncserver -geometry 800x600 建一个vnc。
我想把它自动化,启动系统的时候自动执行。

参考:https://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-part-two.html

在/lib/systemd/system目录,创建一个 open1vnc.service,内容如下:
[Unit]
Description=Open 1 vnc

[Service]
User=root
Group=root
Type=oneshot
ExecStart=/usr/bin/vncserver -geometry 800x600
ExecStop=/usr/bin/vncserver -kill :1
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
用这条命令让它在系统启动时执行。
systemctl enable open1vnc

评论

The Hot3 in Last 30 Days

Mihomo (Clash-meta) 择优录取 url-test 自动选择能用的端口和协议

搭 Docker版 Sub-Store 带 http-meta 实现 集合订阅 测延迟 排序 筛选 生成新订阅 定时任务上传Gist

Mihomo (Clash-meta) 故障转移 fallback 自动选择能用的端口