vim /etc/rc.local

#!/bin/sh## This script will be executed *after* all the other init scripts.# You can put your own initialization stuff in here if you don't# want to do the full Sys V style init stuff. touch /var/lock/subsys/local# 使用 bitlink 用户及 用户环境 后台执行 start.sh &后台运行su - bitlink -c "/home/bitlink/service/dc/start.sh &"
也是可以的 但是有一个弊端是重启之后需要root用户登录一次 才能执行。原因不详。
/etc/rc.d/init.d# cd /etc/rc.d/init.d
# touch bitlink.sh
#!/bin/sh#chkconfig: 2345 20 80##普通用户启动服务/bin/su - carbon -c "sh /home/carbon/service/start_jar.sh"/bin/su - carbon -c "docker-compose -f /home/carbon/software/middleware.yml up -d"
# chmod +x bitlink.sh
# chkconfig --add bitlink.sh
# chkconfig bitlink.sh on
CentOS 7采用systemd作为初始化系统,这是配置进程自启动的推荐方法:
sudo vim /etc/systemd/system/myapp.service
[Unit]Description=My ApplicationAfter=network.target[Service]ExecStart=/path/to/your/applicationRestart=alwaysUser=youruser[Install]WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable myapp.service
使用crontab计划任务
crontab -e
@reboot /path/to/your/application
以上为个人经验,希望能给大家一个参考,也希望大家多多支持本站。
您可能感兴趣的文章: