ubuntu 自启动服务

#查看所有服务
systemctl list-unit-files --type service -all
方法1:开机自动执行一个脚本
参考https://blog.csdn.net/t624124600/article/details/111085234,https://www.cnblogs.com/milton/p/7812177.html
/etc/init.d/xxxx
配置启动脚本xxxx,放到/etc/init.d/
chmod a+x xxx update-rc.d xxx defaults 90 service xxx start/stop/status/restart 或者 systemctl start/stop/status/restart xxx

#配置开机启动,参考https://blog.csdn.net/u014299762/article/details/103936006
修改启动脚本/etc/init.d/xxx
#!/bin/bash ### BEGIN INIT INFO # Provides: xxx # Required-Start: # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start xxx daemon at boot time # Description: Start xxx daemon at boot time ### END INIT INFO
systemctl enable xxx
systemctl is-enabled xxx
方法2:创建/etc/systemd/system/xxx.service
创建 /lib/systemd/system/xxx.service,之后软链接到 /etc/systemd/system/,或者直接创建/etc/systemd/system/xxx.service
[Unit]
Description=Finein
After=network.target mysql.target
[Service]
Type=forking
#jdk路径
Environment="JAVA_HOME=/usr/java/jdk1.8.0_321/"
#Finein安装路径
ExecStart=/home/develop/tomcat9_Finein/bin/startup.sh
ExecStop=/home/develop/tomcat9_Finein/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#服务
systemctl status/start/stop/restart Finein

方法3:利用/etc/rc.local
#参考 https://zhuanlan.zhihu.com/p/271963900
我实际操作失败了
 
                    
                     
                    
                 
                    
                 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号