Info
In the RPM spec the mongod service is (re)started upon an update, no matter if mongod service is running or not:
https://github.com/mongodb/mongo/blob/49d34008db892e6a89498ecdd68fcd26e1d7ffab/rpm/mongodb-org.spec#L284
With help of systemctl is-active this can be changed to restart only a running mongod service:
/usr/bin/systemctl is-active --quiet mongod && /usr/bin/systemctl restart mongod
Top User Comments
xgen-internal-githook commented on Tue, 6 Dec 2022 20:13:49 +0000:
Author:
{'name': 'Ryan Egesdahl', 'email': 'ryan.egesdahl@mongodb.com', 'username': 'deriamis'}
Message: SERVER-71380 Use `systemctl try-restart` during `postun`
Branch: master
https://github.com/mongodb/mongo/commit/6a8d2a5eb450093cadca0043b7de6925e093c5f5
ryan.egesdahl commented on Mon, 5 Dec 2022 19:11:30 +0000:
systemd also has a try-restart action, which is essentially the same as is-active followed by restart. Also, for the sake of parity, I'll make sure the same is happening in our Debian packages. Turns out we don't restart mongod during Debian package updates. That seems not great for a variety of reasons, but it's also not something I would like to just do without some thought and discussion first. I've opened SERVER-71852 to track that.
Steps to Reproduce
install mongod RPM
ensure the service is disabled and not started
update the mongod server RPM
observe that the mongod process is started, with the service still being disabled
This was tested on Amazon Linux 2, but should hold true on other distros using the RPM.