Linux后台运行hexo

hexo是一个非常高效的博客,但由于其设计特点,目的是为了转换为静态页面,因此不必要一直在后台运行,但是我想随时随地写博客同步到github

,使用hexo admin编辑器,这就需要hexo一直在后台运行,于是在网上找到了pm2托管的方式。

首先安装pm2

1
$ npm  install -g pm2

第二步,写一个运行脚本,在博客根目录下面创建一个hexo_run.js

1
2
3
4
5
6
7
8
9
10
//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}');
})

第三步,cd到博客根目录下运行脚本

1
# pm2 start hexo_run.js

参考文献

让hexo一直在后台运行


Linux后台运行hexo
https://www.frytea.com/post/20190221232200.html
作者
Tianlun Song
发布于
2019年2月21日
更新于
2024年6月10日
许可协议