lean openwrt 里的 qbittorrent-nox 服务 如何监控其是否在运行并在发现服务挂掉时重启? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
OpenWrt 是一个专门面向嵌入式设备的 Linux 发行版。你可以将 OpenWrt 支持的型号的嵌入式设备,比如各种路由器上的系统,换成一个有更多可能性可以折腾的 Linux 系统。
OpenWrt 官方网站
AllenHua
V2EX    OpenWrt

lean openwrt 里的 qbittorrent-nox 服务 如何监控其是否在运行并在发现服务挂掉时重启?

  •  
  •   AllenHua 2021-01-10 11:48:52 +08:00 669 次点击
    这是一个创建于 1737 天前的主题,其中的信息可能已经有所发展或是发生改变。
    1. openwrt 没有 systemd
    2. 编写了一个 shell 脚本 配合 crond 服务一直没有成功
    #!/bin/sh while true do COUNT=$(ps |grep qbittorrent |grep -v grep |wc -l) echo "current running qbittorrent process count: "$COUNT if [ $COUNT -eq 0 ] then su - transmission <<EOF /usr/bin/qbittorrent-nox --profile=/mnt/ThreeTB2/qbit_backup echo "qbittorrent-nox process has been restarted!" EOF else echo "qbittorrent-nox already started!" fi sleep 10 done kill $! 

    以上文件放在 /mnt/ThreeTB2/qbittorrent.sh 已经添加 可执行权限

    cron 脚本是 */3 * * * * /bin/ash /mnt/ThreeTB2/qbittorrent.sh > /tmp/crontab-qbittorrent-sh.log

    测试的时候 用的 每隔三分钟 执行一次

    但是调试了一段时间 发现并不靠谱…… 希望大神前来指点

    1 条回复    2021-01-10 12:16:25 +08:00
    AllenHua
        1
    AllenHua  
    OP
       2021-01-10 12:16:25 +08:00
    重新编写了一个 `/mnt/ThreeTB2/check_qbittorrent.sh`

    ```bash
    #!/bin/bash
    # author: xxx
    # time: 2021-01-10
    # program: check if qbittorrent-nox is running, if not, start it

    function check_qbittorrent(){
    qbittorrentCount=`ps |grep qbittorrent-nox |grep -v grep |wc -l`
    echo "current running qbittorrent process count: "$qbittorrentCount
    if [ 0 == $qbittorrentCount ]; then
    /usr/bin/qbittorrent-nox --profile=/mnt/ThreeTB2/qbit_backup
    fi
    }

    check_qbittorrent
    ```

    cron 表达式 `*/3 * * * * /bin/ash /mnt/ThreeTB2/check_qbittorrent.sh > /tmp/crontab-qbittorrent-sh.log`

    似乎是 ok 了 发现了问题所在,刚刚 使用 ps 过滤程序时 应该过滤 qbittorrent-nox 才对 所以刚刚程序中的 COUNT 会出现问题 过滤 qbittorrent-nox 就好
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     5575 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 33ms UTC 07:20 PVG 15:20 LAX 00:20 JFK 03:20
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86