mirror of
				https://github.com/spantaleev/matrix-docker-ansible-deploy.git
				synced 2025-10-31 07:17:57 +01:00 
			
		
		
		
	also, worker.yaml.j2:
  - hone worker_name
  - remove worker_pid_file entry (would only be used if worker_daemonize
    set to true; also, synapse only knows about the container namespace
    and thus can not provide the required host-view PID)
		
	
		
			
				
	
	
		
			31 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
| #!/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
 |