I am trying to launch mongod with my own configuration from systemd, but it does not work. And I do not understand why. Any help by some more experienced person would be very welcome.
This is what I can say to start with:
1) When started outside of systemd, using the mongod command, the configuration works with no issue.
2) When I use systemd with the default configuration instead of mine, it also works with no issue.
This is the report provided by “systemctl status”, when using my own configuration:
root@ubuntu:/home/ubuntu# systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Thu 2020-12-17 03:43:33 UTC; 15min ago
Docs: https://docs.mongodb.org/manual
Process: 1816 ExecStart=/usr/bin/mongod --config /home/ubuntu/mongo-1.cfg (code=exited, status=0/SUCCESS)
Main PID: 1816 (code=exited, status=0/SUCCESS)
Dec 17 03:43:10 ubuntu systemd[1]: Started MongoDB Database Server.
Dec 17 03:43:18 ubuntu mongod[1816]: about to fork child process, waiting until server is ready for connections.
Dec 17 03:43:18 ubuntu mongod[1982]: forked process: 1982
Dec 17 03:43:24 ubuntu mongod[1816]: child process started successfully, parent exiting
Dec 17 03:43:33 ubuntu systemd[1]: mongod.service: Succeeded.
root@ubuntu:/home/ubuntu#
Here is the content of the config file:
ubuntu@ubuntu:~$ cat mongo-1.cfg
storage:
dbPath: /mnt/mongoDB-One/DB_Data_1st
journal:
enabled: true
net:
bindIp: localhost,192.168.1.2
port: 22330
systemLog:
destination: file
path: /mnt/mongoDB-One/DB_Data_1st/mongod.log
logAppend: true
processManagement:
fork: true
replication:
replSetName: mngoRepSet
ubuntu@ubuntu:~$
Here is the end of the server log file:
root@ubuntu:/home/ubuntu# tail -20 /mnt/mongoDB-One/DB_Data_1st/mongod.log
{"t":{"$date":"2020-12-17T03:43:25.146+00:00"},"s":"I", "c":"FTDC", "id":20626, "ctx":"SignalHandler","msg":"Shutting down full-time diagnostic data capture"}
{"t":{"$date":"2020-12-17T03:43:25.160+00:00"},"s":"I", "c":"STORAGE", "id":4784927, "ctx":"SignalHandler","msg":"Shutting down the HealthLog"}
{"t":{"$date":"2020-12-17T03:43:25.160+00:00"},"s":"I", "c":"STORAGE", "id":4784929, "ctx":"SignalHandler","msg":"Acquiring the global lock for shutdown"}
{"t":{"$date":"2020-12-17T03:43:25.160+00:00"},"s":"I", "c":"STORAGE", "id":4784930, "ctx":"SignalHandler","msg":"Shutting down the storage engine"}
{"t":{"$date":"2020-12-17T03:43:25.160+00:00"},"s":"I", "c":"STORAGE", "id":20282, "ctx":"SignalHandler","msg":"Deregistering all the collections"}
{"t":{"$date":"2020-12-17T03:43:25.161+00:00"},"s":"I", "c":"STORAGE", "id":22372, "ctx":"OplogVisibilityThread","msg":"Oplog visibility thread shutting down."}
{"t":{"$date":"2020-12-17T03:43:25.161+00:00"},"s":"I", "c":"STORAGE", "id":22261, "ctx":"SignalHandler","msg":"Timestamp monitor shutting down"}
{"t":{"$date":"2020-12-17T03:43:25.162+00:00"},"s":"I", "c":"STORAGE", "id":22317, "ctx":"SignalHandler","msg":"WiredTigerKVEngine shutting down"}
{"t":{"$date":"2020-12-17T03:43:25.163+00:00"},"s":"I", "c":"STORAGE", "id":22318, "ctx":"SignalHandler","msg":"Shutting down session sweeper thread"}
{"t":{"$date":"2020-12-17T03:43:25.164+00:00"},"s":"I", "c":"STORAGE", "id":22319, "ctx":"SignalHandler","msg":"Finished shutting down session sweeper thread"}
{"t":{"$date":"2020-12-17T03:43:25.164+00:00"},"s":"I", "c":"STORAGE", "id":22320, "ctx":"SignalHandler","msg":"Shutting down journal flusher thread"}
{"t":{"$date":"2020-12-17T03:43:25.164+00:00"},"s":"I", "c":"STORAGE", "id":22321, "ctx":"SignalHandler","msg":"Finished shutting down journal flusher thread"}
{"t":{"$date":"2020-12-17T03:43:25.164+00:00"},"s":"I", "c":"STORAGE", "id":22322, "ctx":"SignalHandler","msg":"Shutting down checkpoint thread"}
{"t":{"$date":"2020-12-17T03:43:25.164+00:00"},"s":"I", "c":"STORAGE", "id":22323, "ctx":"SignalHandler","msg":"Finished shutting down checkpoint thread"}
{"t":{"$date":"2020-12-17T03:43:25.164+00:00"},"s":"I", "c":"STORAGE", "id":4795902, "ctx":"SignalHandler","msg":"Closing WiredTiger","attr":{"closeConfig":"leak_memory=true,"}}
{"t":{"$date":"2020-12-17T03:43:33.802+00:00"},"s":"I", "c":"STORAGE", "id":4795901, "ctx":"SignalHandler","msg":"WiredTiger closed","attr":{"durationMillis":8638}}
{"t":{"$date":"2020-12-17T03:43:33.802+00:00"},"s":"I", "c":"STORAGE", "id":22279, "ctx":"SignalHandler","msg":"shutdown: removing fs lock..."}
{"t":{"$date":"2020-12-17T03:43:33.803+00:00"},"s":"I", "c":"-", "id":4784931, "ctx":"SignalHandler","msg":"Dropping the scope cache for shutdown"}
{"t":{"$date":"2020-12-17T03:43:33.803+00:00"},"s":"I", "c":"CONTROL", "id":20565, "ctx":"SignalHandler","msg":"Now exiting"}
{"t":{"$date":"2020-12-17T03:43:33.803+00:00"},"s":"I", "c":"CONTROL", "id":23138, "ctx":"SignalHandler","msg":"Shutting down","attr":{"exitCode":0}}
root@ubuntu:/home/ubuntu#
This is the content of the mongod.service file:
root@ubuntu:/home/ubuntu# cat /lib/systemd/system/mongod.service
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network-online.target
Wants=network-online.target
[Service]
User=mongodb
Group=mongodb
EnvironmentFile=-/etc/default/mongod
#(Commented out by me)ExecStart=/usr/bin/mongod --config /etc/mongod.conf
ExecStart=/usr/bin/mongod --config /home/ubuntu/mongo-1.cfg
PIDFile=/var/run/mongodb/mongod.pid
# 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
root@ubuntu:/home/ubuntu#