Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable worker environment variables #214

Merged
merged 3 commits into from
Mar 21, 2024
Merged

Conversation

subpop
Copy link
Collaborator

@subpop subpop commented Mar 13, 2024

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.

@subpop subpop added enhancement New feature or request backport-yggdrasil-0.2 labels Mar 13, 2024
@subpop subpop requested a review from jirihnidek March 13, 2024 15:13
@subpop subpop force-pushed the worker-env-var branch 3 times, most recently from 0747a4b to e167e4c Compare March 13, 2024 15:32
Copy link
Contributor

@jirihnidek jirihnidek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it is good. I have several comments, questions, suggestions and only few requests.

cmd/yggd/exec.go Outdated Show resolved Hide resolved
cmd/yggd/exec.go Outdated Show resolved Hide resolved
cmd/yggd/exec.go Show resolved Hide resolved
cmd/yggd/exec_test.go Outdated Show resolved Hide resolved
cmd/yggd/exec_test.go Outdated Show resolved Hide resolved
cmd/yggd/worker.go Outdated Show resolved Hide resolved
cmd/yggd/worker.go Outdated Show resolved Hide resolved
cmd/yggd/worker.go Show resolved Hide resolved
cmd/yggd/worker.go Show resolved Hide resolved
cmd/yggd/worker.go Show resolved Hide resolved
subpop added 2 commits March 19, 2024 13:37
A worker may optionally install a configuration file into
/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.

HTTP proxy environment variables are automatically read from the yggd
environment and are passed into the worker environment automatically.

A sample echo worker config file has been added to demonstrate the new
env field.

Much of the code in exec.go was lifted into a new workers.go file.
exec.go now containers lower level routines for starting and stopping
processes. It has no awareness of the concept of a "worker". workers.go
has higher-level functions that use the startProcess and stopProcess
routines to start a worker process, create a PID file, wait for exit
status, restart and backoff restart delays, etc.

Signed-off-by: Link Dupont <[email protected]>
Clean up the worker validation logic slightly.

Signed-off-by: Link Dupont <[email protected]>
@subpop subpop requested a review from jirihnidek March 19, 2024 17:41
Copy link
Contributor

@jirihnidek jirihnidek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jirihnidek jirihnidek merged commit ef1e4b2 into yggdrasil-0.2 Mar 21, 2024
6 checks passed
@jirihnidek jirihnidek deleted the worker-env-var branch March 21, 2024 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants