mirror of
https://github.com/spantaleev/matrix-docker-ansible-deploy.git
synced 2024-11-07 16:12:43 +00:00
31 lines
1.1 KiB
Plaintext
31 lines
1.1 KiB
Plaintext
|
#!/bin/bash
|
||
|
# Find a synapse worker's PID and write it to a file so systemd can manage it as a service
|
||
|
|
||
|
# example invocation:
|
||
|
# matrix-synapse-worker-write-pid user_dir:18700 /run/matrix-synapse-worker.user_dir:18700.pid
|
||
|
|
||
|
docker_api_call() { curl --silent --unix-socket /var/run/docker.sock ${@}; }
|
||
|
|
||
|
TARGETCONTAINER=matrix-synapse
|
||
|
TARGETWORKER=${1}
|
||
|
PIDFILE=${2}
|
||
|
|
||
|
# get ID list of subprocesses executed in $TARGETCONTAINER, and for each..
|
||
|
for EXECID in $(docker_api_call http://localhost/containers/${TARGETCONTAINER}/json | jq --raw-output '.ExecIDs[]')
|
||
|
do
|
||
|
# fetch detailed process info
|
||
|
EXECINFO=$(docker_api_call http://localhost/exec/${EXECID}/json)
|
||
|
|
||
|
# extract config file path from last command argument
|
||
|
WORKERCONFIGFILE=$(echo ${EXECINFO} | jq --raw-output .ProcessConfig.arguments[-1])
|
||
|
|
||
|
# reconstruct worker name
|
||
|
WORKERNAME=${WORKERCONFIGFILE#*/worker.}
|
||
|
WORKERNAME=${WORKERNAME%.yaml}
|
||
|
|
||
|
# if name matches the target worker: write out most recent PID & quit
|
||
|
[ "${WORKERNAME}" = "${TARGETWORKER}" ] \
|
||
|
&& echo ${EXECINFO} | jq --raw-output .Pid > ${PIDFILE} \
|
||
|
&& exit 0
|
||
|
done
|