linux系统学习-systemd开机自启动服务

初版开机自启动,后续需要修改服务启动依赖。
3.1 通用步骤

(1)创建开机需要启动的脚本

(2)为脚本增加可执行权限

(3)进入systemd放置service的目录,在该目录下可看到大量服务配置文件,命令如下。

进入 systemd 的 service 目录

cd /etc/systemd/system

查看文件列表

ls -al

(4)在该目录创建一个新的.service文件用于配置开机启动脚本,如MogoWeb.service,文件中的配置内容如下。

[Unit]
Description=Startup xxxx
[Service]
ExecStart=xxx.sh
[Install]
WantedBy=multi-user.target

(5)运行xxx.service文件。

#启动服务
sudo systemctl start xxxx.service

查看运行日志

systemctl status xxxx.service

(6)校验脚本是否执行成功。

(7)添加到开机自启动

systemctl enable 将服务设置为每次开机启动;
systemctl start 服务立即启动 下次不启动;
systemctl enable --now 立即启动且每次重启也启动

你可能感兴趣的:(#,linux学习,linux,学习,服务器)