Stop program running at startup in Linux

92,705

Solution 1

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.

Solution 2

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.

Solution 3

To list all the startup services

    systemctl

To stop a service from running on start up

    sudo systemctl disable servicename

For instance if we need to stop running ssh server at startup

    sudo systemctl disable sshd.service

We can enable this again using

    sudo systemctl enable sshd.service

Almost every linux distributions use systemd for bootstrapping startup services. So above commands work for most of the distros.

Solution 4

On recent Fedora and Future RHEL systems

systemctl disable httpd.service

will disable the httpd service

Share:
92,705

Related videos on Youtube

Jeff Winkworth
Author by

Jeff Winkworth

Hmmm, I like Django & Chocolate, That is all... Oh and I'm both an MCT and MCSD.

Updated on September 17, 2022

Comments

  • Jeff Winkworth
    Jeff Winkworth over 1 year

    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

  • Jeff Winkworth
    Jeff Winkworth almost 14 years
    Why do you need -f (I assume it's force) on Debian based distros?
  • jacksonh
    jacksonh almost 14 years
    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.
  • Jeff Winkworth
    Jeff Winkworth almost 14 years
    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.
  • tshepang
    tshepang about 13 years
    Original image is no longer there.
  • Jeff Schaller
    Jeff Schaller about 5 years
    Welcome to U&L, and thank you for your contribution! I'd like to point out that this question is about eight years old now, so the accepted answer was correct for the time. Using systemctl may be correct now, but it's correct for a different question.
  • loved.by.Jesus
    loved.by.Jesus over 4 years
    Thanks! I had tried many methods, but this systmctl command worked fine.
  • loved.by.Jesus
    loved.by.Jesus over 4 years
    @Prince thanks for the detailed explanations. It helped me to understand how the boot startup works in my Xubuntu.