Install and Replace mongodb pkg

I’m new to mongodb administration and Linux. I have been tasked with upgrading replica sets on EC2 (Ubuntu) from 3.6 to 4.0. Reading through some instructions and demos online I have questions about the steps I should take:

  1. shutdown the mongo instance on the secondary member
  2. download and install 4.0 binary
  3. start the mongo instance on the secondary member

what happens when I run apt-get install for mongo 4.0 while 3.6 is running?
do I need to move the 4.0 binaries to a different dir than where 3.6 binaries are located?
some posts mention ‘replacing’ the 3.6 pkg with the 4.0 pkg - does that mean overwriting?

my plan was to create a new dir and download the 4.0 pkg there. then cd into that dir and start the mongo service for the replica set member using the existing conf file. will that work or cause an issue with the existing 3.6 pkg?

1 Like

The steps are all in the upgrade guide.

The binaries are updated and the systemctl is called with daemon-reload. The existing version will continue to run. But if you are following the upgrade guide the server is shut down first.

No. The package manager will install the new files over the old.

Yes

Follow the upgrade guide.

2 Likes

The binaries are updated and the systemctl is called with daemon-reload. The existing version will continue to run. But if you are following the upgrade guide the server is shut down first.

This is the part that confuses me in the rolling upgrade guide. I have three instances running on localhost:27017, localhost:27018, and localhost:27019
I connect to the instance on localhost:27019 and run db.shutdownServer()
Then I run apt-get install for mongo 4.0 and restart the instance.
What happens to the other replica set members on ports 27017 and 27018 that I didn’t shut down prior to the 3.6 pkg being replaced with 4.0? Its odd to me that they will still run after I overwrite 3.6

If this is for anything other than testing/experimentation, you’re doing in wrong.

This is pretty standard for linux, the old binary is still in use and will exist until it is no longer ‘open’.

What can stop the running process is the upgrade scripts included in the package. You cannot assume that a package will or will not stop the current process. My opinion is you should always test it yourself too.

From unlink man page:

   If the name was the last link to a file but any processes still
  have the file open, the file will remain in existence until the
  last file descriptor referring to it is closed.

Example. Running 4.0 and upgraded the binary to 4.2, the running inode and the new binary inode are different, also note that the replaced binary shows as (deleted).

ls -li /proc/$(pidof mongod)/exe; ls -li /usr/bin/mongod
28134638 lrwxrwxrwx 1 root root 0 Aug 23 08:05 /proc/4906/exe -> '/usr/bin/mongod (deleted)'
408225 -rwxr-xr-x 1 root root 73807784 Dec 19  2013 /usr/bin/mongod

Disclaimer: running as root for illustration purposes only, always run your mongod under a dedicated user.

1 Like