主页 > imtoken市场打不开 > ubuntu-18.04 设置启动脚本

ubuntu-18.04 设置启动脚本

imtoken市场打不开 2023-02-02 07:30:02

从ubuntu-16.10开始,不再使用initd管理系统,改用systemd

systemd 现在用于用户会话。 在以前的 Ubuntu 版本中,systemd 已经提供了系统会话。

快速浏览了一下systemd的使用方法,发现变化有点大,包括用systemctl命令替换了service和chkconfig的功能。

比如之前启动mysql服务:

sudo service mysql start

现在使用:

sudo systemctl start mysqld.service

开机启动设置_开机启动时出现\"bootini非法操作\"错误提示_etc怎么开机启动

其实这个变化并不算太大etc怎么开机启动,主要是启动比以前复杂了很多。 systemd默认读取/etc/systemd/system下的配置文件,该目录下的文件会链接/lib/systemd/system/下的文件。

执行ls /lib/systemd/system 可以看到有很多启动脚本etc怎么开机启动,包括我们需要的rc.local.service

打开脚本内容:

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or

etc怎么开机启动_开机启动设置_开机启动时出现\"bootini非法操作\"错误提示

# (at your option) any later version. # This unit gets pulled automatically into multi-user.target by # systemd-rc-local-generator if /etc/rc.local is executable. [Unit] Description=/etc/rc.local Compatibility ConditionFileIsExecutable=/etc/rc.local After=network.target

开机启动时出现\"bootini非法操作\"错误提示_开机启动设置_etc怎么开机启动

[Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 RemainAfterExit=yes

一般正常的启动文件主要分为三部分。

etc怎么开机启动_开机启动设置_开机启动时出现\"bootini非法操作\"错误提示

[Unit] 部分:启动顺序和依赖项

[Service]部分:启动行为、如何启动、启动类型

[install]段:定义如何安装这个配置文件,即开机如何启动

可以看出/etc/rc.local的启动顺序是在network后面的,但是明显缺少了Install部分,也没有定义如何启动,显然这个配置是无效的。 所以我们后面需要帮他添加[Install]部分:

[Install]  
WantedBy=multi-user.target  
Alias=rc-local.service

etc怎么开机启动_开机启动设置_开机启动时出现\"bootini非法操作\"错误提示

这里要注意ubuntu-18.04默认是没有/etc/rc.local文件的,需要自己创建

sudo touch /etc/rc.local 

然后把你需要的启动脚本写入/etc/rc.local,我们不妨在里面写一些测试脚本来验证脚本是否有效。

echo "this just a test" > /usr/local/text.log

在这一步之后,还需要最后一步。 我们说过systemd默认读取/etc/systemd/system下的配置文件,所以我们需要在/etc/systemd/system目录下创建软链接

ln -s /lib/systemd/system/rc.local.service /etc/systemd/system/ 

OK,接下来,重启系统,查看/usr/local/text.log文件是否存在,即可知道启动脚本是否生效。