I see that you have mentioned that you would like to start HTTPD in runlevel 3 and 5, and to stop HTTPD in runlevel 2 and 4. Here is a URL to the Red Hat manual the provides a great overview of Init and SystemD.
The Red Hat manual states that multi-user.target is the same as runlevels 2, 3, and 4.
- Runlevel 0 = poweroff.target
- Runlevel 1 = rescue.target
- Runlevel 2 = multi-user.target
- Runlevel 3 = multi-user.target
- Runlevel 4 = multi-user.target
- Runlevel 5 = graphical.target
- Runlevel 6 = reboot.target
With this in mind, it seems like there would be no point in using a command such as
systemctl set-default multi-user.target in an attempt to switch between runlevels 2, 3, and 4, since runlevels 2, 3, and 4 are synonymous with multi-user.target.
It is noteworthy that the
systemctl cat httpd command can be used to view some of the configuration information. Related to your question, this command will show that HTTPD is set to multi-user.target.
# systemctl cat httpd
. . .
I am not sure if this would be appropriate for your environment. A possible solution to your need may be to have a script that determines the current run-level of the system, and then uses some if loops to start or stop the HTTPD daemon based on the target. For example, perhaps the script could look a little something like this.
if [ $target == "multi-user.target" ]
systemctl stop httpd
systemctl start httpd