【问题标题】:Bash script for Ghost blog not starting up on server rebootGhost博客的Bash脚本未在服务器重新启动时启动
【发布时间】:2013-12-12 14:44:25
【问题描述】:

我有一个非常简单的 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 有什么问题导致无法正常启动脚本?

【问题讨论】:

    标签: node.js bash crontab forever ghost-blog


    【解决方案1】:

    我运行: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")
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-20
        • 1970-01-01
        • 1970-01-01
        • 2013-09-11
        • 2019-08-23
        • 2021-03-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多