0%

Debian解决开机启动问题

Debian 10 解决 /etc/rc.local 开机启动问题

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

QQ群:397745473

查看服务配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@debian /root]#  cat /lib/systemd/system/rc.local.service
# SPDX-License-Identifier: LGPL-2.1+
#
# 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
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

查看服务状态

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

1
2
3
4
5
6
7
[root@debian /root]#  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: /usr/lib/systemd/system/rc-local.service.d
└─debian.conf
Active: inactive (dead)
Docs: man:systemd-rc-local-generator(8)

增加配置文件

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@debian /root]#  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

** 这里有几个需要注意的地方 **

1
2
3
4
5
6
7
8
注意1: 
#!/bin/sh -e
不能是
# !/bin/sh -e
中间有个空格就会报格式错误

注意2:
在 exit 0 前加入需要执行的命令或脚本. 需要在最后面加一个"&" 符号.放到后台执行。不然也会报错

赋予配置文件权限

1
[root@debian /root]#  chmod +x /etc/rc.local

启动 rc-local 服务

1
[root@debian /root]#  systemctl start rc-local

查看服务状态

1
2
3
4
5
6
7
8
9
10
11
[root@debian /root]#  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: /usr/lib/systemd/system/rc-local.service.d
└─debian.conf
Active: active (exited) since Tue 2020-03-17 10:04:27 CST; 9s ago
Docs: man:systemd-rc-local-generator(8)
Process: 18500 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

3月 17 10:04:27 debian systemd[1]: Starting /etc/rc.local Compatibility...
3月 17 10:04:27 debian systemd[1]: Started /etc/rc.local Compatibility.

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

报错解决:the input device is not a TTY

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#参考 https://blog.csdn.net/sunmingyang1987/article/details/108877902
在重启过程中用shell脚本去启动docker容器并执行某一操作时,
可能会出现如题所示错误,
原因是后台linux执行的时候没有终端设备,
TTY一词源于Teletypes,或teletypewriters。其实出现该错误和我们的一个习惯有关,
一般来说我们启动容器后要与容器进行交互操作,这是,就要加上"-it"这个参数,
而在重启过重中或定时任务中,如果让脚本在后台运行,
就没有可交互的终端,这就会引发如题所示错误,解决办法就是去掉“-it”这个参数。

sudo nvidia-docker start Jupyter;
nohup sudo docker exec Jupyter bash /etc/init.d/Jupyter.sh &
exit 0


sudo nvidia-docker start Jupyter;
nohup sudo docker exec Jupyter bash /etc/init.d/Jupyter.sh;
exit 0


sudo nvidia-docker start Jupyter;
sudo docker exec Jupyter bash /etc/init.d/Jupyter.sh;



Ubuntu16.04 rc.local不生效,启动过程中报“Failed to start /etc/rc.local Compatibility”错误

使用Ubuntu16.04时,发现有时候启动脚本/etc/rc.local中的命令不生效,随即发现在这种情况下系统启动时会打印 Failed to start /etc/rc.local Compatibility 错误。

搜索了下,找到适合我的解决办法是将文件中第一行:
文件

修改成 #!/bin/bash 就可以了。
原因可能是用户使用的shell和rc.local文件指定的执行shell不一致。
记录下,以免以后忘记。

QQ群:397745473

欢迎关注我的其它发布渠道