supervisor 管理一个由 shell 脚本启动的进程

supervisor manages a process which is started up with a shell script

我正在使用 supervisord 运行 容器中的多服务。我想为我的 Web 应用程序提供 ldap 服务。所以我使用以下信息安装并启动了 opendj,

Docker 文件

RUN dpkg -i $APP_HOME/packages/opendj_3.0.0-1_all.deb && \
    /opt/opendj/setup \
          --cli \
          --backendType je \
          --baseDN dc=test,dc=net \
          --ldapPort 389 \
          --adminConnectorPort 4444 \
          --rootUserDN cn=Directory\ Manager \
          --rootUserPassword 123456 \
          --no-prompt \
          --noPropertiesFile \
          --acceptLicense \
          --doNotStart

supervisord.conf

[program:ldap]
command=/opt/opendj/bin/start-ds
priority=1

当 运行使用我的自定义 imgae 时,我收到以下 ldap 退出消息。

2020-05-25 06:46:03,486 INFO exited: ldap (exit status 0; expected)

分别使用 supervisorctl status allps -aux 登录容器以获取所有进程状态信息。

$supervisorctl status all
ldap                             EXITED    May 25 06:46 AM
$ps -aux
root        97  3.4  5.9 3489048 240248 pts/0  Sl   06:15   0:08 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -server -Dorg.opends.server.scriptName=start-ds org.opends.server.core.DirectoryServer --configClass org.opends.server.extensions.ConfigFileHandler

我发现ldap程序是用start-dsshell脚本启动的,也就是start-dsshell进程退出了,但是的ldap服务器不受主管控制 是运行ning。 如果停止主管子进程,则无法正常停止 ldap 服务器。

所以我的问题是如何配置让主管控制由 start-ds 启动的 ldap 服务器进程。

在这种情况下,您应该使用 --nodetach 选项:https://github.com/ForgeRock/opendj-community-edition/blob/master/resource/bin/start-ds#L60

Reference Doc 说:

Options

The start-ds command takes the following options:

-N | --nodetach
Do not detach from the terminal and continue running in the foreground. This option cannot be used with the -t, --timeout option.

Default: false

start-ds.sh文件中的语句是:

exec "${OPENDJ_JAVA_BIN}" ${OPENDJ_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
  org.opends.server.core.DirectoryServer \
  --configClass org.opends.server.extensions.ConfigFileHandler \
  --configFile "${CONFIG_FILE}" "${@}"

start-ds 脚本将在 运行 /opt/opendj/bin/start-ds -N

时附加此选项
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -server -Dorg.opends.server.scriptName=start-ds org.opends.server.core.DirectoryServer --configClass org.opends.server.extensions.ConfigFileHandler --configFile /opt/opendj/config/config.ldif -N