由于某些软件并没有增加开启启动的服务,很多时候需要手工添加,一般我们都是推荐添加命令到 /etc/rc.local 文件,但是 Debian 9 默认不带 /etc/rc.local 文件,而 rc.local 服务却还是自带的

root@debian9 ~ # cat /lib/systemd/system/rc.local.service
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version. # This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.local
After=network.target [Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

并且默认情况下这个服务还是关闭的状态

root@debian9 ~ # systemctl status rc-local
● rc-local.service - /etc/rc.local Compatibility
Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
Drop-In: /lib/systemd/system/rc-local.service.d
└─debian.conf
Active: inactive (dead)

添加/etc/rc.local

为了解决这个问题,我们需要手工添加一个 /etc/rc.local 文件

cat <<EOF >/etc/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. exit 0
EOF

赋予权限

chmod +x /etc/rc.local

启动 rc-local 服务

systemctl start rc-local

再次查看状态

root@debian9 ~ # systemctl status rc-local
● rc-local.service - /etc/rc.local Compatibility
Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
Drop-In: /lib/systemd/system/rc-local.service.d
└─debian.conf
Active: active (exited) since Thu 2017-08-03 09:41:18 UTC; 14s ago
Process: 20901 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS) Aug 03 09:41:18 xtom-proxy systemd[1]: Starting /etc/rc.local Compatibility...
Aug 03 09:41:18 xtom-proxy systemd[1]: Started /etc/rc.local Compatibility.

添加命令启动

然后你就可以把需要开机启动的命令添加到 /etc/rc.local 文件,丢在 exit 0 前面即可,并尝试重启以后试试是否生效了

root@Samba96-21:/home/user# ls
images ServerStatus
root@Samba96-21:/home/user# cd ServerStatus/
root@Samba96-21:/home/user/ServerStatus# pwd
/home/user/ServerStatus root@Samba96-21:/home/user# vim.tiny /etc/rc.local /usr/bin/python3 /home/user/ServerStatus/ServerStatus.py & exit 0

作者:吾星喵
链接:https://www.jianshu.com/p/8408d66942bf
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

Debian 9.x "stretch" 解决 /etc/rc.local 开机启动问题的更多相关文章

  1. Ubuntu 16.04设置rc.local开机启动命令/脚本的方法

    Ubuntu 16.04设置rc.local开机启动命令/脚本的方法       Ubuntu 16.04设置rc.local开机启动命令/脚本的方法(通过update-rc.d管理Ubuntu开机启 ...

  2. Ubuntu 16.04设置rc.local开机启动命令/脚本的方法(通过update-rc.d管理Ubuntu开机启动程序/服务)

    注意:rc.local脚本里面启动的用户默认为root权限. 一.rc.local脚本 rc.local脚本是一个Ubuntu开机后会自动执行的脚本,我们可以在该脚本内添加命令行指令.该脚本位于/et ...

  3. (转)CentOS 7 —— /etc/rc.local 开机不执行 - 解决方法

    chmod +x /etc/rc.d/rc.localsystemctl enable rc-local.service Note: rc.local is obsolete. ----------- ...

  4. 配置rc.local开机自启动文件的疑问

    有时我们自己在/etc/rc.d/rc.local里面增加的随机器启动的脚本和指令总是不能自动加载和启动,,机器启动后手动执行脚本又能成功,经常被搞得晕头转向的.最近我经过1天的辛苦测试和查找资料,终 ...

  5. centos 7 /etc/rc.local 开机不执行的问题

    最近发现centos7 的/etc/rc.local不会开机执行,于是认真看了下/etc/rc.local文件内容的就发现了问题的原因了 1 2 3 4 5 6 7 8 9 10 11 #!/bin/ ...

  6. centos7设置rc.local开机执行命令

    在Centos7下,rc.local文件,开机默认是不执行的 它是个软链接 [root@data-1-1 ~]# ll /etc/rc.local lrwxrwxrwx. 1 root root 13 ...

  7. /etc/rc.d/rc.local linux启动自动开启某些服务(转)

    /etc/rc.d/rc.local似乎是很多Linux系统管理员的偏爱,因为凡是需要随系统自动启动的服务.程序等,只要系统没有提供Sys V风格的启动脚本,就把这些需求都塞到/etc/rc.d/rc ...

  8. rc.local 开机自启脚本无法启动

    1.看是否rc.local 第一行如果是 #!/bin/sh -e 改成 #!/bin/bash sudo systemctl enable rc-local.service 2.看rc.local的 ...

  9. CentOS7 rc.local开机开法启动

    CentOS 7添加开机启动服务/脚本 一.添加开机自启服务 在CentOS 7中添加开机自启服务非常方便,只需要两条命令(以Jenkins为例):systemctl enable jenkins.s ...

随机推荐

  1. 题解 CF1216A 【Prefixes】

    题目大意:给你一个长度为$n$($n$为偶数)的字符串,且这个字符串仅由$'a'$与$'b'$两种字符组成,要你用最少的操作次数使得 $s[i]!=s[i-1] (i/2=0,1≤i≤n)$(若字符串 ...

  2. echo、print和print_r的区别

    1.echo 可以输出一个或多个字符串 ,多个以逗号隔开就行 2.print 也可以输出一个或多个字符串 ,多个要用连接符 3.print_r()可以打印数组:对象 bool print_r ( mi ...

  3. Python-18-类的内置属性

    1. __getattr__.set__attr__.__delattr__ class Foo: x=1 def __init__(self,y): self.y=y def __getattr__ ...

  4. sublime3 安装markdown插件

    sublime3 安装markdown插件 第一步安装package control 自动安装package control 手动安装package control 安装具体的markdown相关的p ...

  5. http GET 和 POST 请求的优缺点、区别以及误区

    原文章:https://blog.csdn.net/qq_28483283/article/details/80207674 请优先参考原文章 Get和Post在面试中一般都会问到,一般的区别: (1 ...

  6. PAT(B) 1039 到底买不买(Java)字符串

    题目链接:1039 到底买不买 (20 point(s)) 题目描述 小红想买些珠子做一串自己喜欢的珠串.卖珠子的摊主有很多串五颜六色的珠串,但是不肯把任何一串拆散了卖.于是小红要你帮忙判断一下,某串 ...

  7. 小细节--关于printf的输出问题

    关于printf输出函数,曾经在栈和队列中有过提及,并未作过深入的研究,今天在看一些面经的时候发现有的公司有所提及,那么就势研究一下 面试题如下: 首先看一下printf函数在汇编层面上是如何实现的: ...

  8. PB笔记之日期函数

    https://wenku.baidu.com/view/a0d5f16fb84ae45c3b358cc7.html this.object.yjzzrq[row]= RelativeDate(dat ...

  9. 案例(2)-- 线程不安全对象(SimpleDateFormat)

    问题描述: 1.系统偶发性抛出异常:java.lang.NumberFormatException: multiple points ,追溯源头抛出的类为:SimpleDateFormat 问题的定位 ...

  10. FPS 游戏实现GDI透视

    FPS游戏可以说一直都比较热门,典型的代表有反恐精英,穿越火线,绝地求生等,基本上只要是FPS游戏都会有透视挂的存在,而透视挂还分为很多种类型,常见的有D3D透视,方框透视,还有一些比较高端的显卡透视 ...