2

When I use daemon service to start mongodb, MongoDB is always received kill signal by system(CentOS7.3) after about 2 minutes:

Log: [signalProcessingThread] got signal 15 (Terminated)

But when I run it Manually in shell: /data/mongo/bin/3.4/mongod -f /data/mongo/config/uxdb_27019.conf --fork , it runs ok.

My mongodb daemon service: /usr/lib/systemd/system/mongod.service

[Unit]
Description=mongodb
After=network.target·
After=syslog.target

[Service]|
Type=forking
User=mongo
ExecStart=/data/mongo/bin/3.4/mongod -f /data/mongo/config/uxdb_27019.conf
PrivateTmp=true
PIDFile=/data/mongo/pid/mongod_27019.pid
LimitFSIZE=infinity
LimitCPU=infinity
LimitAS=infinity
LimitNOFILE=32000
LimitNPROC=32000

[Install]
WantedBy=multi-user.target

Which process is terminate mongod service ?

2017-08-08T14:57:55.638+0800 I NETWORK  [conn12] received client metadata from 10.10.9.51:56714 conn12: { driver: { name: "mongo-java-driver", version: "3T_5.0.0-74-g1de6631-dirty" }, os: { type: "Windows", name: "Windows Server 2012 R2", architecture: "amd64", version: "6.3" }, platform: "Java/Oracle Corporation/1.8.0_121-b13" }
2017-08-08T14:59:14.169+0800 I CONTROL  [signalProcessingThread] got signal 15 (Terminated), will terminate after current cmd ends
2017-08-08T14:59:14.169+0800 I NETWORK  [signalProcessingThread] shutdown: going to close listening sockets...
3
  • Remove the --fork option. That should only be used on command line execution. Using systemd it "daemonizes" automatically, so you don't need the option.
    – Neil Lunn
    Aug 8, 2017 at 7:46
  • but when I Remove the --fork option, it also shutdown after 2 minutes
    – BlueSky
    Aug 8, 2017 at 7:50
  • You might also need to run mongod under an strace to track down where the kill signal is coming from. However the --fork option has no place here and should be removed. See stackoverflow.com/questions/4078089/… and general usages of strace google.com/search?q=centos+trace+sigterm
    – Neil Lunn
    Aug 8, 2017 at 7:54

2 Answers 2

3

Please check the valie of PIDFile in your mongod.service :

[Service]

... deleted ...

Type=forking

PIDFile=/data/mongo/pid/mongod_27019.pid

... deleted ...

Must have the same value with pidFilePath in /etc/mongod.conf:

processManagement:

fork: true
pidFilePath: /data/mongo/pid/mongod_27019.pid

Hope this can help your problem.

1
  • You saved my nighs! Thank you. That was the reason that systemd killed mongos, but I don't use Type=forking. Anyway PIDFile saved me.
    – Panoptik
    Mar 19, 2021 at 0:39
2

I resolved this by:

  1. Modify the daemon: mongod.service: from forking to oneshot

    [Service]
    Type=oneshot
    
  2. Modify config/Mongodb.conf: remark the follow line:

    #processManagement:
    #fork: true
    

But I don't know why, but it works well now.

1
  • Because your service was exiting after launching your process. Now it will wait until your process exits, and then the service will stop.
    – Josh M.
    Apr 7, 2020 at 22:14

You must log in to answer this question.

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