我用workerman搭建了一個(gè)git的webhook,原來是在onMessage中直接exec自己寫的腳本,內(nèi)容為:
**#!/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**
一直運(yùn)行挺正常的。結(jié)果:
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搭建了其它服務(wù),所以我想用url的參數(shù)來讓workerman決定加載哪個(gè)類,這樣也方便在更改了文件之后reload。
大概是這樣:
onMessage = function() {
$app = Factory::create($app_name);
$app->run();
}
在那個(gè)app類的run中執(zhí)行上面的shell腳本,腳本內(nèi)容一致。但這種情況下會(huì)報(bào)錯(cuò):
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中執(zhí)行,又正常了。
請高手解決一下是什么原因?謝謝!
我已經(jīng)在php中將shell語句寫入了腳本文件。直接運(yùn)行就正常的。
將exec寫在onMessage()中也是正常的。但是exec語句寫在其它函數(shù)中就不能正常運(yùn)行。