1

I have multiple processes running in the background at Ubuntu with the help of supervisord

I want to stop each process running in supervisord by using the command below & adapted from the solution here

supervisorctl status | awk '{print $1}' | supervisorctl stop $1

I do not know how to get the process name (1st column) returned by supervisorctl status & pass it to supervisorctl stop command at the end of the pipe.

I could not use supervisorctl stop all due to some technical reasons.

So appreciate it if anyone could suggest how to stop all processes using supervisorctl status & pipe method.

hunterex
  • 565
  • 11
  • 27
  • 2
    `due to some technical reasons.` what "technical reasons"? Is this XY question? – KamilCuk Aug 04 '21 at 14:44
  • 1
    `for name in $(supervisorctl status | awk '{print $1}'); do supervisorctl stop "$name"; done`? – Renaud Pacalet Aug 04 '21 at 14:53
  • @KamilCuk, I am using `supervisord` with other tool - `dotMemory`, and the dotMemory tool does not behave correctly when I use `supervisord stop all` – hunterex Aug 04 '21 at 15:10
  • @RenaudPacalet, is `for` the only way to do it? or can it be done using pipe? – hunterex Aug 04 '21 at 15:13
  • @hunterex This depends on this `supervisorctl` command that I do not know. Can it read its parameter from the standard input? Do you need to do something special for this to work (e.g. use `-` instead of the parameter)? Depending on the answers to these questions something like `supervisorctl status | awk '{print $1}' | xargs supervisorctl stop` could work. – Renaud Pacalet Aug 04 '21 at 15:16
  • @RenaudPacalet, `supervisorctl status | awk '{print $1}' | xargs supervisorctl stop` works here. Would you like to use your comment as an answer? – hunterex Aug 04 '21 at 15:21
  • @hunterex OK, it might help others one day or another. – Renaud Pacalet Aug 04 '21 at 15:31

1 Answers1

1

If the supervisorctl stop command cannot read its parameter from the standard input the following should do what you want:

supervisorctl status | awk '{print $1}' | xargs supervisorctl stop

Explanation: xargs command converts its standard input to arguments of command and executes it.

Note: xargs has other benefits. It automatically splits the input in chunks of arguments such that the maximum total length of the command line is not exceeded. It can also parallelize several calls to its command (see the -P option).

Renaud Pacalet
  • 25,260
  • 3
  • 34
  • 51