未分类
hexo博客开机自启动
vps机器重启后, hexo博客502了, 发现没有做开机自启动. npm用pm2做托管: 创建hexo-backrun.js:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[sean@rainingwalk hexo_run ]$ cat hexo-backrun.js var spawn = require('child_process').spawn; /* 其实就是等于执行hexo server --draft*/ free = spawn('hexo', ['server', '--draft']); free.stdout.on('data', function (data) { console.log('standard output:\n' + data); }); free.stderr.on('data', function (data) { console.log('standard error output:\n' + data); }); free.on('exit', function (code, signal) { console.log('child process eixt ,exit:' + code); }); |
创建pm2-config.json:
1 2 3 4 5 6 7 |
[sean@rainingwalk hexo_run ]$ cat pm2-config.json { "apps" : [{ "name" : "blog", "script" : "./hexo-backrun.js" }] } |
创建hexo.service:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
[sean@rainingwalk hexo_run ]$ cat /usr/lib/systemd/system/hexo.service [Unit] Description=PM2 process manager Documentation=https://pm2.keymetrics.io/ After=network.target [Service] User=sean LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity TimeoutStartSec=8 Environment=PATH=/usr/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin Environment=PM2_HOME=/home/sean/.pm2 Restart=always RestartSec=8 ExecStart=/usr/bin/pm2 start /data/blog/hexo_run/pm2-config.json --no-daemon ExecReload=/usr/bin/pm2 reload all ExecStop=/usr/bin/pm2 kill [Install] WantedBy=multi-user.target |
systemctl deamon-reload && systemctl start hexo && systemctl enable hexo