10

I just provisioned a new VPS running CentOS 6, and it comes with Apache.

I want to disable Apache, because I will be using Nginx instead.

I know I can just delete the script in /etc/init.d/, but I don't want to do that, because it's a stock thing that came with the system. I would rather have a graceful way of disabling the service.

I thought that I would be able to put something in /etc/inittab, but inittab contains:

# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
# 
id:3:initdefault:

This leads me to believe that the system is running upstart. Well, I looked, and the correct way to disable a service in upstart is to add an override file. So I run:

% 'manual' > /etc/init/httpd.override

And reboot my server. But httpd is still running! Confused by this, I decide to check that upstart is the init service, by running

% readlink /proc/1/exe
/sbin/init

Well that's not what I was expecting to see. Maybe I'm not running upstart after all. Is there a definite way to check? And if I am running init, what is the recommended way to disable a service permanently? I am new to all this, and there seem to be many conflicting opinions out there.

Thank you all for your help.

Max Bucknell
  • 213
  • 1
  • 3
  • 9
  • Why not just remove apache if you are not going to use it? – Frederik Aug 05 '13 at 14:35
  • Because I might want to use it in the future, for proxying Python applications with mod_wsgi, or running PHP. For now, I don't want to use it. And this seems like a problem I might have again in the future, with different services, too. – Max Bucknell Aug 05 '13 at 14:37

2 Answers2

16

The way you disable a service under just about any RedHat-derived distribution is with the chkconfig command:

# chkconfig httpd off

And to stop a running service:

# service httpd stop

These commands will Do the Right Thing regardless of whether your system is running systemd, upstart, or vanilla SysVInit.

For what it's worth, despite running upstart most services in CentOS 6 actually use legacy init.d scripts, located in /etc/rc.d/rc<RUNLEVEL>.d. For these services, chkconfig manages the symlinks in /etc/rc.d/init.d.

larsks
  • 41,276
  • 13
  • 117
  • 170
  • I found this out by searching for something equivalent to update-rc.d from trillan's answer. Was just about to answer my own question, but you beat me to it. Thanks a lot, larsks. – Max Bucknell Aug 05 '13 at 14:12
4

Disable the service you dont want to start during system boot using chkconfig.

List available services with their states

chkconfig --list

Disable service htttpd in runlevel 2345

chkconfig --level 2345 httpd off

clement
  • 875
  • 5
  • 9