You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.1 KiB

#!/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