ubuntu-18.04不能像ubuntu14一样通过编辑rc.local来设置开机启动脚本

可以通过下列简单设置后,可以使rc.local重新发挥作用。

1、建立rc-local.service文件

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

2、将下列内容复制进rc-local.service文件

[Unit]

Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
 
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
 
[Install]
WantedBy=multi-user.target
 
3、创建文件rc.local
sudo vi /etc/rc.local
 
4、将下列内容复制进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 "看到这行字,说明添加自启动脚本成功。" /usr/local/test.log
exit 0
 
5、给rc.local加上权限
sudo chmod +x /etc/rc.local
 
6、启用服务
sudo systemctl enable rc-local
 
7、启动服务并检查状态
sudo systemctl start rc-local.service

sudo systemctl status rc-local.service
 
8、重启并检查test.log文件
cat /usr/local/test.log
 
如果能看到内容,说明设置成功,你就可以通过编辑rc.local文件来设置启动脚本了

ubuntu高版本如何设置开机启动脚本的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. ubuntu设置开机启动脚本

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

  7. Fedora 21 设置开机启动脚本

    sudo touch /etc/rc.d/rc.localsudo vim /etc/rc.d/rc.local 在/etc/rc.d/rc.local文件中写入, 然后使用:wq命令 保存并退出. ...

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

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

  9. ubuntu 18.04 - server版 开机启动脚本

    ubuntu 18.04 不再使用 inited 管理系统,改用 systemd systemd 默认读取 /etc/systemd/system 下的文件,该目录下的文件会链接/lib/system ...

随机推荐

  1. Typescript学习总结之模块

    面向对象的特性 模块 模块可以帮助开发者将代码分割为可重用的单元.开发者可以自己决定将模块中的哪些资源(类.方法.变量) 暴露给外部使用,哪些资源只在模块内使用. 如下图, 创建了a.ts 和b.ts ...

  2. 【转】EF Code First 学习笔记:约定配置

    要更改EF中的默认配置有两个方法,一个是用Data Annotations(在命名空间System.ComponentModel.DataAnnotations;),直接作用于类的属性上面;还有一个就 ...

  3. Linux下Python与C++混合编程

    最近在做一个CUDA的项目,记录下学习心得. 系统 Linux --generic #-Ubuntu x86_64 GNU/Linux C++调用Python Python模块代码: #!/usr/b ...

  4. Spring Cloud Zuul 快速入门

    Spring Cloud Zuul 实现了路由规则与实例的维护问题,通过 Spring Cloud Eureka 进行整合,将自身注册为 Eureka 服务治理下的应用,同时从 Eureka 中获取了 ...

  5. 服务发现:Zookeeper vs etcd vs Consul 参考自http://dockone.io/article/667

    服务发现:Zookeeper vs etcd vs Consul [编者的话]本文对比了Zookeeper.etcd和Consul三种服务发现工具,探讨了最佳的服务发现解决方案,仅供参考. 如果使用预 ...

  6. ByteType字符串中判断是否英文

    ByteType('123你好吗',1)=mbSingleByte//单字节ByteType('123你好吗',4)=mbLeadByte//双字节字符的第一个字符ByteType('123你好吗', ...

  7. 跟着未名学Office - 高效笔记OneNote

    了解OneNote 2016年12月22日    19:57 OneNote Summary 理解OneNote中的笔记本.分区.页的概念 编写人:未名 感谢秦大: http://www.zloffi ...

  8. LeetCode——18. 4Sum

    一.题目链接:https://leetcode.com/problems/4sum/ 二.题目大意: 给定一个数组A和一个目标值target,要求从数组A中找出4个数来使之构成一个4元祖,使得这四个数 ...

  9. Windump教程-参数介绍

    1 应用 Windump是tcpdump的Windows版本,主要的参数如下: -D 列出所有的接口 -i interface 指定用于抓包的接口 -c packetcount 指定抓包的个数 -w ...

  10. bzoj2856: [ceoi2012]Printed Circuit Board

    Description 给出一个N个顶点的简单多边形,对于每个顶点,假如它和原点连成的线段只在这个顶点处和多边形相交,就称为满足要求的顶点.你的任务是输出所有满足要求的顶点编号. Input 第一行一 ...