I managed to start the service in 2 different ways
- Using normal command
root@ip-172-31-35-92:/#/usr/bin/mongod --config /etc/mongod_27018.conf &
- Using systemd service.
service mongod_27018 start
When either way I start the service a different PID is generate.
Problem statement
When I start service with command, I cannot stop using systemd service mongod_27018 stop
.
In order use systemctl start/stop/restart, I need to manually kill the process ID kill -9 $PID
Is there a way I can stop the service even though it is started from command ?
Unit file content
[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
ExecStart=/usr/bin/mongod --config /etc/mongod_27018.conf
PIDFile=/var/run/mongodb/mongod_27018.pid
LimitFSIZE=infinity
LimitCPU=infinity
LimitAS=infinity
LimitNOFILE=64000
LimitNPROC=64000
LimitMEMLOCK=infinity
TasksMax=infinity
TasksAccounting=false
[Install]
WantedBy=multi-user.target