postgresml / pgcat

PostgreSQL pooler with sharding, load balancing and failover support.
MIT License
3.13k stars 193 forks source link

Automatically start systemd service if config file is present #800

Closed MrSerth closed 2 months ago

MrSerth commented 2 months ago

Previously, upgrading the deb package stopped the service but didn't reenable it after a successful upgrade. This made upgrading the package more difficult and required a second step to restart the service. With this commit, the systemd service is automatically started when the default config file is present.

drdrsh commented 2 months ago

Thank you for the patch!

Can you share steps I can follow to reproduce the issue and verify that the patch works? Can these steps be replicated in a test or would it be too much work?

I don't use the deb package so I don't where to start :sweat_smile:

MrSerth commented 2 months ago

Sure!

My testing workflow might not be the best, but it is the same I used to test the package generation:

# Download current release and install it manually
wget https://apt.postgresml.org/pool/jammy/p/pg/pgcat-1.2.0-ubuntu22.04-amd64.deb
sudo dpkg -i pgcat-1.2.0-ubuntu22.04-amd64.deb

# Check systemd status
systemctl status pgcat # is likely `Active: inactive (dead)`

# Create the default config file manually
nano /ect/pgcat.toml
# Start the service
systemctl start pgcat

# Check service status
systemctl status pgcat # --> should be `Active: active (running)`

# "Fake" an update and install the official package a second time
sudo dpkg -i pgcat-1.2.0-ubuntu22.04-amd64.deb

# Check systemd status
systemctl status pgcat # is `Active: inactive (dead)` ☹️

# unpack deb, modify file, pack again
mkdir tmp
dpkg-deb -R pgcat-1.2.0-ubuntu22.04-amd64.deb tmp/
nano tmp/DEBIAN/postinst # apply changes!
dpkg-deb -b tmp fixed.deb

# Fake the update another time, install the fixed package
sudo dpkg -i fixed.deb

# Check systemd status
systemctl status pgcat # is `Active: active (running)` 🙂

Let me know if this worked for you.

AndrewJackson2020 commented 2 months ago

Thank you for the patch!

Can you share steps I can follow to reproduce the issue and verify that the patch works? Can these steps be replicated in a test or would it be too much work?

I don't use the deb package so I don't where to start 😅

Running systemd in a container is a very non trivial problem. Might be more trouble than it's worth to write an automated test for this.

MrSerth commented 2 months ago

Running systemd in a container is a very non trivial problem.

That’s true, indeed. Unfortunately, I don’t have any solution or recommendation here either.