全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 1216|回复: 11

Debian10如何开机自启shell脚本?Debian10没有rc.local了

[复制链接]
发表于 2020-2-1 23:45:34 | 显示全部楼层 |阅读模式
本帖最后由 mymyhope 于 2020-2-2 00:13 编辑

谷歌也谷歌不到 百度也没有答案?????
打的Debian10 要怎么开机自启shell?

update-rc.d试过了 无效


果然是自己太无能了,待会儿试试楼下大佬们的方案。不一一回复了 感谢!
发表于 2020-2-3 09:44:55 | 显示全部楼层
Debian has removed rc.local from its recent releases.
I have created a simple script which adds rc.local back to the system.
You need to run the following command as root:

bash <(curl -s https://www.adminsehow.com/wp-content/uploads/2019/10/rc-local.txt)
or if you are skeptical to run a script from internet, you can create rc-local.txt yourself and run it.
rc-local.txt :

#!/bin/bash

echo '[Unit]
Description=/etc/rc.local
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' > /etc/systemd/system/rc-local.service


echo '#!/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' > /etc/rc.local

chmod +x /etc/rc.local
systemctl enable rc-local
发表于 2020-2-3 06:05:17 | 显示全部楼层
  1. sudo nano /etc/rc.local
复制代码
  1. #!/bin/sh -ex
  2. #
  3. # rc.local
  4. #
  5. # This script is executed at the end of each multiuser runlevel.
  6. # Make sure that the script will "exit 0" on success or any other
  7. # value on error.
  8. #
  9. # In order to enable or disable this script just change the execution
  10. # bits.
  11. #
  12. # By default this script does nothing.

  13. exit 0
复制代码
  1. sudo chmod +x /etc/rc.local
复制代码
  1. sudo systemctl start rc-local
复制代码
发表于 2020-2-1 23:46:51 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2020-2-1 23:52:11 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2020-2-1 23:53:28 来自手机 | 显示全部楼层
systemd了啊,自己新建个服务啊
发表于 2020-2-1 23:59:23 来自手机 | 显示全部楼层
systemd,在/lib/systemd/system里面添加一个.service,然后systemctl enable xxx,就是这么简单
发表于 2020-2-2 00:02:22 | 显示全部楼层
使用oneshot类型系统服务
  1. [Service]
  2. Type=oneshot
复制代码

如果有更进一步要求可以参考下这个:
https://unix.stackexchange.com/questions/320400/systemd-oneshot-requirement-to-execute-only-once
发表于 2020-2-2 00:02:49 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2020-2-2 00:23:35 | 显示全部楼层
推荐楼上 systemctl 自建服务的方式
发表于 2020-2-3 07:40:40 | 显示全部楼层
个人习惯了用supervisor
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-4-26 03:53 , Processed in 0.065616 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表