MongoDB 3.2.6 init script is missing

I followed the directions to install MongoDB via apt-get. There was a hiccup with verification, but tracking this down on StackExchange indicated it was a known issue with the signing process, so I re-ran apt-get install mongodb without the -y flag. Installation then succeeded, or so it seemed. But when I tried to start the service, this happened:

$ sudo service mongod start
[sudo] password for mark: 
Failed to start mongod.service: Unit mongod.service not found.
$ sudo service mongod status
● mongod.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)

Sure enough, the file /etc/init.d/mongod does not exist. The install directions explicitly say this file is provided:

The mongodb-org package includes various init scripts, including the init script /etc/init.d/mongod.

The file does exist in the sources on GitHub. So I can carry on. But I'd like to know why a critical configuration file is missing from a successfully installed package. (Call me a completist.)

My Ubuntu release is 16.10, which is not officially supported. I wouldn't think that could be the cause. Could the release version really be to blame? Or was it a mistake to install the packages unsigned? Or is the package itself broken? Or is something else going on here?


I was just wrong. The release incompatibility is the issue. It appears a post-install script was silently failing, which is why the missing file did not exist.

The solution turned out to be very similar to this question, which suggests running this script.

I made minor changes to the script, in accordance with a change to the default file locations for MongoDB 3.2.6. (The changes aren't strictly necessary. I just don't like cruft.) Previously, data files were located in /data/db/. The default location is now /var/lib/mongodb/, and the old location is no longer used at all. So I removed the lines in the script that refer to that path.

Ubuntu now uses systemd by default rather than Upstart, so /var/run/mongodb/ is no longer needed. I just commented out these lines rather than removing them. If you're still using Upstart for whatever reason, you'll need to uncomment the three lines that refer to this path.

The updated script looks like this:

# enable_mongo.sh

echo '[Unit]
Description=High-performance, schema-free document-oriented database
After=syslog.target network.target

[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod -f /etc/mongod.conf

[Install]
WantedBy=multi-user.target' > /lib/systemd/system/mongod.service

# Setup the required directories
# mkdir -p /var/run/mongodb/
mkdir -p /var/log/mongodb/
mkdir -p /var/lib/mongodb/

# chown mongodb:mongodb /var/run/mongodb/
chown mongodb:mongodb /var/log/mongodb/
chown mongodb:mongodb /var/lib/mongodb/

# chmod 0755 /var/run/mongodb/
chmod 0755 /var/log/mongodb/
chmod 0755 /var/lib/mongodb/

# Start the new service and enable it on boot
systemctl --system daemon-reload
systemctl enable mongod.service

echo "Starting"
systemctl start mongod.service