postgrest-docs icon indicating copy to clipboard operation
postgrest-docs copied to clipboard

[Feature Request] systemd scripts

Open geepie opened this issue 4 years ago • 3 comments

Please find below the systemd scripts I use on Debian. PostgREST executable is in /usr/bin/postgrest Multiples configuration files are /etc/postgrest/xxx.conf Note: must take care to use a different port in each config file.

I test the following commands:

systemctl enable postgrest
systemctl disable postgrest
systemctl stop postgrest
systemctl start postgrest
systemctl enable postgrest@xxx
systemctl disable postgrest@xxx
systemctl stop postgrest@xxx
systemctl start postgrest@xxx

/etc/systemd/system/postgrest.service

[Unit]
Description=REST API for Postgres database
After=postgresql.service

[Service]
Type=oneshot
ExecStart=/bin/true
ExecReload=/bin/true
RemainAfterExit=on

[Install]
WantedBy=multi-user.target

/etc/systemd/system/[email protected]

[Unit]
Description=REST API for Postgres database %i
AssertPathExists=/etc/postgrest/%i.conf
PartOf=postgrest.service
ReloadPropagatedFrom=postgrest.service
Before=postgrest.service

[Service]
ExecStart=/usr/bin/postgrest /etc/postgrest/%i.conf
ExecReload=/bin/kill -SIGUSR1 $MAINPID
Restart=on-failure

[Install]
WantedBy=postgrest.service

geepie avatar Jan 17 '21 14:01 geepie

Hey @geepie, thanks for sharing!

We do have a systemd section on: https://postgrest.org/en/v7.0.0/admin.html#daemonizing.

Perhaps we can include your recommendations there.

(I'll transfer the issue to our docs repo).

steve-chavez avatar Jan 19 '21 18:01 steve-chavez

@geepie Could you elaborate how postgrest.service and [email protected] work?

systemctl start postgrest@xxx AssertPathExists=/etc/postgrest/%i.conf

Does %i gets replaced by xxx?

steve-chavez avatar Jan 19 '21 18:01 steve-chavez

Let's expand on this in the docs. It would be difficult to provide any scripts that apply across distros. @geepie, any additonal background that you can provide on your scripts?

monacoremo avatar Apr 07 '21 08:04 monacoremo