1.用pm2管理进程让 hexo 博客在服务器后台跑起来

1
npm install -g pm2

2.编写一个执行脚本 —— 在博客根目录下创建一个文件 run.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cd /usr/local/src/myblog

vim run.js

##添加如下内容:
const { exec } = require('child_process')
exec('hexo server -p 指定端口',(error, stdout, stderr) => {
if(error){
console.log('exec error: ${error}')
return
}
console.log('stdout: ${stdout}');
console.log('stderr: ${stderr}');
})

3,使用pm2运行脚本 run.js

1
2
cd /usr/local/src/myblog
指令: pm2 start run.js

运行起来后可以使用pm2 show + 进程pid查看后台hexo进行