由于某些软件并没有增加开启启动的服务,很多时候需要手工添加,一般我们都是推荐添加命令到 /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. FZU2018级算法第五次作业 m_sort(归并排序或线段树求逆序对)

    首先对某人在未经冰少允许情况下登录冰少账号原模原样复制其代码并且直接提交的赤裸裸剽窃行为,并且最终被评为优秀作业提出抗议! 题目大意: 给一个数组含n个数(1<=n<=5e5),求使用冒泡 ...

  2. Python--对list、tuple、dict的操作

    一.List(列表) 首先,创建一个简单的list: animal = ['cat','dog','lion','tiger'] (1) 用索引的方式访问list中的元素:animal[0] 当索引从 ...

  3. 20191031:GIL全局解释锁

    20191031:GIL全局解释锁 总结关于GIL全局解释锁的个人理解 GIl全局解释锁,本身不是Python语言的特性,而是Python语言底层的c Python解释器的一个特性.在其他解释器中是没 ...

  4. 小白入门.有函数F(x)=(x+1)^2和G(x)=2x+1.输入x值计算F(G(x))。

    #include<stdio.h> #include<math.h> void main() { float x,y; printf("Please input x\ ...

  5. 【dfs】Sequence Decoding

    Sequence Decoding 题目描述 The amino acids in proteins are classified into two types of elements, hydrop ...

  6. H5中表格的用法

    1.表格的基本结构: 表格由行和列组成,单元格式表格的最基本单元;每个表格均有若干行,行标签由<tr></tr>定义,每行被分割为若干单元格,由<td></t ...

  7. 最简容器化动手小实践——再战flappybird

    <Flappy Bird>是一名越南开发者所开发的游戏,这款游戏的主要内容是帮助一只小鸟穿越水管的层层阻碍,玩家所需要的只是点击屏幕从而调整小鸟的高度.而令这款游戏与众不同的是,这款游戏的 ...

  8. sidecar-inject代码分析

    Istio通过对serviceMesh中的每个pod注入sidecar,来实现无侵入式的服务治理能力.其中,sidecar的注入是其能力实现的重要一环(本文主要介绍在kubernetes集群中的注入方 ...

  9. ionic开发遇到的问题总结

    前言 ionic是一个用来开发混合手机应用的,开源的,免费的代码库.可以优化html.css和js的性能,构建高效的应用程序,而且还可以用于构建Sass和AngularJS的优化.ionic会是一个可 ...

  10. java-websocket客户端 断线重连 注入Service问题

    java版客户端: 使用开源项目java-websocket, github地址: https://github.com/TooTallNate/Java-WebSocket github上有很多示例 ...