Вопрос

I am using PM2 to keep Ghost (blogging platform) alive and I need a Cron Job to restart Ghost in the event of a server reboot. However, I am unsure of the proper code for the Cron Job.

I read that this is what I am to use:

@reboot /usr/local/bin/npm start /path/to/ghost/

but instead of using npm start should I replace it with pm2 start index.js which is what I use to start Ghost with PM2?

Note: I do not have root access and I cannot use pm2 startup. This is why I am using a Cron Job. Also this area is new to me; please provide examples.

Это было полезно?

Решение

Yes I would put the pm2 command in the cron job. To make sure pm2 starts your Ghost blog in the correct environment run the following command:

echo "export NODE_ENV=production" >> ~/.profile

and this is the command you will want to put in the cron job to start Ghost with pm2:

cd /path/to/ghost; pm2 start index.js --name ghost

You can checkout my article on pm2 here for some more details and options.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top