Laravel运行systemctl——用户使用进程



我正试图使用process(((来自Symfony\Component\process\process(在ubuntu服务器上运行一些服务

$process = new Process(['systemctl', '--user', 'start', $serviceName]);
try {
$process->mustRun();
} 
catch (ProcessFailedException $ex) {
Log::alert($ex->getMessage());
}

但我得到了以下错误:

The command "'systemctl' '--user' 'start' 'some_service_name.service'" failed.
Exit Code: 1(General error)
Working directory: /
Output:

Error Output:
Failed to connect to bus: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined (consider using --machine=<user>@.host --user to connect to bus of other user)

任何帮助都将不胜感激!

我想明白了,对于任何面临同样问题的人来说--机器=username@.host"不见了。

所以最终结果应该是这样的:

$process = new Process(['systemctl', '--machine=USER_HERE@.host', '--user', 'start', $serviceName]);
try {
$process->mustRun();
} 
catch (ProcessFailedException $ex) {
Log::alert($ex->getMessage());
}

(用您的用户替换USER_HERE(

相关内容

  • 没有找到相关文章

最新更新