【发布时间】:2016-07-15 21:09:18
【问题描述】:
我有一个应用程序在完成并正常退出后不应重新启动。在此应用程序完成其业务后,我想关闭实例(ec2)。我正在考虑使用带有选项的 systemd 单元文件来执行此操作
Restart=on-failure
ExecStopPost=/path/to/script.sh
应该在ExecStopPost 上运行的脚本:
#!/usr/bin/env bash
# sleep 1; adding sleep didn't help
# this always comes out deactivating
service_status=$(systemctl is-failed app-importer)
# could also do the other way round and check for failed
if [ $service_status = "inactive" ]
then
echo "Service exited normally: $service_status . Shutting down..."
#shutdown -t 5
else
echo "Service did not exit normally - $service_status"
fi
exit 0
问题是,当 post stop 运行时,我似乎无法检测到服务是否正常结束,然后状态为deactivating,只有在我知道它是否进入failed 状态之后。
【问题讨论】: