一、使用Systemd 方式配置开机自启动

systemd 是当前 Linux 主流用于系统和服务管理的组件,同时也取代了过去的SysV init 系统,关于systemd的介绍请见这里。 System 使用以 ”.service” 结尾的unit 配置文件来管控一个进程,Service 文件一般存放于”/etc/systemd/system” 或者 “/lib/systemd/system/“ 目录下,并可以通过systemctl 命令来启动,使能或者关闭 systemd有系统和用户区分;系统(/user/lib/systemd/system/)、用户(/etc/lib/systemd/user/).一般系统管理员手工创建的单元文件建议存放在/etc/systemd/system/目录下面。

https://blog.csdn.net/u010168781/article/details/79666992?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromBaidu-1.control&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromBaidu-1.control

  1. #启动服务
  2. $ sudo systemctl start nginx.service
  3. #查看日志
  4. $ sudo journalctl -f -u nginx.service
  5. 重新加载service文件:systemctl daemon-reload
  6. 启动一个服务:systemctl start nginx-1.13.0.service
  7. 关闭一个服务:systemctl stop nginx-1.13.0.service
  8. 重启一个服务:systemctl restart nginx-1.13.0.service
  9. 显示一个服务的状态:systemctl status nginx-1.13.0.service
  10. 在开机时启用一个服务:systemctl enable nginx-1.13.0.service
  11. 在开机时禁用一个服务:systemctl disable nginx-1.13.0.service
  12. 查看服务是否开机启动:systemctl is-enabled nginx-1.13.0.service
  13. 查看已启动的服务列表:systemctl list-unit-files|grep enabled
  14. 查看启动失败的服务列表:systemctl --failed

二、将用户脚本添加到/etc/init.d中

2.1 新建一个脚本

  1. #!/bin/bash
  2. ./usr/bin/diodon

2.2 拷贝到/etc/init.d/, 注册到系统

  1. sudo cp diodon.sh /etc/init.d/
  2. sudo update-rc.d diodon.sh defaults 96

2.3 删除用户进程

  1. sudo update-rc.d -f diodon remove

二、添加自启

http://www.360doc.com/content/19/0601/14/806630_839618914.shtml
https://www.jianshu.com/p/1a160067d8fd