RedHatInsights / yggdrasil

GNU General Public License v3.0
21 stars 37 forks source link

Configurable worker environment variables #214

Closed subpop closed 7 months ago

subpop commented 7 months ago

This PR refactors the way processes are started, watched, killed, and restarted. The routines in exec.go were a mixture of higher-level worker process management (including restart delays, PID file management, etc.) and lower-level process start and kill routines. This PR moves the higher-level logic out of exec.go and into a file called worker.go. The routines in exec.go are now purely lower-level routines that start and stop processes; they have no awareness of worker configuration or process restart management (startProcess, stopProcess, waitProcess). The functions in worker.go operate on a workerConfig data structure to start, stop and manage workers.

A workerConfig structure is created by parsing an optional configuration file that must be defined in /etc/yggdrasil/workers. This configuration file, if present when a worker is started, is loaded. The 'env' field of the configuration file is parsed as a string slice. Elements of this slice must be in the form of a "VAR=VALUE" string, and are inserted into the worker process's environment before starting. It is forbidden to set PATH or any variable beginning with YGG_ in a worker's configuration file. Any variables by these names will be omitted when starting the worker process.

A worker's environment is automatically configured with a reasonable base PATH value (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin) and inherits values from its parent for: http_proxy, HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, and NO_PROXY.