这里会显示出您选择的修订版和当前版本之间的差别。
linux添加开机自启动服务 [2021/11/24 11:30] admin 创建 |
linux添加开机自启动服务 [2021/11/24 11:32] (当前版本) admin |
||
---|---|---|---|
行 1: | 行 1: | ||
====== Linux添加开机自启动服务 ====== | ====== Linux添加开机自启动服务 ====== | ||
- | 1.创建服务文件yourService.service | + | 1.创建服务文件yourService.service,ExecStart为自己的程序绝对路径 |
[Unit] | [Unit] | ||
Description=Hello Service | Description=Hello Service | ||
- | |||
[Service] | [Service] | ||
Type=simple | Type=simple | ||
ExecStart=/usr/bin/hello.sh | ExecStart=/usr/bin/hello.sh | ||
SuccessExitStatus=2 | SuccessExitStatus=2 | ||
- | |||
[Install] | [Install] | ||
WantedBy=multi-user.target | WantedBy=multi-user.target | ||
行 14: | 行 12: | ||
2.复制yourService.service到/lib/systemd/system/目录 | 2.复制yourService.service到/lib/systemd/system/目录 | ||
- | 3.<code>systemctl daemon-reload</code>重载服务项目 | + | 3.重载服务项目<code>systemctl daemon-reload</code> |
- | 4.<code>systemctl enable yourService.service</code> | + | 4.开机自启动设置<code>systemctl enable yourService.service</code> |
- | 5.<code>service yourService start</code>启动服务 | + | 5.启动服务<code>service yourService start</code> |