Run Hexo Server as a Daemon Service


Article Outline
Keywords: ,

This is the basic configuration for running a local hexo server as a service.

  • Create the following file,
1
$ sudo nano /etc/systemd/system/hexo.service
  • Add the following contents,
1
2
3
4
5
6
7
8
9
10
11
12
[Service]
WorkingDirectory=/home/<user>/<path-to-hexo-project>
ExecStart=/bin/hexo server
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=hexo
User=<user>
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target
  • Load the service and start it,
1
2
$ sudo systemctl daemon-reload
$ sudo systemctl start hexo
  • After a few moments, check the status of the service,
1
$ systemctl status hexo
  • If the hexo server service is running correctly, the last line of output should read,

INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.