一、守护进程
写个sh脚本
#!/bin/sh #echo "[`date`] run.sh triggered" >> /root/wxPubServ/run.log while true; do cd /root/wxPubServ/ #跳转到项目路径,如果你有配置文件的话 /root/wxPubServ/OverMan_linux #拉起你的程序 echo "程序崩溃,15 秒后重启..." sleep 15 done设置可运行权限
chmod +x /root/wxPubServ/run.sh二、开机自启
这是执行守护进程的指令
pgrep -f run.sh > /dev/null || bash /root/wxPubServ/run.sh &将其添加到 /etc/profile中, 开机启动, 直接用echo写到profile中
echo 'pgrep -f run.sh > /dev/null || bash /root/wxPubServ/run.sh &' >> /etc/profile或 在profile中编辑,
1输入指令vi /etc/profile
2按 i 后编辑,将刚刚所说的指令粘贴到最后一行
3按ESC然后输入:wq保存
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1)) # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...). # profile本身就有的内容 if [ "${PS1-}" ]; then if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then # The file bash.bashrc already sets the default PS1. # PS1='\h:\w\$ ' if [ -f /etc/bash.bashrc ]; then . /etc/bash.bashrc fi else if [ "$(id -u)" -eq 0 ]; then PS1='# ' else PS1='$ ' fi fi fi if [ -d /etc/profile.d ]; then for i in /etc/profile.d/*.sh; do if [ -r $i ]; then . $i fi done unset i fi PATH=/root/miniconda3/bin:/usr/local/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt #添加这条命令 pgrep -f run.sh > /dev/null || bash /root/wxPubServ/run.sh &