MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / startCommand

Function startCommand

internal/collector/instance.go:182–223  ·  view source on GitHub ↗

startCommand generates the command script used by the collector container

(logDirectories []string, includeLogrotate bool)

Source from the content-addressed store, hash-verified

180
181// startCommand generates the command script used by the collector container
182func startCommand(logDirectories []string, includeLogrotate bool) []string {
183 var mkdirScript string
184 for _, logDir := range logDirectories {
185 mkdirScript += "\n" + shell.MakeDirectories(logDir, "receiver")
186 }
187
188 var logrotateCommand string
189 if includeLogrotate {
190 logrotateCommand = `logrotate -s /tmp/logrotate.status /etc/logrotate.d/logrotate.conf`
191 }
192
193 var startScript = fmt.Sprintf(`
194%s
195OTEL_PIDFILE=/tmp/otel.pid
196
197start_otel_collector() {
198 echo "Starting OTel Collector"
199 /otelcol-contrib --config %s/config.yaml &
200 echo $! > $OTEL_PIDFILE
201}
202start_otel_collector
203
204exec {fd}<> <(:||:)
205while read -r -t 5 -u "${fd}" ||:; do
206 %s
207 if [[ "${directory}" -nt "/proc/self/fd/${fd}" ]] && kill -HUP $(head -1 ${OTEL_PIDFILE?});
208 then
209 echo "OTel configuration changed..."
210 exec {fd}>&- && exec {fd}<> <(:||:)
211 stat --format='Loaded configuration dated %%y' "${directory}"
212 fi
213 if [[ ! -e /proc/$(head -1 ${OTEL_PIDFILE?}) ]] ; then
214 start_otel_collector
215 fi
216done
217`, mkdirScript, configDirectory, logrotateCommand)
218
219 wrapper := `monitor() {` + startScript +
220 `}; export directory="$1"; export -f monitor; exec -a "$0" bash -ceu monitor`
221
222 return []string{"bash", "-ceu", "--", wrapper, "collector", configDirectory}
223}

Callers 1

AddToPodFunction · 0.85

Calls 1

MakeDirectoriesFunction · 0.92

Tested by

no test coverage detected