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

我实际操作失败了

posted @   huangyn  阅读(522)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示