PostgREST / postgrest-docs

This repo is archived and will be merged into postgrest/postgrest soon.
http://postgrest.org
MIT License
365 stars 164 forks source link

[Feature Request] systemd scripts #386

Open geepie opened 3 years ago

geepie commented 3 years ago

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/postgrest@.service

[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
steve-chavez commented 3 years ago

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 commented 3 years ago

@geepie Could you elaborate how postgrest.service and postgrest@.service work?

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

Does %i gets replaced by xxx?

monacoremo commented 3 years ago

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?