Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Supervisord- Execute a command before starting the application / program

Tags:

supervisord

Using supervisord, how do I execute a command before running the program?

For example in the code below, I want a file to be created before starting the program. In the code below I am using tail -f /dev/null to simulate the background process but this could be any running program like '/path/to/application'. I tried '&&' and this doesn't seem to work. The requirement is that the file has to be created first in order for the application to work.

[supervisord]
nodaemon=true
logfile=~/supervisord.log

[program:app]
command:touch ~a.c && tail -f /dev/null
like image 746
Nagendra Kakarla Avatar asked Feb 07 '23 12:02

Nagendra Kakarla


1 Answers

The problem is that supervisor isn't running a shell to interpret command sections, so "&&" is just one of 5 space separated arguments it is passing to the touch command; if this ran successfully, then there should be some unusual filenames in its working directory now.

You can use a shell as your command and pass it the shell logic you would like:

command=/bin/sh -c "touch ~a.c && tail -f /dev/null"

Usually, this type of shell wrapper should be the interface provided and managed by the app and is what supervisord and others just know how to call with paths and options, i.e.:

command=myappswrapper.sh ~a.c 
(where myappswrapper.sh is:)
#!/bin/sh
touch $1 && tail -f /dev/null
like image 195
lossleader Avatar answered Apr 25 '23 09:04

lossleader