Skip to content

Config and add PATH in supervisor

homepage-banner

TL; DR

Add the following line into supervisor config

environment=PATH="/PATH/TO/YOUR/bin"

Introduction

Supervisor is a popular process control system used in managing various types of processes. It is configured via a configuration file which contains a list of programs to be managed by supervisor. In this blog post, we will discuss how to add PATH in supervisor and configure it.

By default, when supervisord is launched in Linux, it inherits the system’s environment variables. Here, you can set other environment variables specific to the supervisord process. When supervisord launches a child process, the child process will copy the memory space content of the parent process, so any environment variables set here will also be inherited by the child process.

Configuring Supervisor

To configure supervisor, we need to create a configuration file. The configuration file contains a list of programs to be managed by supervisor. Each program has its own configuration.

To create a configuration file, we need to create a new file in the /etc/supervisor/conf.d directory. Let’s call our configuration file myprogram.conf.

Here is an example configuration file for a program named myprogram:

[program:myprogram]
command=/path/to/myprogram
autostart=true
autorestart=true
user=ubuntu

In this configuration file, we specify the command to run our program, whether to automatically start and restart the program if it fails, and the user that should run the program.

Adding PATH in Supervisor

Sometimes, we need to specify the PATH environment variable for our program to run properly. To add the PATH environment variable in supervisor, we need to specify it in our program’s configuration.

Let’s update our myprogram.conf configuration file to include a PATH environment variable:

[program:myprogram]
command=/path/to/myprogram
autostart=true
autorestart=true
user=ubuntu
environment=PATH="/usr/local/bin:/usr/bin:/bin"

In this configuration, we have added the environment parameter to our program’s configuration. The environment parameter specifies a list of environment variables that should be set when running our program. In this case, we have set the PATH environment variable to include /usr/local/bin, /usr/bin, and /bin.

Conclusion

Supervisor is a powerful process control system that can manage various types of processes. Configuring it is easy, and adding environment variables like PATH is just a matter of adding a few lines to your program’s configuration. Hopefully, this blog post has helped you understand how to configure supervisor and add PATH in supervisor for your program to run smoothly.

Feedback







Disclaimer
  • Welcome to visit the knowledge base of SRE and DevOps!
  • License under CC BY-NC 4.0
  • Made with Material for MkDocs and improve writing by generative AI tools
  • Copyright issue feedback me#imzye.com, replace # with @