Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How do I stop a program running at startup in Linux. I want to remove some apps from startup to allow them to be managed by supervisord e.g apache2

share|improve this question
    
imo in this kind of question it would definitely be good to tag with distro and mention it. I know this varies by distribution. –  xenoterracide Aug 10 '10 at 20:34
    
That's exactly why I didn't tag it... I'm looking for all the variations as I work with quite a few different distros. –  Frozenskys Aug 10 '10 at 21:15
add comment

5 Answers

up vote 10 down vote accepted

Depending on your distro use the chkconfig or update-rc.d tool to enable/disable system services.

On a redhat/suse/mandrake style system:

sudo chkconfig apache2 off 

On Debian:

sudo update-rc.d -f apache2 remove

Checkout their man pages for more info.

share|improve this answer
    
Why do you need -f (I assume it's force) on Debian based distros? –  Frozenskys Aug 10 '10 at 20:05
2  
There are two sets of files in play here. You've got the actual init script in /etc/init.d/ and you have the links to it in your runlevel directory /etc/rcrunlevel.d/. These guys point to the script in /etc/init.d/ If you don't use -f update-rd.d will fail UNLESS the script in /etc/init.d/ is already deleted. If you do use -f update-rc.d will properly delete the link files regardless of whether or not the /etc/init.d/ script is deleted. –  jacksonh Aug 10 '10 at 20:38
    
Ah, that makes a lot of sense, I'd forgotten that the runlevel scripts were just links to the init scripts. Thanks for the extra explanation. –  Frozenskys Aug 10 '10 at 21:18
add comment

If you are dealing with a modern Ubuntu system and a few other distros you may have to deal with a combination of traditional init scripts and upstart scripts. Managing init scripts is covered by other answers. The following is one way to stop an upstart service from starting on boot:

# mv /etc/init/servicename.conf /etc/init/servicename.conf.disabled

The problem with this method is that it does not allow you to start the service using:

# service start servicename

An alternative to this is to open the servicename.conf file in your favorite editor and comment out any lines that start with:

start on

That is, change this to

#start on ...

where the "..." is whatever was after "start on" previously. This way, when you want to re-enable it, you don't have to remember what the "start on" parameters were.

Finally, if you have a new version of upstart you can simply add the word "manual" to the end of the configuration file. You can do this directly from the shell:

# echo "manual" >> /etc/init/servicename.conf

This will cause upstart to ignore any "start on" phrases earlier in the file.

share|improve this answer
add comment

On Ubuntu 10.04 you can control some startup programs from the GUI.

System-->Preferences-->Startup Applications

startup apps

share|improve this answer
    
Original image is no longer there. –  Tshepang Mar 3 '11 at 21:28
add comment

Slackware and Arch linux have similar methods of stopping/starting processes at boot, different than the Ubuntu and Redhat-style examples given above.

In both Slackware and Arch linuxes, sh scripts exist in directory /etc/rc.d, typically one script per daemon, or one script per subsystem.

For example, Slackware starts the Apache web server with a script /etc/rc.d/rc.httpd, called at the appropriate time during system startup with an argument of "start". Arch linux has differently-named scripts, but the same sort of thing goes on.

To keep some process from starting during system boot, on Slackware, you just make the appropriate script in /etc/rc.d not executable. To keep Apache from starting at the next boot:

chmod -x /etc/rc.d/rc.httpd

To stop an Apache that got started at boot: /etc/rc.d/rc.httpd stop You'll need to be root.

Arch is a bit more complex. The file /etc/rc.conf, a shell script, has an array DAEMONS. To keep Apache from starting at boot, you'd change this line in /etc/rc.conf:

DAEMONS=(hal syslog-ng network netfs crond alsa sshd httpd ntpd postgresql)

To this line:

DAEMONS=(hal syslog-ng network netfs crond alsa sshd ntpd postgresql)

To stop an already executing apache, you'd execute /etc/rc.d/httpd stop as root.

share|improve this answer
add comment

On recent Fedora and Future RHEL systems

systemctl disable httpd.service

will disable the httpd service

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.