参考:https://www.cnblogs.com/defifind/p/9285456.html

       http://www.cnblogs.com/airdot/p/9688530.html

  systemd 默认读取 /etc/systemd/system 下的配置文件,该目录下的文件会链接/lib/systemd/system/下的文件

  打开脚本/lib/systemd/system/rc.local.service  添加末尾几行

[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target [Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no [Install]
WantedBy=multi-user.target
elias=rc-local.service

  PS:实际测试无需添加最后三行也能实现

  最后增加字段[Install]否则在enable的时候可能会报一下错误,虽然报一下错误后开机自启程序还是正常的

The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
settings in the [Install] section, and DefaultInstance for template units).
This means they are not meant to be enabled using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
.wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
D-Bus, udev, scripted systemctl call, ...).
4) In case of template units, the unit is meant to be enabled with some
instance name specified.

  创建启动文件/etc/rc.local(默认无该文件)

#!/bin/sh -e
touch /tmp/test

  增加执行权限

chmod +x /etc/rc.local

  PS:需要#!/bin/sh -e否则可能不生效

  设置软连接

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

  重启如果在/tmp目录下面创建了test文件则代表设置开启启动成功

  启动服务并设置开启自启动

systemctl start rc-local
systemctl enable rc-local

  重启服务器测试,可以通过命令查看自启动状态以及自启动执行时候的报错等信息

systemctl status rc-local

  如果启动rc-local报错

journalctl -xe

  

单元已失败

  检查/etc/rc.local文件配置,是否有非英文状态输入的字符

  

Ubuntu-18.04设置开机启动脚本的更多相关文章

  1. Ubuntu 18.04 设置开机启动脚本 rc.local systemd

    ubuntu18.04不再使用initd管理系统,改用systemd. ubuntu-18.04不能像ubuntu14一样通过编辑rc.local来设置开机启动脚本,通过下列简单设置后,可以使rc.l ...

  2. Ubuntu 16.04设置开机启动脚本的方法

    需求:公司卡片机容量太小,只有100G,由于使用的人比较的多,开机使用后有时候就会出现磁盘空间占满数据写不进去的情况,影响工作进度,而且每次使用完都得关掉卡片机,所以就有必要写个清理磁盘的脚本,当卡片 ...

  3. Ubuntu 14.04设置开机启动脚本的方法

    rc.local脚本 rc.local脚本是一个ubuntu开机后会自动执行的脚本,我们可以在该脚本内添加命令行指令.该脚本位于/etc/路径下,需要root权限才能修改. 该脚本具体格式如下: #! ...

  4. ubuntu-18.04 设置开机启动脚本

    ubuntu-18.04 设置开机启动脚本 参阅下列链接 https://askubuntu.com/questions/886620/how-can-i-execute-command-on-sta ...

  5. ubuntu-18.04 设置开机启动脚本-亲测有效

    ubuntu-18.04不能像ubuntu14一样通过编辑rc.local来设置开机启动脚本,通过下列简单设置后,可以使rc.local重新发挥作用. 2.将下列内容复制进rc-local.servi ...

  6. Ubuntu14.04设置开机启动脚本(转)

    原文:https://www.magentonotes.com/ubuntu-config-autostart-shell-script.html 方法一:将脚本添加到文件/etc/rc.local ...

  7. ubuntu-server-18.04 设置开机启动脚本

    ubuntu-16.10 开始不再使用initd管理系统,改用systemd systemd is now used for user sessions. System sessions had al ...

  8. Ubuntu 16.04设置开机启动应用程序

    在终端通过以下命令进行设置,Dash已经搜索不到Startup了: gnome-session-properties 或者直接在Dash中搜索:gnome-session

  9. ubuntu 18.04设置开机自动挂载移动硬盘

    首先在命令行执行df -h指令,可以看到如下结果: zifeiy@zifeiy-PC1:~$ df -h 文件系统 容量 已用 可用 已用% 挂载点 udev 964M 0 964M 0% /dev ...

随机推荐

  1. 【ZH奶酪】为什么Python不需要函数重载?

    函数重载的作用是什么? 函数重载主要是为了解决两个问题 可变参数类型 可变参数个数 另外,一个基本的设计原则是,仅仅当两个函数除了参数类型和参数个数不同以外,其功能是完全相同的,此时才使用函数重载,如 ...

  2. 救基友3(三维BFS)

    救基友记3 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述   话说CZ因为不守基道.被妖怪抓走了.好基友WP在努力讨好高富帅 ...

  3. Cache Line 伪共享发现与优化

    https://yq.aliyun.com/articles/465504 Cache Line 伪共享发现与优化 作者:吴一昊,杨勇 1. 关于本文 本文基于 Joe Mario 的一篇博客 改编而 ...

  4. supervisor //todo

    #安装easy-installyum install python-setuptools #安装 supervisoreasy_install supervisor #创建主配置文件echo_supe ...

  5. Jmeter远程测试

    11.3 详解JMeter远程测试(1) 2012-04-09 09:14 温素剑 电子工业出版社 字号:T | T 综合评级: 想读(7)  在读(2)  已读(0)   品书斋鉴(0)   已有9 ...

  6. [转]BLAS简介

    BLAS(Basic Linear Algebra Subprograms)是一组线性代数计算中通用的基本运算操作函数集合[1] .BLAS Technical (BLAST) Forum负责规范BL ...

  7. WCF中记录SOAP消息日志

    Windows Communication Foundation (WCF) 默认启用消息日志,WCF使用了在System.Diagnostics名称空间中定义的跟踪机制.在这个跟踪机制中,通过在配置 ...

  8. SQL Server 数据库基础笔记分享(下)

    前言 本文是个人学习SQL Server 数据库时的以往笔记的整理,内容主要是对数据库的基本增删改查的SQL语句操作和约束,视图,存储过程,触发器的基本了解. 注:内容比较基础,适合入门者对SQL S ...

  9. Ansible 使用普通用户远程执行playbook

    设置ansible使用普通用户jsxge远程连接执行playbook 1. ansible控制端创建普通用户jsxgecd /homeuseradd jsxgechown -R jsxge.wheel ...

  10. 【spark 深入学习 05】RDD编程之旅基础篇-01

    ---------------- 本节内容 1.RDD的工作流程 2.WordCount解说  · shell版本WordCount  · java版本WordCount -------------- ...