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. 关键字:this、ref、out

    Class1.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; usin ...

  2. NLP自然语言处理中的hanlp分词实例

    本篇分享的依然是关于hanlp的分词使用,文章内容分享自 gladosAI 的博客,本篇文章中提出了一个问题,hanlp分词影响了实验判断结果.为何会如此,不妨一起学习一下 gladosAI 的这篇文 ...

  3. ML: 聚类算法R包-层次聚类

    层次聚类 stats::hclust stats::dist    R使用dist()函数来计算距离,Usage: dist(x, method = "euclidean", di ...

  4. mysql 性能

    https://blog.csdn.net/zengxuewen2045/article/category/6388631 #sda 磁盘信息dstat -D sda 3 5 #找出系统瓶颈dstat ...

  5. Windows核心编程 中部分代码 Delphi 实现

    // ① Delphi 使用 Interlocked 系列函数 var MyValue:Longint = ; // = Integer begin InterlockedIncrement(MyVa ...

  6. XE5开发Android程序调用电话相关功能(短信息和电话) [转]

    其实都可以通过intent和URI调用系统功能.Windows程序员可以理解成是ShellExecute.这个是万金油.可以有调用各种功能.后面会介绍. 1.短信息.很简单 方法a.不使用Intent ...

  7. 17行代码解决微信小程序图片延迟加载

    js 页面 Page({ data: { realScrollTop: 0,//页面滚动距离 driveHeight //屏幕高度可初始化设置 }, scroll(e){ if(e.detail.sc ...

  8. ucos-iii串口用信号量及环形队列中断发送,用内建消息队列中断接收

    串口发送部分代码: //通过信号量的方法发送数据 void usart1SendData(CPU_INT08U ch) { OS_ERR err; CPU_INT08U isTheFirstCh; O ...

  9. VS正则msdn地址

    https://msdn.microsoft.com/zh-cn/library/2k3te2cs(v=vs.100).aspx 备查.vs里正则有很多特殊的规则.

  10. git初始化项目 以及 git常用操作

    初始化项目 $ git config --global user.name "Your Name"  配置用户名 $ git config --global user.email ...