percona / mongodb_exporter

A Prometheus exporter for MongoDB including sharding, replication and storage engines
Apache License 2.0
1.17k stars 425 forks source link

mongodb_exporter service fails to start on Amazon linux #912

Open Eric-Tyrrell22 opened 5 days ago

Eric-Tyrrell22 commented 5 days ago

Describe the bug mongodb_exporter systemd service failing to start on
al2023-ami-2023.5.20240916.0-kernel-6.1-x86_64

To Reproduce

Expected behavior mongodb_exporter service starts

Logs

Sep 17 16:15:57 ip-172-31-31-213.ec2.internal systemd[1]: mongodb_exporter.service: Main process exited, code=exited, status=216/GROUP
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ An ExecStart= process belonging to unit mongodb_exporter.service has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 216.
Sep 17 16:15:57 ip-172-31-31-213.ec2.internal systemd[1]: mongodb_exporter.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ The unit mongodb_exporter.service has entered the 'failed' state with result 'exit-code'.
Sep 17 16:15:57 ip-172-31-31-213.ec2.internal systemd[1]: mongodb_exporter.service: Scheduled restart job, restart counter is at 5.

Environment

cat /etc/os-release

NAME="Amazon Linux"
VERSION="2023"
ID="amzn"
ID_LIKE="fedora"
VERSION_ID="2023"
PLATFORM_ID="platform:al2023"
PRETTY_NAME="Amazon Linux 2023.5.20240916"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2023"
HOME_URL="https://aws.amazon.com/linux/amazon-linux-2023/"
DOCUMENTATION_URL="https://docs.aws.amazon.com/linux/"
SUPPORT_URL="https://aws.amazon.com/premiumsupport/"
BUG_REPORT_URL="https://github.com/amazonlinux/amazon-linux-2023"
VENDOR_NAME="AWS"
VENDOR_URL="https://aws.amazon.com/"
SUPPORT_END="2028-03-15"

Additional context Issue has been ran into before: https://github.com/percona/mongodb_exporter/issues/815

I fixed this by changing the group in the service file to mongodb_exporter.

I'm not 100% sure if changing the group to mongodb_exporter would have security implications, but I have the feeling that it would be negligble at worst.

taking a look at the mongod service file, they specify the same user and group, for example. https://github.com/mongodb/mongo/blob/master/debian/mongod.service#L8-L9

This change can be made here: https://github.com/percona/mongodb_exporter/blob/main/.scripts/systemd/mongodb_exporter.service#L10

BupycHuk commented 5 days ago

Hello @Eric-Tyrrell22, have you passed options to service? could you replace $OPTIONS with flags you need.

Eric-Tyrrell22 commented 5 days ago

@BupycHuk I actually did replace the $OPTIONS with the flags I needed, but this issue was still present. It seems like not all operating systems have the group nogroup which is what's causing this issue. Amazon linux has nobody instead of nogroup

# Debian OS
$ cat /etc/group | grep no
nogroup:x:65534:

# Amazon linux
$ cat /etc/group | grep no
nobody:x:65534:

For reference this is the service file I'm using now.

[Unit]
Description=Prometheus MongoDB Exporter
Documentation=https://github.com/percona/mongodb_exporter
After=network.target

[Service]
Type=simple

User=mongodb_exporter
Group=mongodb_exporter

ExecStart=/usr/bin/mongodb_exporter --mongodb.uri="mongodb://localhost:27017/" --discovering-mode --collector.dbstats --collector.dbstatsfreestorage --collector.collstats

Restart=always

[Install]
WantedBy=multi-user.target