1. 程式人生 > >pt-heartbeat --update --daemonize 只執行一次秒退的問題

pt-heartbeat --update --daemonize 只執行一次秒退的問題

you 參數 程序退出 sam remove exitcode working previous wan

使用pt-heartbeat幫助測試MySQL從庫delay時長-

第一次運行測試成功,運行順暢。

過幾天再次用--update測試時,發現pt-heartbeat只update一次就自己退出了,--daemonize參數似乎不起作用。

而且程序退出的exitcode還是0.

排查半天未發現問題。

後在從庫上測試,發現出現同樣問題,但這次註意到--stop的時候有提示:

[root@localhost mysql3306]# /usr/bin/pt-heartbeat --stop --database=pt --defaults-file=/data/mysql/mysql3306/conf/my3306.cnf --socket=/data/mysql/mysql3306/3306.sock --ask-pass
Successfully created file /tmp/pt-heartbeat-sentinel

查看pt-heartbeat代碼發現該文件存在pt-heartbeat就會自動退出。

刪除掉該文件後,主庫上終於可以運行pt了。

重新仔細閱讀pt-heartbeat的man手冊才發現,手冊裏早已經進行了說明。

--sentinel
type: string; default: /tmp/pt-heartbeat-sentinel Exit if this file exists.
--stop
Stop running instances by creating the sentinel file. This should have the effect of stopping all running instances which are watching the same sentinel file. If none of "--update", "--monitor" or "--check" is specified, "pt-heartbeat" will exit
after creating the file. If one of these is specified, "pt-heartbeat" will wait the interval given by "--interval", then remove the file and continue working. You might find this handy to stop cron jobs gracefully if necessary, or to replace one running instance with another. For example, if you want to stop and restart "pt-heartbeat" every hour
(just to make sure that it is restarted every hour, in case of a server crash or some other problem), you could use a "crontab" line like this: 0 * * * * pt-heartbeat --update -D test --stop \
--sentinel /tmp/pt-heartbeat-hourly The non-default "--sentinel" will make sure the hourly "cron" job stops only instances previously started with the same options (that is, from the same "cron" job). See also "--sentinel".
[root@localhost mysql3306]# cat /tmp/pt-heartbeat-sentinel
Remove this file to permit pt-heartbeat to run

pt-heartbeat --update --daemonize 只執行一次秒退的問題