Service Management: Difference between revisions

From Leo's Notes
This page was last edited on 12 September 2019, at 02:20.
No edit summary
m formatting
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Linux ==
== Linux using SystemV ==
Use <strong>any one</strong> of:
/etc/init.d/&lt;service&gt; restart


/etc/init.d/&lt;service&gt; stop && /etc/init.d/<service> start
=== Starting & Stopping Services ===
Use '''any one''' of:
{{highlight|lang=terminal|code=
# /etc/init.d/<service> restart
# /etc/init.d/<service> stop && /etc/init.d/<service> start
# service <service> restart
}}


service &lt;service&gt; restart
Since the location of startup scripts varies from distro to distro, using the {{code|service}} command is recommended.


Since the location of startup scripts varies from distro to distro, using the <code>service</code> command is recommended.
=== Manage Startup ===
Show all the services for every runlevel:
{{highlight|lang=terminal|code=
# chkconfig --list
}}
Enable a service (eg: sshd) on runlevels 2, 3, 4:
 
{{highlight|lang=terminal|code=
# chkconfig --add sshd
# chkconfig --level 234 sshd on
}}
 
== Linux using systemd ==
=== Starting & Stopping Services ===
 
{{highlight|lang=terminal|code=
# systemctl start <service>
# systemctl stop <service>
}}
 
=== Getting Service Information ===
 
{{highlight|lang=terminal|code=
# systemctl status <service>
# journalctl -u <service>
}}
 
=== Enabling / Disabling Services at Startup ===
 
{{highlight|lang=terminal|code=
# systemctl enable <service>
# systemctl disable <service>
}}


== FreeBSD ==
== FreeBSD ==
Similar to linux, you can either start services using their startup scripts or using the <code>service</code> command.
Similar to Linux, you can either start services using their startup scripts or using the {{code|service}} command.
 
Usually, the startup scripts are located in {{code|/etc/rc.d}}
 
{{highlight|lang=terminal|code=
# /etc/rc.d/<service> restart
}}
 
However, if it is 3rd party software, they are located in {{code|/usr/local/etc/rc.d}}
 
{{highlight|lang=terminal|code=
# /usr/local/etc/rc.d/<service> restart
}}


Usually, the startup scripts are located in <code>/etc/rc.d</code>
Or to not worry about any of the above, use {{code|service}}
/etc/rc.d/&lt;service&gt; restart


However, if it is 3rd party software, they are located in <code>/usr/local/etc/rc.d</code>
{{highlight|lang=terminal|code=
/usr/local/etc/rc.d/&lt;service&gt; restart
# service nfs stop
# service sickbeard start
# service httpd status
}}


Or to not worry about any of the above, use <code>service</code>
<strong>Note:</strong> You can send the {{code|HUP}} signal to restart a service. For instance, to restart NFS, you can do any one of:
service nfs stop
service sickbeard start
service httpd status


{{highlight|lang=terminal|code=
# kill -HUP `cat /var/run/mountd.pid`
# /etc/rc.d/nsfd restart
# service nfs restart
}}


<strong>Note:</strong> You can send the <code>HUP</code> 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 ==
== Solaris / SunOS ==
The startup scripts are located in <code>/lib/svc/method/<service></code>
The startup scripts are located in {{code|/lib/svc/method/<service>}}
/lib/svc/method/<service> restart
svcadm restart <service>


Example: To restart ssh, do <strong>any one</strong> of:
{{highlight|lang=terminal|code=
svcadm restart ssh
# /lib/svc/method/<service> restart
# svcadm restart <service>
}}


svcadm restart svc:/network/ssh
Example: To restart ssh, do '''any one''' of:


/lib/svc/method/sshd restart
{{highlight|lang=terminal|code=
# svcadm restart ssh
# svcadm restart svc:/network/ssh
# /lib/svc/method/sshd restart
}}


[[Category:Linux]]
{{Navbox Linux}}[[Category:Linux]]
[[Category:FreeBSD]]
[[Category:FreeBSD]]
[[Category:Solaris]]
[[Category:Solaris]]

Latest revision as of 02:20, 12 September 2019

Linux using SystemV

Starting & Stopping Services

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

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

Starting & Stopping Services

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

Getting Service Information

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

Enabling / Disabling Services at Startup

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

FreeBSD

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

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