Process
查找觸發重啟的程序或程序
每天晚上凌晨 3:00,我的 Raspberry 會重新啟動,但我所做的或正在執行的任何事情都沒有觸發這個。我想確定“違規”程序並禁用重新啟動。
這是目前版本:
pi@raspberrypi:~ $ lsb_release -a No LSB modules are available. Distributor ID: Raspbian Description: Raspbian GNU/Linux 10 (buster) Release: 10 Codename: buster
我檢查了
crontab -e
;沒有什麼會觸發這個。關於如何辨識可能觸發計劃重啟的其他建議?謝謝你。
更新
命令的輸出
last
:pi@raspberrypi:~/splitflap $ last pi pts/2 192.168.0.8 Wed May 6 17:42 still logged in pi pts/2 192.168.0.8 Wed May 6 09:34 - 17:34 (08:00) pi pts/1 192.168.0.8 Wed May 6 09:34 still logged in pi pts/0 192.168.0.8 Wed May 6 09:34 still logged in reboot system boot 4.19.97-v7+ Wed Dec 31 16:00 still running
更新
systemctl list-timers --all
命令的輸出pi@raspberrypi:~/splitflap/pickle $ systemctl list-timers --all NEXT LEFT LAST PASSED UNIT ACTIVATES Thu 2020-05-07 08:39:00 PDT 5min left Thu 2020-05-07 08:09:10 PDT 24min ago phpsessionclean.timer phpsessionclean.service Thu 2020-05-07 08:46:11 PDT 12min left Thu 2020-05-07 08:31:11 PDT 2min 21s ago prometheus-node-exporter-apt.timer prometheus-node-exporter-apt.service Thu 2020-05-07 08:46:11 PDT 12min left Thu 2020-05-07 08:31:11 PDT 2min 21s ago prometheus-node-exporter-smartmon.timer prometheus-node-exporter-smartmon.service Thu 2020-05-07 13:51:22 PDT 5h 17min left Wed 2020-05-06 19:22:06 PDT 13h ago apt-daily.timer apt-daily.service Fri 2020-05-08 00:00:00 PDT 15h left Thu 2020-05-07 00:00:12 PDT 8h ago logrotate.timer logrotate.service Fri 2020-05-08 00:00:00 PDT 15h left Thu 2020-05-07 00:00:12 PDT 8h ago man-db.timer man-db.service Fri 2020-05-08 03:15:12 PDT 18h left Thu 2020-05-07 03:15:12 PDT 5h 18min ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service Fri 2020-05-08 06:24:39 PDT 21h left Thu 2020-05-07 06:04:53 PDT 2h 28min ago apt-daily-upgrade.timer apt-daily-upgrade.service n/a n/a n/a n/a prometheus-node-exporter-ipmitool-sensor.timer prometheus-node-exporter-ipmitool-sensor.service n/a n/a n/a n/a prometheus-node-exporter-mellanox-hca-temp.timer prometheus-node-exporter-mellanox-hca-temp.service
我在凌晨 3 點之前看不到任何東西 -
systemd-tmpfiles-clean.service
凌晨 3 點 15 分執行的那個,但恰好在凌晨 3 點 00 分,系統重新啟動。不過,我是 systemd 的新手,所以也許還有其他沒有透露的計時器?我試過
sudo systemctl list-timers --all
了,但得到了相同的列表。我還在 cron.daily 中找到了以下內容;在審查了每個腳本之後,沒有什麼會觸發重新啟動(儘管如果我正確解釋了 /etc/crontab,那麼每日腳本無論如何都會在第 6 分鐘(但不清楚幾點)執行,而不是在小時。
pi@raspberrypi:~ $ cat /etc/crontab # /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed 17 * * * * root cd / && run-parts --report /etc/cron.hourly 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) #
pi@raspberrypi:~ $ ls /etc/cron.daily/ apt-compat bsdmainutils dpkg exim4-base lighttpd logrotate man-db ntp passwd
使用記錄器更新
好消息是對命令的修改記錄了請求 - 請參見最後兩行:
pi@raspberrypi:~/splitflap $ cat /var/log/user.log <4 other lines removed> May 8 03:00:01 raspberrypi reboot: Reboot requested but ignored: reboot May 8 03:00:01 raspberrypi reboot: Parent: root 15328 15318 0 03:00 ? 00:00:00 /bin/sh -c /sbin/reboot
Def 感覺更近了,但我在這裡承認我缺乏關於如何進一步辨識有問題的程序或服務的知識 - 當我執行
ps -ef
.
如果您替換
/sbin/reboot
為通知和日誌記錄腳本,它可能有助於確定導致重新啟動的原因。這是設置此類腳本的一個範例:mv /sbin/reboot /sbin/reboot.REAL cat >>/sbin/reboot <'x' #!/bin/bash # logger -t reboot "Reboot requested but ignored: reboot $*" # Identify the calling process ps=$(ps -ef | awk -v ppid=$PPID '$2 == ppid') logger -t reboot "Parent: $ps" # Abort exit 1 x chmod a+x /sbin/reboot
當您將此稱為假時,您將在每次呼叫
reboot
中獲得兩個條目。/var/log/user.log
例如,May 7 16:06:20 pi reboot: Reboot requested but ignored May 7 16:06:20 pi reboot: Parent: roaima 20862 20857 0 16:01 pts/0 00:00:00 -bash
可能需要對
systemctl ... reboot
. 這有點困難,因為不破壞其他功能很重要。像這樣開始的腳本可能適合安裝為/bin/systemctl
:#!/bin/bash # if [[ "$*" != *reboot* ]] then logger -t reboot "Not a reboot: systemctl $*" exec /bin/systemctl.REAL "$@" fi logger -t reboot "Reboot requested but ignored: systemctl $*" ...