0

while restarting the mongodb instance the directory mongodb in /var/run is deleting after restarting the instance the again i am creating the directory in /var/run and restarting the service whats the solution to it not to delete the directory after restarting the instance

  • which version of MongoDB , you are using? – Md Haidar Ali Khan Nov 18 '17 at 15:07
  • 1
    At normal system that directory is not removed automatically, you startup script must do it.. Why, I don't know. However, same way you can create it at the startup script. – JJussi Nov 18 '17 at 20:34
  • My version is 3.4.3 can you provide me a startup script for for scheduling the script – ashk Nov 20 '17 at 7:10
0

Here you can find startup/stop init.d script

Edit mongod -script file: PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/mongodb/mongodb-linux-x86_64-rhel70-3.4.3/bin/ PIDDIR=/var/run/mongod PIDFILE=$PIDDIR/$NAME.pid

In the mongod -script file add line mkdir -p $PIDDIR ; chown -R $PIDDIR before start-stop-daemon line (at star_server() section)

edit your /etc/mongod.conf file, so it have

systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log
processManagement:
  fork: true
  pidFilePath: /var/run/mongod/mongod.pid

start your mongodb with command sudo service mongod restart

  • Please tell me where should i add my requirement is i need to create a directory in /var/run as name mongodb and then to start the Mongodb service where shouid i add this service /mongodb/mongodb-linux-x86_64-rhel70-3.4.3/bin/mongod --config /etc/mongod.conf --fork --logpath /var/log/mongodb/mongod.log in the script – ashk Nov 21 '17 at 14:39
  • Put that script to /etc/init.d/ directory with name mongod, then fix those parameters (PATH, NAME, DAEMON, PIDFILE) to point right directories and names. Then service mongod start should bring everything up. If script don't create directory automatically, add to line 148 (before start-stop-daemon) line mkdir $PIDFILE – JJussi Nov 22 '17 at 6:25
  • mongodb/mongodb-linux-x86_64-rhel70-3.4.3/bin/mongod --config /etc/mongod.conf --fork --logpath /var/log/mongodb/mongod.log (I am starting this service manually at the time of starting the instance how can i enable this service automatically when i on the instance) – ashk Nov 23 '17 at 14:25
  • I extended my answer... – JJussi Nov 23 '17 at 20:00
  • After adding the script while starting the service as service mongod start it showing error as Could not find /usr/bin/mongod – ashk Dec 1 '17 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.