bash - 使用 systemctl 作为服务运行时优雅退出 bash 脚本
问题描述
我已经在 call 中设置了一个/etc/systemd/system/
服务my_script.service
。之后我运行:
sudo systemctl daemon-reload
sudo systemctl start my_script.service
sudo systemctl stop my_script.service
我希望脚本优雅地“死去”。
当我从 CLI 运行脚本时,我有一个trap ctrl_c INT
函数在我按 ctrl+c 停止脚本时运行。
如何使用 systemctl 获得相同的功能?
解决方案
陷阱TERM
以及INT
。TERM
是 的非交互式模拟INT
;交互式按下Ctrl-C触发器INT
,而非交互式进程终止通常使用TERM
.
推荐阅读
- android - 更新到 Firebase Crashlytics SDK 后出现严重错误
- sql - SQL Query 根据 ID 将多行合并为一行,同时将其他值保留在同一行中?
- c++ - C++ 将 time_t 读入不同的时区,然后提取年/月....纳秒
- python - 使用熊猫在数据框中插入行
- python - Selenium for 循环在 2 个循环后停止
- python-3.x - 将罗马数字转换为国际系统的简单 Python 程序
- fortran - Fortran 中的 Project Euler 29 - 处理大整数
- asynchronous - F# AWS lambda - 部分异步函数永远不会执行
- swift - Swift多次运行http请求不起作用
- reactjs - reactjs中的useEffect和react路由器问题?