0

Mongodb 4.4 on centos 8 using official RPM repo.

I can start & use mongos from command line just fine: mongos --config /etc/mongos.conf

However, if I try to start mongos as systemd service, it give the error mongos.service: Failed with result 'timeout'. During the start process, I can connect to mongos and it is working until the start script error out.

the content of /etc/mongos.conf

sharding:
  configDB: rs_cfg/web05:27017

net:
  port: 27017
  bindIp: 0.0.0.0

The content of /etc/systemd/system/mongos.service. Basically I took /usr/lib/systemd/system/mongod.service and make minor modifications to produce mongos.service

[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network.target

[Service]
User=mongod
Group=mongod
Environment="OPTIONS=-f /etc/mongos.conf"
EnvironmentFile=-/etc/sysconfig/mongod
ExecStart=/usr/bin/mongos $OPTIONS
ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb
ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb
ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb
PermissionsStartOnly=true
PIDFile=/var/run/mongodb/mongos.pid
Type=forking
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for mongod as specified in
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings

[Install]
WantedBy=multi-user.target

journalctl -xe

systemd[1]: mongos.service: Start operation timed out. Terminating.
systemd[1]: mongos.service: Failed with result 'timeout'.

Checked all dir permissions, it just does not create the pid file /var/run/mongodb/mongos.pid.

What am I missing?

1 Answer 1

1

You set Type=forking but mongos is not configured to fork. You should reset this to its default, Type=simple. Alternatively you can add --fork to the mongos command line, but you will also need to specify --pidfile. The PID file is not required with Type=simple. Since you're using systemd it's best to just not fork and let systemd handle managing the process.

1
  • Thanks! You pointed me to the right direction. I copied the systemd script from mongod but did not config mongos to have the same fork/pid setting as mongod. It is working now.
    – Reed
    Aug 31, 2020 at 19:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .