How can I stop Supervisor processes ( a process control system ) from within a PHP script Supervisor is managing?

StackOverflow https://stackoverflow.com/questions/8795421

  •  15-04-2021
  •  | 
  •  

Question

I'm parallelizing a PHP script using Supervisor. When my script gets a certain response from the database, it executes a command to stop all the processes under control by the Supervisord daemon using supervisorctl. Here is the command:

// gracefully stop all processes in supervisor's group called processes
$cmd = 'sudo /usr/bin/supervisorctl stop processes:*';
exec( $cmd, $outputs );

The problem is that this command seems to have no affect when triggered from within a PHP script under Supervisor's control. Why?

If I start this group of processes running within Supervisor, and then trigger another instance of the script directly from the command line, it works and all the Supervisor processes are stopped.

What is going on? Can daemonized PHP scripts not exec() shell commands?

Was it helpful?

Solution

I checked Supervisor's log files and found the error message "sorry, you must have a tty to run sudo." From what I can figure, this is happening because Supervisor has daemonized my PHP scripts. Because of Linux security, I'm not allowed to invoke commands with sudo from within a daemonized process.

The solution was to run Supervisor as the current user, which is does by default, unless you execute it with the sudo command like I had been doing ( sudo /usr/bin/supervisord ). I was doing this because my scripts didn't have all the access they needed to run ( I guess I was lazy long ago when I set up my process ).

After fixing this, I could start Supervisor without using the sudo command ( /usr/bin/supervidord ), and then I didn't need to execute supervisorctl ( /usr/bin/supervisorctl ) with sudo to control it, thus solving the root problem of not being able to invoke sudo from a daeomonized process.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top