跳转到内容

Systemd 服务

创建 /etc/systemd/system/rcommerce.service:

[Unit]
Description=rCommerce API Server
After=network.target postgresql.service
[Service]
Type=simple
User=rcommerce
Group=rcommerce
ExecStart=/usr/local/bin/rcommerce server -c /etc/rcommerce/config.toml
Restart=always
RestartSec=5
Environment=RUST_LOG=info
Environment=STOREFRONT_URL=https://your-store.com
[Install]
WantedBy=multi-user.target
Terminal window
# 创建用户
sudo useradd -r -s /bin/false rcommerce
# 设置权限
sudo chown rcommerce:rcommerce /usr/local/bin/rcommerce
sudo chown -R rcommerce:rcommerce /etc/rcommerce
# 启用并启动
sudo systemctl daemon-reload
sudo systemctl enable rcommerce
sudo systemctl start rcommerce
# 查看状态
sudo systemctl status rcommerce
Terminal window
# 实时日志
sudo journalctl -u rcommerce -f
# 最近 100 行
sudo journalctl -u rcommerce -n 100
Terminal window
sudo systemctl restart rcommerce

在 [Service] 段中设置:

  • RUST_LOG —— 日志级别
  • STOREFRONT_URL —— 邮件链接中的店面 URL
  • RCOMMERCE_CONFIG —— 配置文件路径(-c 参数的替代方式)