我有一个aaa.service
文件(控制 JBoss),除了其他常规内容之外,还包含
[Service]
Type=forking
ExecStart=/my/script start
ExecReload=/my/script restart
ExecStop=/my/script stop
PIDFile=...
/my/script start
创建 PID 文件并service aaa status
显示它发出一个奇怪的警告:
Supervising process xxx which is not our child. We'll most likely not notice when it exits.
完整输出:
Loaded: loaded (/etc/systemd/system/aaa.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2019-01-22 20:55:16 CET; 34min ago
Process: 32435 ExecStart=/my/script start (code=exited, status=0/SUCCESS)
Main PID: 32542
Tasks: 0 (limit: 512)
CGroup: /system.slice/aaa.service
Jan 22 20:54:56 I011-830 su[32447]: (to aaa) root on none
Jan 22 20:54:56 I011-830 su[32447]: pam_unix(su-l:session): session opened for user aaa by (uid=0)
Jan 22 20:55:16 I011-830 aaa[32435]: Starting JBoss application server: Starting JBoss application server:
Jan 22 20:55:16 I011-830 systemd[1]: aaa.service: Supervising process 32542 which is not our child. We'll most likely not notice when it exits.
现在我的实际问题是,如果进程被杀死,然后通过发出service aaa stop
,systemd 不会检测到它。它甚至声称它正在运行并且不想再次启动它:
# cat <pid-file>
No such file or directory
# service aaa status
Loaded: loaded (/etc/systemd/system/aaa.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2019-01-22 20:55:16 CET; 40min ago
Process: 32435 ExecStart=/konsens/app/aaa/init/aaastart (code=exited, status=0/SUCCESS)
Main PID: 32542
Tasks: 0 (limit: 512)
CGroup: /system.slice/aaa.service
...
# service aaa start
# <--- Instant return, no process started
我怎样才能实现以下目标?
- systemd 应该能够启动和停止我的服务
service aaa status
应该显示进程的状态,无论它是由 systemd 启动还是手动发出/my/service start
- systemd 应该能够在手动终止服务后启动服务
- systemd 应该能够停止我手动启动的服务
答案1
我怎样才能实现以下目标? 1 systemd 应该能够启动和停止我的服务
大多数发行版都具有向后兼容性,因此如果您不想创建本机服务,可以将服务存储在 /etc/init.d/ 中。
2 service aaa status 应显示进程的状态,无论它是由 systemd 启动还是手动发出 /my/service start
执行此操作的一种方法是在脚本中添加一个检查,以调用systemctl start aaa.service
是否一开始就没有以这种方式调用。陷阱可用于退出。
3 systemd 手动杀死后应该能够启动服务
由#2解决
4 systemd 应该能够停止我手动启动的服务
由#2解决