失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > ubuntu18.04中如何设置开机启动脚本 开机启动命令

ubuntu18.04中如何设置开机启动脚本 开机启动命令

时间:2023-09-22 14:04:12

相关推荐

ubuntu18.04中如何设置开机启动脚本 开机启动命令

转载:/airdot/p/9688530.html

转载:/qingshangucheng/p/10183583.html

大体上找资料看了一下,简单的说就是开机启动脚本被阉割了,导致不能用 ,现在systemd 默认读取 /etc/systemd/system 下的配置文件!

所以我们需要手动的创建可执行的启动脚本:

vi/etc/systemd/system/rc-local.service

插入如下内容:

[Unit]Description=/etc/rc.local CompatibilityConditionPathExists=/etc/rc.local[Service]Type=forkingExecStart=/etc/rc.local startTimeoutSec=0RemainAfterExit=yes[Install]WantedBy=multi-user.targetAlias=rc-local.service

因为上面的路径指向的是/etc/rc.local,所以我们还需要创建这个文件

vi /etc/rc.local

插入如下内容:

#!/bin/sh -e## rc.local## This script is executed at the end of each multiuser runlevel.# Make sure that the script will "exit 0" on success or any other# value on error.## In order to enable or disable this script just change the execution# bits.## By default this script does nothing.#这里就会防止脚本,执行启动命令的位置#例如:# echo "hello world" >> /root/123.log# /bin/sh /root/123.shexit 0

然后给文件赋权

sudochmod+x/etc/rc.local

然后加入系统程序中

sudosystemctlenablerc-local#这条语句就是创建一个超链接,在系统启动服务程序中

到这里添加开机启动已完成了,如果想不重启,直接查看效果执行如下命令即可;

启动服务并检查状态

sudosystemctl start rc-local.service

sudosystemctl status rc-local.service

如果觉得《ubuntu18.04中如何设置开机启动脚本 开机启动命令》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。