Remove usage of pkill (fix #286)

pull/260/head
Varun Patil 2023-01-04 12:32:36 -08:00
parent f7bf45dc86
commit 6a0a3a370e
3 changed files with 19 additions and 3 deletions

View File

@ -234,7 +234,7 @@ class VideoController extends ApiBase
$env .= "FFMPEG='{$ffmpegPath}' FFPROBE='{$ffprobePath}' GOVOD_TEMPDIR='{$tmpPath}/go-vod' "; $env .= "FFMPEG='{$ffmpegPath}' FFPROBE='{$ffprobePath}' GOVOD_TEMPDIR='{$tmpPath}/go-vod' ";
// Check if already running // Check if already running
exec("pkill {$transcoder}"); \OCA\Memories\Util::pkill($transcoder);
shell_exec("{$env} nohup {$transcoder} > {$tmpPath}/go-vod.log 2>&1 & > /dev/null"); shell_exec("{$env} nohup {$transcoder} > {$tmpPath}/go-vod.log 2>&1 & > /dev/null");
// wait for 1s and try again // wait for 1s and try again

View File

@ -25,7 +25,7 @@ class Repair implements IRepairStep
public function run(IOutput $output): void public function run(IOutput $output): void
{ {
// kill any instances of go-transcode and go-vod // kill any instances of go-transcode and go-vod
shell_exec('pkill go-transcode'); \OCA\Memories\Util::pkill('go-transcode');
shell_exec('pkill go-vod'); \OCA\Memories\Util::pkill('go-vod');
} }
} }

View File

@ -141,4 +141,20 @@ class Util
return false; return false;
} }
/**
* Kill all instances of a process by name.
* Similar to pkill, which may not be available on all systems.
*/
public static function pkill(string $name): void
{
// get pids using ps as array
$pids = shell_exec("ps -ef | grep $name | grep -v grep | awk '{print $2}'");
$pids = array_filter(explode("\n", $pids));
// kill all pids
foreach ($pids as $pid) {
posix_kill((int) $pid, SIGKILL);
}
}
} }