如何通过 runit 正确生成 postgresql 服务器

如何通过 runit 正确生成 postgresql 服务器

我正在尝试了解 Voidlinux,特别是 runit。 Void 的存储库中有 postgresql v9,我需要更新的东西,所以我从源代码编译了 v12。它工作正常,但现在我正在努力为它创建一个 runit 服务,我读了一些手册,用谷歌搜索了一下,这就是我想到的:

# /etc/sv/postgresql/run
#!/bin/sh
exec chpst -u postgres /usr/local/pgsql/bin/pg_ctl -D /var/lib/postgresql/data -l /var/lib/postgresql/logfile start 2>&1
# I've also tried postmaster command, which doesn't work even as standalone, whereas I'm able to launch the server by hand with the command above

我还尝试创建一个空目录/run/runit/supervise.postgresql并将其链接到/etc/sv/postgresql(以及没有它)

重新启动(或尝试手动启动服务)后,我得到输出:

waiting for server to start.... done
server started
pg_ctl: another server might be running; trying to start server anyway
waiting for server to start.... stopped waiting
pg_ctl: could not start server
Examine the log output.

然后最后 4 行无限循环地重复,没有结果。内容/var/lib/postgresql/logfile

2019-05-10 08:11:15.859 CEST [1138] FATAL:  lock file "postmaster.pid" already exists
2019-05-10 08:11:15.859 CEST [1138] HINT:  Is another postmaster (PID 760) running in data directory "/var/lib/postgresql/data"?
2019-05-10 08:11:16.964 CEST [1211] FATAL:  lock file "postmaster.pid" already exists
2019-05-10 08:11:16.964 CEST [1211] HINT:  Is another postmaster (PID 760) running in data directory "/var/lib/postgresql/data"?
2019-05-10 08:11:18.070 CEST [1215] FATAL:  lock file "postmaster.pid" already exists
2019-05-10 08:11:18.070 CEST [1215] HINT:  Is another postmaster (PID 760) running in data directory "/var/lib/postgresql/data"?

谢谢。

答案1

所以我最终解决了这个问题,这是给遇到同样问题的人的答案。这个错误实际上很愚蠢,但只有在我了解了日志记录如何在 void 中工作之后,我才注意到它,不知何故,只有 syslog (而不是 postgres 日志)确实显示了读取的错误SSL is not supported in this build,所以我开始以这种方式进行挖掘,最终意识到-l服务执行命令中的标志会强制使用 SSL,而我不需要。所以我最终使用的运行文件是:

# /etc/sv/postgresql/run:
#!/bin/sh
exec chpst -u postgres:postgres /usr/local/pgsql/bin/postgres -D '/var/lib/postgresql/data' 2>&1

/etc/sv/postgresql/log此外,通过创建一个文件夹并在其中创建一个包含以下内容的文件 ( )来启用该服务的日志记录/etc/sv/postgresql/log/run

#!/bin/sh
exec logger -p daemon.info -t postgres

还要安装一个 syslog 守护进程来实际存储日志(例如 socklog-void)

相关内容