'Run mongodb replica as service
So currently I already have a mongodb replica set running with three instances. All three instances are running on the same server for now.
So the replica set is working fine if i'm starting it with the commands below.
sudo mongod --port 27017 --dbpath /var/lib/mongodb1 --replSet rs0 --bind_ip localhost,xxx.xxx.xxx.xxx
sudo mongod --port 27018 --dbpath /var/lib/mongodb2 --replSet rs0 --bind_ip localhost,xxx.xxx.xxx.xxx
sudo mongod --port 27019 --dbpath /var/lib/mongodb3 --replSet rs0 --bind_ip localhost,xxx.xxx.xxx.xxx
But as soon as I create a shell file with the exact same commands and try to start it with systemctl, the replica set wont even start.
Same problem when I start each instance as service.
[Unit]
Description=MongoDB Database Server 1
Documentation=https://docs.mongodb.org/manual
After=network-online.target
Wants=network-online.target
[Service]
User=username
Type=forking
EnvironmentFile=-/etc/default/mongod
ExecStart=/usr/bin/mongod --port 27017 --quiet --dbpath /var/lib/mongodb --replSet rs0 --fork --logpath /var/lib/mongodb/27017.log --bind_ip localhost,xxx.xxx.xxx.xxx
PIDFile=/run/mongod1.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
In both cases im always getting
about to fork child process, waiting until server is ready for connections.
forked process: 1909
child process started successfully, parent exiting
But than the process just disappears.
What am I doing wrong? Is there maybe a better way to start the mongo-instance?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
