在workerman中exec的奇怪问题

thy38

我用workerman搭建了一个git的webhook,原来是在onMessage中直接exec自己写的脚本,内容为:

**#!/bin/bash
cd /website
git reset --hard HEAD
git clean -f
git pull origin dev
git checkout dev
if ; then composer update; fi
if ; then cnpm update; fi
if ; then gulp dev; fi**

一直运行挺正常的。结果:

 Array
(
     => HEAD is now at 1c3c1b0
     => Total 4 (delta 2), reused 4 (delta 2)
     => From 
     =>  * branch            dev        -> FETCH_HEAD
     => Updating 1c3c1b0..3acf4b8
     => Fast-forward
     =>  test.php | 47 ++++++++++++++++++++++++++++++++++-------------
     =>  1 file changed, 34 insertions(+), 13 deletions(-)
     => Already on 'dev'
     => Your branch is ahead of 'origin/dev' by 31 commits.
     =>   (use "git push" to publish your local commits)
     => Running composer as root/super user is highly discouraged as packages, plugins and scripts cannot always be trusted
     => Loading composer repositories with package information
     => Updating dependencies (including require-dev)
     => Nothing to install or update
     => Generating autoload files
)

最近又想用workerman搭建了其它服务,所以我想用url的参数来让workerman决定加载哪个类,这样也方便在更改了文件之后reload。
大概是这样:

onMessage = function() {
    $app = Factory::create($app_name);
    $app->run();
}

在那个app类的run中执行上面的shell脚本,脚本内容一致。但这种情况下会报错:

 Array
(
     => HEAD is now at 1be625e
     => From 
     =>  * branch            dev        -> FETCH_HEAD
     => Already up-to-date.
     => Already on 'dev'
     => Your branch is ahead of 'origin/dev' by 156 commits.
     =>   (use "git push" to publish your local commits)
     =>
     =>
     =>   
     =>   The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly
     =>
     =>
     => /mnt/service/log/git-website.sh: line 8: cnpm: command not found
     => /mnt/service/log/git-website.sh: line 9: gulp: command not found
)

我又试着把exec语句放到onMessage中执行,又正常了。

请高手解决一下是什么原因?谢谢!

3740 2 0
2个回答

latin

目测不是workerman问题,弄个脚本试下?

  • 暂无评论
thy38

我已经在php中将shell语句写入了脚本文件。直接运行就正常的。
将exec写在onMessage()中也是正常的。但是exec语句写在其它函数中就不能正常运行。

  • 暂无评论
年代过于久远,无法发表回答
×
🔝