用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 7 Days

用 Cloudflare worker 抓取 喷嚏网 浮世汇 生成 RSS

白嫖worker 自建短链服务 Url-Shorten-Worker 变身文件保管站 File Storage 保存到 R2对象存储 搭建手册

KV-woker 纯练手项目 保护 _ 开头的 Key VS code 重构 JS 代码 提取代码为函数