安装pm2
npm install -g pm2
创建文件hexo_run.js
vi hexo_run.js
//run
const { exec } = require('child_process')
exec('hexo server',(error, stdout, stderr) => {
if(error){
console.log('exec error: ${error}')
return
}
console.log('stdout: ${stdout}');
console.log('stderr: ${stderr}');
})
后台运行
pm2 start hexo_run.js
其他脚本
pm2 start hexo_run.js -i max //启动 使用所有CPU核心的集群
pm2 stop hexo_run.js // 停止
pm2 stop all // 停止所有
pm2 restart hexo_run.js // 重启
pm2 restart all // 重启所有
pm2 delete hexo_run.js // 关闭
问题
如过没有全局化,做下面操作
cd /usr/local/nodejs/bin
ln -s /usr/local/nodejs/bin/pm2 /usr/bin/pm2
使用
hexo new your-title