ubuntu-18.04 设置开机启动脚本

参阅下列链接

https://askubuntu.com/questions/886620/how-can-i-execute-command-on-startup-rc-local-alternative-on-ubuntu-16-10

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

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

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

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

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

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

    参考:https://www.cnblogs.com/defifind/p/9285456.html    http://www.cnblogs.com/airdot/p/9688530.html s ...

  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. .net Core+Dapper MySQL增删改查

    新建一个用户表,以该有为例 1.Model层 public class TuiUsers { public int id { get; set; } public string userName { ...

  2. kafka可视化客户端工具(Kafka Tool)的基本使用(转)

    转载地址:https://www.cnblogs.com/frankdeng/p/9452982.html 1.下载 下载地址:http://www.kafkatool.com/download.ht ...

  3. web.xml中Servlet3.1版本的头信息格式

    <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http:// ...

  4. swool配置ssl

    1 yum install  openssl  --enable-openssl -y 2 切换在swoole 安装目录 cd /usr/local/swoole 3 ./configure --en ...

  5. 【转】Apache与Tomcat有什么关系和区别

    [原文链接:https://www.cnblogs.com/zangdalei/p/8057325.html] Apache 和 Tomcat 都是web网络服务器,两者既有联系又有区别,在进行HTM ...

  6. WPF使用总结

    ListboxItemContainer样式 一般items控件的项模板 很容易 设置DataTemplate就可以了,比如listbox .但是在选中和失去焦点的时候 却是Windows自带的那种 ...

  7. SpringBoot使用prometheus监控

    本文介绍SpringBoot如何使用Prometheus配合Grafana监控. 1.关于Prometheus Prometheus是一个根据应用的metrics来进行监控的开源工具.相信很多工程都在 ...

  8. STM8L052低功耗模式

    Stm8L系列单片机的低功耗有五种模式: § wait模式 § Lowpower run模式 § Lowpower wait模式 § Active-haltwith full RTC模式 § Halt ...

  9. Spark集群部署(standLone)模式

      安装部署: 1. 配置spark为1个master,2个slave的独立集群(Standlone)模式, 可以在VMWare中构建3台运行Ubuntu的机器作为服务器: master主机配置如下: ...

  10. H5本地存储详细使用教程(localStorage + JSON数据存储应用框架)

    一.Web Storage教程 1.概述: 对于Web Storage来说,实际上是Cookies存储的进化版.如果了解Cookie的人几乎一看Web Storage就会用,如果你从来没用过没了解过C ...