写了一个 IPFS 守护进程

项目中有使用到 IPFS ,但是最新的版本老是会挂掉(目前没有精力搞挂掉的原因)。所以就写了个脚本。查询到 IPFS 进程死掉会,就重新启动。

vim watch.sh

#! /bin/bash
# 守护的进程名称
PRO_NAME=/ipfs/ipfs

while true ; do
    # 用 ps 获取 $PRO_NAME 进程数量
    NUM=`ps aux | |grep ${PRO_NAME} | grep -v grep|wc -l`
    # 小于1,说明进程死掉,需要重启
    if [ "${NUM}" -lt "1" ];then
        echo "${PRO_NAME} was stoped"
        # 启动命令
        nohup /home/xxxxxx/cmd/ipfs/ipfs daemon > /home/xxxxxx/ipfs.log 2>&1 &
    fi
done
exit 0

使用后台启动的方式启动脚本

nohup sh watch.sh > watch.log 2>&1 &