1
0
mirror of https://github.com/sendevia/website.git synced 2026-03-05 23:32:45 +08:00
Files
website/posts/设置开机自启动的 Jekyll 服务.md

1.3 KiB
Raw Permalink Blame History

title, description, color, impression, categories, tags, date
title description color impression categories tags date
设置开机自启动的 Jekyll 服务 通过 systemd 实现一个开机自启的 Jekyll 服务,通常来说,这对使用 Jekyll 作为服务后端的网站很有用。 #aa0c2b /assets/images/120678678_p0.webp
随笔
jekyll
2024-07-11T04:00:00Z

::: info 本文的目标是使用普通用户启动 Jekyll因此需要添加一行Environment来设置下环境变量,并且所有的操作都在这个普通用户的用户目录下进行。 :::

新建一个 systemd 服务

sudo nano /etc/systemd/system/jekyll.service
[Unit]
Description = Jekyll Service
After = syslog.target

[Service]
# 指定 GEM_HOME 的目录
Environment = GEM_HOME="/home/<user>/gems"
# Jekyll 网站的目录
WorkingDirectory = /home/<user>/<jekyll_site>
User = <user>
Type = simple
# 指定 bundle 所在目录并启动 Jekyll
ExecStart = /home/<user>/gems/bin/bundle exec jekyll serve --port 4000

Restart = always
StandardOutput = journal
StandardError = journal
SyslogIdentifier = jekyll

[Install]
WantedBy = multi-user.target

保存之后执行

sudo systemctl daemon-reload

启动自启服务并检查运行状况

sudo systemctl enable jekyll --now
sudo journalctl -u jekyll