Start Specific Services First in RedHat 7/CentOS 7 - SystemD - Set Service Start Order
Question sent in by: Gaurav P
Q: I was wondering if there is a way that I can specify one service to always start before the other service? For eg. I have enabled both mongodb and celiometer service to start at boot time, but I want to ensure that every time the mongodb service starts before the celiometer.
A: You can configure dependencies for certain services. For example you can make celiometer dependent on mongodb, this way celiometer will not start before mengodb.
NOTE: I am not familiar with celiometer, so for this example we will use mongodb and apache (httpd).
This should work in any version of Linux running Systemd, including but not limited to Redhat 7, CentOS 7, Fedora 20 or higher, Ubuntu, etc...
So let's say you want mongodb to start first before httpd. You can simply edit the /usr/lib/systemd/system/httpd.service file and look for the following line:
After=network.target remote-fs.target nss-lookup.target
After=network.target remote-fs.target nss-lookup.target mongod.service
(This will activate mongodb when httpd is started, but will not cause httpd to fail if mongodb fails to start)
(This will activate mongodb when httpd is started, but will cause httpd to fail if mongodb fails to start)
(This will stop mongodb when httpd is stopped)
This site uses Akismet to reduce spam. Learn how your comment data is processed.