0

I'm developping a PHP-FPM driven module in which in upload videos, then transcode them into several HTML5 formats in the background with ffmpeg. This PHP-FPM script runs under a specific, non-root UID, called tv25.

There is a variant in which I record a webcam stream through a Streaming Server (Wowza), which runs under the root UID, and launches the conversion through Java-written module.

In order to know the status of the processes I make a GET request to a script which runs the following function :

function is_conversion_running($base_file_name) {
  $command = "sudo ps aux | grep {$base_file_name} | grep -v grep | wc -l";
  $lignes  = shell_exec($command);
  return (bool) $lignes;
}

When I call this function through AJAX, it works for the PHP-FPM variant (the UID is the same, returns true while the conversion is running), but not with the Wowza variant (return false everytime).

The strange thing is that if I run the command in a shell, with the non-root UID, it works like a charm, since the ps command as been allowed to be run by this UID.

The problem seems similar to the one in shell_exec returns empty string, but the solution listed there doesn't work for me.

My /etc/sudoers line is like this :

tv25  ALL = (root)  NOPASSWD: /bin/ps

Really can't figure out what is the deal...

Community
  • 1
  • 1
jpicaude
  • 356
  • 2
  • 8

2 Answers2

0

What does the command return: 0 or NULL? In the second case the command probably failed alltogether. You can check with the exec function whether you get a non-zero exit code. Make sure to prefix your command with /bin/sh -c in that case.

PS: Do you really need the sudo for running ps? Normally you get all processes even without sudo.

Kris
  • 21
  • 4
  • The command returns 1. I had to sudo ps because if not, the process launched as root would not appear. – jpicaude Jun 14 '14 at 08:54
0

Well I found another way to sikve my problem : since I want to know if the process is still running, I delegated the command in a shell script :

#!/bin/bash

BASE_NAME=`basename $0`
LIGNES=$(/usr/bin/sudo /bin/ps aux | grep "$1" | grep -v grep | grep -v $BASE_NAME | wc -l)

[ $LIGNES -eq "0" ] && exit 1
exit 0

And then I call it with passthru. Its return value parameter is then converted to boolean, negated, and returned by the function.

~

jpicaude
  • 356
  • 2
  • 8