Skip to content

Instantly share code, notes, and snippets.

@guiwuff
Created March 30, 2025 10:43
Show Gist options
  • Select an option

  • Save guiwuff/7681fcdf358182a96a25fafffed37354 to your computer and use it in GitHub Desktop.

Select an option

Save guiwuff/7681fcdf358182a96a25fafffed37354 to your computer and use it in GitHub Desktop.
Supervisor Process with environment variable file loaded
#!/bin/bash
ENV_FILE="$1"
CMD=${@:2}
set -o allexport
source $ENV_FILE
set +o allexport
$CMD

Supervisord command with env variables from a specific file loaded

With program:xxx defined in /etc/supervisord/confd/xxx.conf

[program:xxx]
process_name=%(program_name)s
directory=/home/xx/xxx/
command=/home/xx/xxx/runenv.sh .env /home/xx/xxx/xxx arg1 arg2 ..etc
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=xx
numprocs=1
redirect_stderr=true
stdout_logfile=/home/xx/xxx/logs/xx.supervisor.log
stopwaitsecs=3600

It load the application from a executable sh script which basically loads variables from .env file to the user space environment before executes the program itself. Check the shell script, and you need to make it executable chmod +x runenv.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment