一、使用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/目录下面。
#启动服务
$ sudo systemctl start nginx.service
#查看日志
$ sudo journalctl -f -u nginx.service
重新加载service文件:systemctl daemon-reload
启动一个服务:systemctl start nginx-1.13.0.service
关闭一个服务:systemctl stop nginx-1.13.0.service
重启一个服务:systemctl restart nginx-1.13.0.service
显示一个服务的状态:systemctl status nginx-1.13.0.service
在开机时启用一个服务:systemctl enable nginx-1.13.0.service
在开机时禁用一个服务:systemctl disable nginx-1.13.0.service
查看服务是否开机启动:systemctl is-enabled nginx-1.13.0.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed
二、将用户脚本添加到/etc/init.d中
2.1 新建一个脚本
#!/bin/bash
./usr/bin/diodon
2.2 拷贝到/etc/init.d/, 注册到系统
sudo cp diodon.sh /etc/init.d/
sudo update-rc.d diodon.sh defaults 96
2.3 删除用户进程
sudo update-rc.d -f diodon remove
二、添加自启
http://www.360doc.com/content/19/0601/14/806630_839618914.shtml
https://www.jianshu.com/p/1a160067d8fd