自制systemd服务运行多日后被标记为‘thawing’的问题排查求助
自制systemd服务运行多日后被标记为‘thawing’的问题排查求助
大家好,我遇到了一个奇怪的问题:自己写的systemd服务运行一段时间后,用systemctl status XXX查看时会被标记为**(thawing)**状态,但用htop看明明有多个线程在正常运行。而且不管是Python脚本还是Go编译的二进制程序,都会出现这个情况。
我用systemctl status auto_quote看到的状态示例如下:
[root]# systemctl status auto_quote ● auto_quote.service - run run_quotelive.sh ## <-change run_XXX.sh Loaded: loaded (/usr/lib/systemd/system/auto_quote.service; enabled; vendor preset: disabled) Active: active (running) (thawing) since Wed 2023-06-21 15:05:51 CST; 1 months 18 days ago Main PID: 1765370 (bash) Tasks: 8 (limit: 5366) Memory: 56.5M CGroup: /system.slice/auto_quote.service ├─1765370 /bin/bash /root/run_quotelive.sh ## <-change run_XXX.sh └─1765372 ./quotelive
对应的systemd服务配置文件/lib/systemd/system/auto_quote.service内容是:
[Unit] Description=run run_quotelive.sh ## <-change run_XXX.sh After=network.service [Service] Type=simple ExecStart=/bin/bash /root/run_quotelive.sh ## <-change run_XXX.sh Restart=on-failure RestartSec=3 ## systemd bears daemon duty [Install] WantedBy=multi-user.target
最开始的启动脚本run_quotelive.sh是这样写的,用eval把程序后台运行并输出日志:
# substitute PATH with the desired Abusolute path of the program, binary or script # substitute COMMAND with the shell command to run the program, binary or script # i.e. binary/executable named as XXX, change it to ./XXX # i.e. python3 script named as XXX.py, change it to python3 XXX.py # the script below would run it at background and leave starting/failing time # as well as program output( both normal print and errors) into PATH/out.log cd /root/quotelive cmd='./quotelive' newcmd="$cmd &>> out.log" echo -e '\n' `date +'%Y/%m/%d %a, %X'`: STARTING - "$cmd" '\n' >> out.log eval $newcmd echo -e '\n' `date +'%Y/%m/%d %a, %X'`: PROCESS FAILED >> out.log exit 5 # make an error exit for service to restart
我以为是后台运行的问题,于是修改了脚本,让程序前台执行,只有异常退出时才记录失败日志并返回错误码让systemd重启:
cd /root/quotelive cmd='./quotelive' echo -e '\n' `date +'%Y/%m/%d %a, %X'`: STARTING - "$cmd" '\n' >> out.log $cmd >>out.log 2>&1 if [ $? -ne 0 ]; then echo -e '\n' `date +'%Y/%m/%d %a, %X'`: PROCESS FAILED >> out.log exit 5 # make an error exit for service to restart fi
为了测试,我把程序换成了python3 -m http.server 12345这种会持续运行的服务,但问题还是存在——运行一段时间后服务依然会被标记为**(thawing)**。另外我还发现,原本应该重定向到/root/quotelive/out.log的程序输出,居然出现在了systemctl status auto_quote的输出里。
想请教一下,我的systemd服务配置或者启动脚本哪里有问题吗?为什么会出现这种thawing的状态?
备注:内容来源于stack exchange,提问作者George Y
相关产品推荐
相关产品推荐

