参考: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. 熬之滴水成石:最想深入了解的内容--windows内核机制(6)

    58 进程和线程(3) 说完进程再说说线程,线程相比于进程其实有更多可说的内容.首先实现线程调用的数据结构是个栈,该栈记录了调用方法的信息这里面也包括了函数调用及返回的地址.线程肯定是属于某个进程,其 ...

  2. Cena评测系统在win10中测评cpp程序

    1.装了cena-0.8.1-20110710-setup.exe 2.打补丁:cena-0.8.2-patch.zip 3.菜单->工具->选项->编程语言   修改G++ (mi ...

  3. 【Zookeeper】源码分析之服务器(二)之ZooKeeperServer

    一.前言 前面阐述了服务器的总体框架,下面来分析服务器的所有父类ZooKeeperServer. 二.ZooKeeperServer源码分析 2.1 类的继承关系 public class ZooKe ...

  4. Grails 第二课

    package helloworld import groovy.swing.SwingBuilder import java.awt.BorderLayout import groovy.swing ...

  5. 转 qInstallMsgHandler实现日志输出

    #include <QtDebug> #include <QFile> #include <QTextStream> #define _TIME_ qPrintab ...

  6. java 字符串中参数化符号${}的解析

    我们在很多地方都能看到代表参数意义的符号${},可能我们在写一些框架的时候,有时候也需要用到这个符号,但他们是如何精确解析的?或者说需要我们自已写的时候,如何写?我们先来看以下的几个场景: 1.字符串 ...

  7. Windows 8系统默认开启的.Net Framework版本是4.0,而部分用户可能需要使用到3.5或以下版本,简单添加方法

    从网络途径下载的.Net Framework3.5是无法直接在Windows 8系统上安装的,我们可以通过Windows 8的添加功能来实现 1.打开控制面板,点击”启用或关闭Windows 功能“ ...

  8. [svc]数字证书基础知识

    数字证书基础原理 数字证书采用PKI(Public Key Infrastructure)公开密钥基础架构技术,利用一对互相匹配的密钥进行加密和解密. 每个用户自己设定一把特定的仅为本人所知的私有密钥 ...

  9. Maven使用详解,非常详细

    本文转:http://blog.csdn.net/u010425776/article/details/52027706 什么是Maven? 如今我们构建一个项目需要用到很多第三方的类库,如写一个使用 ...

  10. 为11.2.0.2 Grid Infrastructure添加节点

    转自:http://www.askmaclean.com/archives/add-node-to-11-2-0-2-grid-infrastructure.html 在之前的文章中我介绍了为10g ...