El script Bash para el blog Ghost no se inicia al reiniciar el servidor
Frecuentes
Visto 493 veces
3
I have a very simple bash script which should launch my ghost blog. I am using crontab
to launch the script on startup, here is the crontab command I am running:
@reboot /var/www/ghost/launch.sh
El script tiene el siguiente código:
#!/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
Cuando sudo reboot
the server, and use forever list
to find the processes running, I see the following:
data: [0] sHyo /usr/bin/nodejs index.js 1299 1314 /home/webadmin/.forever/sHyo.log 0:0:1:25.957
Cuando nano
to that log file, the log says the following:
^[[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
It appears to be looking in /home/webadmin/
, but ghost is installed at /var/www/ghost
???
When I run the exact same script in the terminal manually after the sever has started up by ssh
-ing into the server, the script works fine. I run: cd /var/www/ghost/
y luego ./launch.sh
and the ghost blog appears and is working fine. The log for that forever
process says the following:
^[[32mGhost is running...^[[39m
Your blog is now available on http://blog.example.com ^[[90m
Ctrl+C to shut down^[[39m
What is wrong with my script or crontab that it cannot launch the script properly?
2 Respuestas
3
Corro:
cd /var/www/ghost/
y luego./launch.sh
and the ghost blog appears and is working fine.
That's the thing, your cron job is not doing the same:
@reboot /var/www/ghost/launch.sh
This script is executed from your home directory. One way to fix is to change your crontab:
@reboot cd /var/www/ghost; ./launch.sh
Another way is to add this line near the top of launch.sh
, anywhere before launching forever
:
# change to the directory of this script
cd $(dirname "$0")
respondido 27 nov., 13:06
1
Just an FYI for anybody that runs across this I would highly suggest looking into pm2 to start Ghost and to monitor Ghost. It will monitor Ghost like Forever and has a built in feature to generate a init script to start pm2 when your server restarts. Also has better features to monitor Ghost while it is running. Check out my how to aquí.
Respondido el 12 de diciembre de 13 a las 07:12
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas node.js bash crontab forever ghost-blog or haz tu propia pregunta.