Bash script to create a replica set

You need to give the mongo service time to start up. Put some type of delay in the script, after starting the service. Also note that the mongo command as you have it will fail. You still need to run the rs.initiate(...) through --eval.

I have some questions:

  • What are you trying to accomplish with this script?
  • Why run an rs.initiate() via a shell script? You only need to do this once.
  • Why would you want to enable and start the service every time? Shouldn’t the service already be running since enable tells the service to start up after a system reboot?

Knowing what you’re trying to accomplish will allow us to give you more input into how you should go about doing what you’re trying to do. A script like this, as it stands now, doesn’t make a lot of sense to me.

1 Like