尧图网站设计 尧图网站设计YAOTU DESIGN
ARTICLE DETAIL

资讯详情

深耕网站设计与一线实操的经验洞察。

Docker容器内部 开机自启+进程守护

Docker容器内部 开机自启+进程守护 一、守护进程写个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/profile2按 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
返回列表