Ubuntu设置开机启动

1. 创建执行脚本

touch test.sh

2. 编写test.sh脚本

cd /opt/server
./test.sh
exit 0

3. 移动test.sh文件到/etc/init.d目录下(开启启动目录)

# 移动文件
sudo mv test.sh /etc/init.d/
# 给文件增加权限
chmod +750 test.sh
# 设置开机自动启动
sudo update-rc.d test.sh defaults

4. 去除开机启动脚本

update-rc.d start.sh -f test.sh remove

5. 查看系统启动项

systemctl list-unit-files

6. 查看服务状态

systemctl status test.service

7. 禁用开机启动示例

sudo systemctl disable mongodb.service
sudo systemctl disable nginx.service
sudo systemctl disable redis-server.service

8. 停止已经开启的服务示例

sudo systemctl stop mongodb.service
sudo systemctl stop nginx.service
sudo systemctl stop redis-server.service

 

参考:

  • https://blog.csdn.net/caiqiiqi/article/details/99741513
  • https://blog.csdn.net/maxuearn/article/details/79879912
  • https://www.jb51.net/article/175654.htm

你可能感兴趣的:(Shell)