Skip to content

Commit c14c54c

Browse files
authored
Make mongodb_exporter user creation idempotent in postinst script
The previous postinst script unconditionally ran `useradd` to create the `mongodb_exporter` system user. That would fail if the user already existed (e.g., during package upgrade), breaking the post-install process.
1 parent cbb753f commit c14c54c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

.scripts/postinst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
set -e
44

5-
echo "Creating user and group..."
6-
7-
useradd --system \
5+
# creating mongodb_exporter user if he isn't already there
6+
if ! getent passwd mongodb_exporter >/dev/null; then
7+
useradd \
8+
--system \
89
--no-create-home \
910
--shell /sbin/nologin \
1011
--comment "MongoDB Exporter" \
11-
mongodb_exporter
12+
mongodb_exporter >/dev/null
13+
fi
1214

1315
systemctl daemon-reload > dev/null || exit $?
1416

0 commit comments

Comments
 (0)