由于某些软件并没有增加开启启动的服务,很多时候需要手工添加,一般我们都是推荐添加命令到 /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. Linux文件和目录相关的命令

    当前目录 .     上一层目录 ..     tab键 自动补全             查看目录内容 ls 以.开头的都是隐藏文件需要用-a才能显示出来 ls通配符的使用 * 代表任意个数个字符 ...

  2. maven 打包成 .jar 文件执行:没有主清单属性错误

    报错原因是pom.xml配置文件中没有指定main入口信息,在pom.xml文件中添加如下代码: <build> <plugins> <plugin> <gr ...

  3. Android--Fragment嵌套的问题

    项目中遇到Fragment嵌套应用的问题 子Fragment中要用getChildFragmentManager()方法获取FragmentManager,否则会出问题!

  4. Angular Material 学习笔记 Chips

    依据 material guidelines, chips 可以用来做 filter https://material.io/design/components/chips.html#filter-c ...

  5. 设计基于HTML5的APP登录功能及安全调用接口的方式(原理篇)

    登录 保存密码 安全 加密 最近发现群内大伙对用Hbuilder做的APP怎么做登录功能以及维护登录状态非常困惑,而我前一段时间正好稍微研究了一下,所以把我知道的告诉大家,节约大家查找资料的时间. 你 ...

  6. PEB TEB结构体使用

    PEB TEB结构体使用一个可执行文件被OS加载到内存,并处理完成相关的模块加载,导入表处理……及其他必须处理后,形成一个进程.在OS内核中保存有一份关于这个进程的身份证信息,就是平常看到的HANDL ...

  7. .NET Core 使用swagger进行分组显示

    其实,和swagger版本管理类似;只是平时接口太多;不好供前端人员进行筛选. 下面进入主题: 首先: //注册Swagger生成器,定义一个和多个Swagger 文档 services.AddSwa ...

  8. CentOS 6.x 配置iptables

    CentOS 6.x 配置iptables 来源 https://www.cnblogs.com/chillax1314/p/7976067.html iptables -P INPUT DROP-- ...

  9. pinfinder

    pinfinder https://pinfinder.net https://github.com/gwatts/pinfinder 关于 Pinfinder是一个小型免费程序,可以使用iPhone ...

  10. WebSocket 的应用

    后面用到了再来做整理 链接地址:https://www.cnblogs.com/zhaof/p/9833614.html