对于 type=forking 的单元,systemd 状态更改为“正在停用(stop-sigterm)”

对于 type=forking 的单元,systemd 状态更改为“正在停用(stop-sigterm)”

我已经编写了一个 systemd 单元来在启动时启动我的应用程序:

cat [email protected]

[Unit]
Description=Start my application
After=local-fs.target network.target

[Service]
WorkingDirectory=/apps/scope
ExecStart=/apps/scope/scripts/startAtBoot.sh
Type=forking
PIDFile=/apps/scope/scripts/startAtBoot.pid
User=%i
#Group=
TimeoutSec=30min

[Install]
WantedBy=multi-user.target

cat /apps/scope/scripts/startAtBoot.sh

#!/bin/bash
#### Description: Startup applications at system reboot
#set -x

(. ~/.bash_profile && /apps/scope/scripts/envMaint.sh start >> /apps/scope/ca/profile-root/runtime/logs/envMaint-`date +\%m\%d`.log 2>&1)&
echo $! > /apps/scope/scripts/startAtBoot.pid

当我启动这项服务时:
[root@alvd17p01 ~]# systemctl start [email protected]

我可以看到父进程和子进程运行了一段时间。

[root@alvd17p01 ~]# systemctl status [email protected][email protected] - Start my application
   Loaded: loaded (/etc/systemd/system/[email protected]; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2017-08-24 19:12:28 EDT; 13s ago
   Process: 127914 ExecStart=/apps/scope/scripts/startAtBoot.sh (code=exited, status=0/SUCCESS)
   Main PID: 127915 (startAtBoot)
   CGroup: /system.slice/system-myproc.slice/[email protected]
           ├─127915 /bin/bash /apps/scope/scripts/startAtBoot.sh
           ├─127927 /bin/sh /apps/scope/scripts/envMaint.sh start
           ├─127951 /bin/sh ./start.sh
           ├─127952 /bin/sh ./scpp-ant.sh start
           ├─127953 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-2.b15.el7_3.x86_64/jre/bin/java -classpath ...
           └─127982 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-2.b15.el7_3.x86_64/bin/java -Dnop -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -XX:PermSize=64M -XX:MaxPermSize=512M -Xms1024...

但几分钟后,设备状态变为停用(stop-sigterm)

[root@alvd17p01 ~]# systemctl status [email protected][email protected] - Start my application
   Loaded: loaded (/etc/systemd/system/[email protected]; disabled; vendor preset: disabled)
   Active: deactivating (stop-sigterm) since Thu 2017-08-24 19:14:24 EDT; 2s ago
   Process: 127914 ExecStart=/apps/scope/scripts/startAtBoot.sh (code=exited, status=0/SUCCESS)
   Main PID: 127915 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/system-myproc.slice/[email protected]
           ├─128115 /bin/sh /3rdparty/swtools/jboss-eap-6.4.1/bin/standalone.sh -Dscpp.server.name=app -Djboss.server.base.dir=/apps/scope/app/profile-root/runtime/profile
           └─128247 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-2.b15.el7_3.x86_64/bin/java -D[Standalone] -server -XX:+UseCompressedOops -verbose:gc -Xloggc:/apps/scope/app/profile-root/runtime/logs/gc.log -XX...

[root@alvd17p01 ~]# systemctl status [email protected][email protected] - Start my application
   Loaded: loaded (/etc/systemd/system/[email protected]; disabled; vendor preset: disabled)
   Active: inactive (dead)

我不明白为什么它会失败。我的 envMaint.sh 以状态 0 退出。startAtBoot.pid 有子进程的 pid。

有人能帮我解决我做错的地方吗?

相关内容