Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set the PATH for supervisord so it finds the executables

I'm trying to setup supervisor.conf. One of my apps requires node.js, but node is not installed system wise. Also, because it needs to bind to port 80 it need to run as root. How can I modify the PATH variable so that supervisord can find the node executable (which is located in a directory) and run the node.js app.


I'm trying to do it like this

[supervisord]
environment=PATH=/path/to/where/node/executable/is

[program:web]
command=node web.js -c config.json

This fails with

2011-08-25 16:49:29,494 INFO spawnerr: can't find command 'node'
like image 432
Emil Ivanov Avatar asked Aug 25 '11 13:08

Emil Ivanov


People also ask

Where do I put Supervisord conf?

The per-program configuration files for Supervisor programs are located in the /etc/supervisor/conf. d directory, typically running one program per file and ending in . conf. We'll create a configuration file for this script, as`/etc/supervisor/conf.

How do I start a Supervisord process?

To start supervisord, run $BINDIR/supervisord. The resulting process will daemonize itself and detach from the terminal. It keeps an operations log at $CWD/supervisor. log by default.

What user does Supervisord run as?

To be able to run any subprocess as a different user from what supervisord is running as, you must run supervisord as root. It tells you if you run multiple subprocesses, you have to run as a root to be able to start all the subprocesses, meaning that if you have more than 2 projects in you supervisord.

Where is Supervisorctl?

Normally the default file is indeed /etc/supervisor. conf , but the Debian distribution patches this (link to the gzipped patch as provided by Debian) to look for /etc/supervisor/supervisor.


2 Answers

You can add it in the command using env:

[program:web]
command=env PATH="/path/to/where/node/executable/is" node web.js -c config.json

It seems environment does not work on some cases.

like image 53
zenbeni Avatar answered Sep 23 '22 23:09

zenbeni


A pattern I've started using with supervisor (which is similar to zenbeni's) is to use a shell script to start whichever program I'm running which allows setup of environment variables etc.

e.g.

#!/bin/sh
export EXAMPLE_VARIABLE=something
export PYTHONPATH=/something
export PATH=$PATH:/somewhere/else
exec python somescript.py

The use of 'exec' is important. It replaces /bin/sh with the program being executed instead of spawning it as a child. This means that there aren't any additional processes around, and also signals work as expected.

The (small) advantage of this over zenbeni's method is that when updating environment variables etc it only takes a supervisor restart, i.e. no reread/update etc is required. This advantage gets bigger when using an event listener if you hit the same bug I did (full restart of supervisor to update event listener environment variables).

like image 39
Sam Jacobson Avatar answered Sep 22 '22 23:09

Sam Jacobson