Upstart 服务被 TERM 信号杀死,如何跟踪

Upstart 服务被 TERM 信号杀死,如何跟踪

我有暴发户脚本

description "My API API"
author "me@localhost"

env MY_API_PYTHON_HOME=/opt/services

start on runlevel [2345]
stop on runlevel [!2345]

script
  mkfifo /tmp/my-api-log-fifo
  ( logger -t my-api </tmp/my-api-log-fifo & )
  exec >/tmp/my-api-log-fifo
  rm /tmp/my-api-log-fifo
  exec $MY_API_PYTHON_HOME/script_api_virt/bin/python $MY_API_PYTHON_HOME/my_api.py 2>/dev/null
end script

# Restart the process if it dies with a signal
# or exit code not given by the 'normal exit' stanza.
respawn

# Give up if restart occurs 10 times in 90 seconds.
respawn limit 10 90

当我启用调试日志时,它显示

Oct  3 19:50:48 localhost kernel: [6732712.553365] init: job_class_register: Registered job /com/ubuntu/Upstart/jobs/ureadahead
Oct  3 19:50:48 localhost kernel: [6732712.553692] init: my-api goal changed from start to stop
Oct  3 19:50:48 localhost kernel: [6732712.553742] init: my-api state changed from running to pre-stop
Oct  3 19:50:48 localhost kernel: [6732712.553776] init: my-api state changed from pre-stop to stopping
Oct  3 19:50:48 localhost kernel: [6732712.553808] init: event_new: Pending stopping event
Oct  3 19:50:48 localhost kernel: [6732712.553823] init: Handling stopping event
Oct  3 19:50:48 localhost kernel: [6732712.553889] init: event_finished: Finished stopping event
Oct  3 19:50:48 localhost kernel: [6732712.553895] init: my-api state changed from stopping to killed
Oct  3 19:50:48 localhost kernel: [6732712.553935] init: Sending TERM signal to my-api main process (25787)
Oct  3 19:50:48 localhost kernel: [6732712.556636] init: my-api main process (25787) killed by TERM signal
Oct  3 19:50:48 localhost kernel: [6732712.556689] init: my-api state changed from killed to post-stop
Oct  3 19:50:48 localhost kernel: [6732712.556735] init: my-api state changed from post-stop to waiting
Oct  3 19:50:48 localhost kernel: [6732712.556768] init: event_new: Pending stopped event
Oct  3 19:50:48 localhost kernel: [6732712.556783] init: job_change_state: Destroyed inactive instance my-api
Oct  3 19:50:48 localhost kernel: [6732712.556837] init: Handling stopped event

Upstart 有respawn逻辑,我的服务自动启动,但我想知道为什么它会因TERM信号而停止。

如何追踪谁在停止这项服务?

当我运行命令时,exec $MY_API_PYTHON_HOME/script_api_virt/bin/python $MY_API_PYTHON_HOME/my_api.py它运行了 12 小时,没有任何错误。

相关内容