systemd
对于使用 **systemd** 的 Linux 发行版(Ubuntu、Debian、Arch Linux),您可以通过以下方式创建守护进程。
首先,在 /etc/postgrest/config
中创建 postgrest 配置
db-uri = "postgres://<your_user>:<your_password>@localhost:5432/<your_db>"
db-schemas = "<your_exposed_schema>"
db-anon-role = "<your_anon_role>"
jwt-secret = "<your_secret>"
使用以下命令创建一个专用的 postgrest
用户
sudo useradd -M -U -d /nonexistent -s /usr/sbin/nologin postgrest
然后在 /etc/systemd/system/postgrest.service
中创建 systemd 服务文件
[Unit]
Description=REST API for any PostgreSQL database
After=postgresql.service
[Service]
User=postgrest
Group=postgrest
ExecStart=/bin/postgrest /etc/postgrest/config
ExecReload=/bin/kill -SIGUSR1 $MAINPID
[Install]
WantedBy=multi-user.target
之后,您可以启用服务在启动时自动运行,并使用以下命令启动它
systemctl enable postgrest
systemctl start postgrest
## For reloading the service
## systemctl restart postgrest
文件描述符
文件描述符是内核资源,用于 HTTP 连接(以及其他)。每个进程的文件描述符数量有限。内核默认限制为 1024,在某些 Linux 发行版中会增加。在流量繁忙的情况下,PostgREST 可能会达到此限制,并开始显示 No file descriptors available
错误。要清除这些错误,您可以增加进程的文件描述符限制。
[Service]
LimitNOFILE=10000