I am trying to run MongoDB on a Debian 8.5 machine. When I installed the package (pre-built from percona.com), I noticed the following files:
/etc/init.d/mongod (1)
/lib/systemd/system/mongod.service (2)
I understand that /etc/init.d/mongod
is called at boot, or in other particular system states, as long as it is registered via update-rc.d
. This is perfectly fine for me. The script initializes and launches the mongo daemon. It seems to have “triggers” for start, stop, restart, etc., and as far as I understand I can trigger those with sudo service mongod <action>
.
/lib/systemd/system/mongod.service
seems to do the same thing (i.e. run mongo), but with less configuration - just one line in the ExecStart parameter:
[Unit]
Description=MongoDB (High-performance, schema-free document-oriented database)
After=time-sync.target network.target
[Service]
Type=forking
User=mongod
Group=mongod
PermissionsStartOnly=true
EnvironmentFile=/etc/default/mongod
ExecStart=/usr/bin/env bash -c "/usr/bin/mongod $OPTIONS > ${STDOUT} 2> ${STDERR}"
PIDFile=/var/run/mongod.pid
[Install]
WantedBy=multi-user.target
As far as I understand this can be triggered with sudo systemctl start mongod
.
I don’t understand if is called at boot or not.
I don’t understand why the need for two of these ‘service’ files, and how can I get rid of one (possibly the one in /lib/systemd, since it is much simpler).
I don’t understand if there’s any relation between the two.
I have read that
systemctl
works oninit.d
scripts too, and in this case I don’t understand which of the two files will be triggered bysystemctl mongod start
.
I think there’s some redundancy and I should choose just one of the two ways. And I want to be sure that it is
- called at boot
- callable by command (like
service
orsystemctl
).
Could you help me clear my mind?