美文网首页
ubuntu22添加系统启动脚本

ubuntu22添加系统启动脚本

作者: xiaohei08 | 来源:发表于2022-06-12 17:11 被阅读0次

前言

Ubuntu 18 不再使用initd管理系统,而是使用systemd;我们使用 update-rc.d,可以添加和删除服务,并将它们添加到Ubuntu / Debian启动脚本中,实现开启自启动效果。

实现过程

  1. 新建脚本new_service.sh
#!/bin/bash
# command content
exit 0
  1. 设置权限
sudo chmod +x new_service.sh
  1. 将文件移动到启动目录下
sudo mv new_service.sh /etc/init.d/
  1. 添加启动脚本
sudo update-rc.d new_service.sh defaults 90
  1. 查看服务列表
sudo service --status-all
  1. 服务相关操作
sudo service xxx status
sudo service xxx start
sudo service xxx stop
sudo service xxx restart
  1. 移除开机脚本
sudo update-rc.d -f new_service.sh remove

后记

相关文章

网友评论

      本文标题:ubuntu22添加系统启动脚本

      本文链接:https://www.haomeiwen.com/subject/bswomrtx.html