Service Management

From Leo's Notes
Last edited on 12 September 2019, at 02:20.

Linux using SystemV[edit | edit source]

Starting & Stopping Services[edit | edit source]

Use any one of:

# /etc/init.d/<service> restart
# /etc/init.d/<service> stop && /etc/init.d/<service> start
# service <service> restart

Since the location of startup scripts varies from distro to distro, using the service command is recommended.

Manage Startup[edit | edit source]

Show all the services for every runlevel:

# chkconfig --list

Enable a service (eg: sshd) on runlevels 2, 3, 4:

# chkconfig --add sshd
# chkconfig --level 234 sshd on

Linux using systemd[edit | edit source]

Starting & Stopping Services[edit | edit source]

# systemctl start <service>
# systemctl stop <service>

Getting Service Information[edit | edit source]

# systemctl status <service>
# journalctl -u <service>

Enabling / Disabling Services at Startup[edit | edit source]

# systemctl enable <service>
# systemctl disable <service>

FreeBSD[edit | edit source]

Similar to Linux, you can either start services using their startup scripts or using the service command.

Usually, the startup scripts are located in /etc/rc.d

# /etc/rc.d/<service> restart

However, if it is 3rd party software, they are located in /usr/local/etc/rc.d

# /usr/local/etc/rc.d/<service> restart

Or to not worry about any of the above, use service

# service nfs stop
# service sickbeard start
# service httpd status

Note: You can send the HUP signal to restart a service. For instance, to restart NFS, you can do any one of:

# kill -HUP `cat /var/run/mountd.pid`
# /etc/rc.d/nsfd restart
# service nfs restart


Solaris / SunOS[edit | edit source]

The startup scripts are located in /lib/svc/method/<service>

# /lib/svc/method/<service> restart
# svcadm restart <service>

Example: To restart ssh, do any one of:

# svcadm restart ssh
# svcadm restart svc:/network/ssh
# /lib/svc/method/sshd restart