Saturday, May 7, 2011

Manage services in Ubuntu

Start a service
(myServ is a service name)
sudo /etc/init.d/myServ start
or
sudo service myServ start
Stop a service
sudo /etc/init.d/myServ stop
or
sudo service myServ stop
Disable a service
Check if the service is handled by Upstart first by using
status myServ
If it returns the following message,
status: Unknown job: myServ
it's not handled by Upstart, disable it using
sudo update-rc.d myServ disable
For the service that is handled by Upstart, the output of the status command will be like:-
myServ start/running, process 989
If that's the case, then the service can be disabled by doing one of the following

  • Open the Upstart job definition file (e.g. /etc/init/myServ.conf) and then comment out the "start on" line by putting a "#" in front of it.
  • Add a special keyword "manual" to the job definition file by just using the command "echo"
echo manual | sudo tee -a /etc/init/myServ.conf

Enable a service
For non-Upstart managed services, use
sudo update-rc.d myServ enable
For Upstart managed services, undo what's been done above.

Refs:
http://lwn.net/Articles/382853/
http://askubuntu.com/questions/19320/whats-the-recommend-way-to-enable-disable-services

1 comment:

  1. Thanks for this helpful codes. this will now resolve my problem.

    ReplyDelete