3

我有一个非常简单的 bash 脚本,它应该可以启动我的 ghost 博客。我crontab用来在启动时启动脚本,这是我正在运行的 crontab 命令:

@reboot /var/www/ghost/launch.sh

该脚本具有以下代码:

#!/bin/sh

ps auxw | grep apache2 | grep -v grep > /dev/null

if [ $? != 0 ]
then
        NODE_ENV=production forever start --sourceDir /var/www/ghost index.js
fi

当我sudo reboot使用服务器并使用它forever list来查找正在运行的进程时,我看到以下内容:

data:    [0] sHyo /usr/bin/nodejs index.js 1299    1314 /home/webadmin/.forever/sHyo.log 0:0:1:25.957

当我nano查看该日志文件时,日志显示以下内容:

^[[31m
ERROR:^[[39m ^[[31mCould not locate a configuration file.^[[39m
^[[37m/home/webadmin^[[39m
^[[32mPlease check your deployment for config.js or config.example.js.^[[39m

Error: Could not locate a configuration file.
    at checkTemplate (/var/www/ghost/core/config-loader.js:16:36)
    at Object.cb [as oncomplete] (fs.js:168:19)

error: Forever detected script was killed by signal: null

它似乎正在查看/home/webadmin/,但 ghost 安装在/var/www/ghost????

ssh当我通过-ing 进入服务器启动服务器后手动在终端中运行完全相同的脚本时,该脚本工作正常。我运行:cd /var/www/ghost/然后./launch.sh幽灵博客出现并且工作正常。该forever过程的日志显示以下内容:

^[[32mGhost is running...^[[39m
Your blog is now available on http://blog.example.com ^[[90m
Ctrl+C to shut down^[[39m

我的脚本或 crontab 有什么问题无法正确启动脚本?

4

2 回答 2

3

我运行:cd /var/www/ghost/然后./launch.sh幽灵博客出现并且工作正常。

就是这样,你的 cron 工作并没有做同样的事情:

@reboot /var/www/ghost/launch.sh

此脚本从您的主目录执行。一种解决方法是更改​​您的 crontab:

@reboot cd /var/www/ghost; ./launch.sh

launch.sh另一种方法是在启动前的任何位置附近添加此行forever

# change to the directory of this script
cd $(dirname "$0")
于 2013-11-27T06:13:33.877 回答
1

对于遇到此问题的任何人来说,仅供参考,我强烈建议您查看 pm2 以启动 Ghost 并监控 Ghost。它将像 Forever 一样监视 Ghost,并具有内置功能,可以在服务器重新启动时生成一个 init 脚本来启动 pm2。还具有更好的功能,可以在运行时监控 Ghost。在这里查看我的方法。

于 2013-12-12T07:03:40.030 回答