Saturday, July 20, 2013

Manage Services in Linux

Service Management
On any system it is important to manage the running services. Managing services enables you to stop, start, restart services whenever needed. In Linux, services can also be called daemons that's why most of the services end with a "d" such as sshd, httpd, dhcpd, vsftpd etc.

TO manage services at each runlevel, you can use the chkconfig command.
Syntax: chkconfig [option] service_name.
Options that you can use:

--list [name] Shows the status of the service at each runlevel.
--level <levels> Enables or disables the service at the given levels.
 <service_name>  <on|off|

Step 1. To check the status of the sshd service use following command:
# chkconfig --list sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
According to output you can understand the sshd service will be started at runlevels 2, 3, 4, and 5. It will be stopped at runlevels 0, 1, and 6.

Step 2. Use the off option to disable the service at boot.:
# chkconfig sshd off

Step 4. Re-enable the SSH service:
# chkconfig sshd on
Aside from using the chkconfig command, you can do the same task by using the ntsysv command.
#ntsysv
And you will see a menu-driven window where you can manage services.

You can also use the service command. You can use this to start, stop, and query the status of services.
Step 1. Usually, it is a good idea to always check the status of the service first:
# service ntpd status
ntpd is stopped

Step 2. When you know that the service is stopped, you can start it:
# service ntpd start
Starting ntpd: [ OK ]

Step 3. Stop the NTP service:
# service ntpd stop
Shutting down ntpd: [ OK ]

Step4. To restart the sshd service
# service sshd restart

No comments:

Post a Comment