Ubuntu 18.04服务注册方法

本文介绍了Ubuntu 18.04中systemd的使用,替代了传统的service和chkconfig命令。重点讲解了开机启动服务的注册方法,包括[Unit]、[Service]和[Install]段的配置,并提供了修改rc.local服务以实现开机启动的详细步骤。通过设置[Install]段的WantedBy=multi-user.target,确保服务在多用户模式下启动。同时,强调了启动脚本中必须使用绝对路径。文章最后还提到了systemctl的相关命令。
摘要由CSDN通过智能技术生成

背景

systemd is now used for user sessions. System sessions had already been provided by systemd in previous Ubuntu releases.

Ubuntu-18.04用 systemctl 命令来替换了 service 和 chkconfig 的功能。
比如以前启动mysql服务,命令为:

service mysql start

在Ubuntu-18.04启动mysql服务的命令则是:

systemctl start mysqld.service

systemd 默认读取 /etc/systemd/system 下的配置文件,该目录下的文件会链接/lib/systemd/system/下的文件。执行 ls /lib/systemd/system 你可以看到有很多启动脚本,其中就有我们需要的 rc.local.service。
打开rc.local.service脚本中的内容如下所示:

[Unit]
Description=/etc/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.local start
ExecStop=/etc/rc.local stop
ExecReload=/etc/rc.local restart
TimeoutSec=0
RemainAfter

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值