xref: /freebsd/usr.sbin/service/service.8 (revision 8fa4a4eb705ccaece5aac4ae1201034001f21313)
1.\" Copyright (c) 2009 Douglas Barton
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.Dd May 9, 2025
26.Dt SERVICE 8
27.Os
28.Sh NAME
29.Nm service
30.Nd "control (start/stop/etc.) or list system services"
31.Sh SYNOPSIS
32.Nm
33.Op Fl j Ar jail
34.Fl e
35.Nm
36.Op Fl j Ar jail
37.Fl R
38.Nm
39.Op Fl j Ar jail
40.Op Fl v
41.Fl l
42.Nm
43.Op Fl j Ar jail
44.Op Fl v
45.Fl r
46.Nm
47.Op Fl j Ar jail
48.Op Fl q
49.Op Fl v
50.Op Fl E Ar var=value
51.Ar script
52.Op Ar command
53.Sh DESCRIPTION
54The
55.Nm
56command is an easy interface to the rc.d system.
57Its primary purpose is to start and stop services provided
58by the rc.d scripts.
59When used for this purpose it will set the same restricted
60environment that is in use at boot time
61.Po
62see
63.Sx ENVIRONMENT
64.Pc .
65It can also be used to list
66the scripts using various criteria.
67.Pp
68The set of permissible values for
69.Ar command
70depends on the particular rc.d script being invoked.
71For a list of standard commands which are supported by most rc.d
72scripts, see
73.Xr rc 8 .
74.Pp
75The options are as follows:
76.Bl -tag -width F1
77.It Fl E Ar var=value
78Set the environment variable
79.Ar var
80to the specified
81.Ar value
82before starting the script.
83This option can be used multiple times.
84.It Fl e
85List services that are enabled.
86The list of scripts to check is compiled using
87.Xr rcorder 8
88the same way that it is done in
89.Xr rc 8 ,
90then that list of scripts is checked for an
91.Qq rcvar
92assignment.
93If present the script is checked to see if it is enabled.
94.It Fl j Ar jail
95Perform the given actions under the named jail.
96The
97.Ar jail
98argument can be either a jail ID or a jail name.
99.It Fl l
100List all files in
101.Pa /etc/rc.d
102and the local startup directories.
103As described in
104.Xr rc.conf 5
105this is usually
106.Pa /usr/local/etc/rc.d .
107All files will be listed whether they are an actual
108rc.d script or not.
109.It Fl R
110Restart all enabled local services.
111.It Fl r
112Generate the
113.Xr rcorder 8
114as in
115.Fl e
116above, but list all of the files, not just what is enabled.
117.It Fl v
118Be slightly more verbose.
119.It Fl q
120Be quiet, redirecting output to /dev/null.
121.El
122.Sh ENVIRONMENT
123When used to run rc.d scripts the
124.Nm
125command sets
126.Ev HOME
127to
128.Pa /
129and
130.Ev PATH
131to
132.Pa /sbin:/bin:/usr/sbin:/usr/bin
133which is how they are set in
134.Pa /etc/rc
135at boot time.
136If the
137.Fl E
138option is used, the corresponding variable is set accordingly.
139.Sh EXIT STATUS
140.Ex -std
141.Sh EXAMPLES
142These are some examples of the most common service commands.
143For a full list of commands available in most rc.d scripts, see
144.Xr rc 8 .
145.Pp
146Enable a service, then start it:
147.Bd -literal -offset indent
148service sshd enable
149service sshd start
150.Ed
151.Pp
152Stop a service, then disable it:
153.Bd -literal -offset indent
154service sshd stop
155service sshd disable
156.Ed
157.Pp
158Start a service which is not enabled:
159.Bd -literal -offset indent
160service sshd onestart
161.Ed
162.Pp
163Report the status of a service:
164.Bd -literal -offset indent
165service named status
166.Ed
167.Pp
168Restart a service running in a jail:
169.Bd -literal -offset indent
170service -j dns named restart
171.Ed
172.Pp
173Start a service with a specific environment variable set:
174.Bd -literal -offset indent
175service -E LC_ALL=C.UTF-8 named start
176.Ed
177.Pp
178Report a verbose listing of all available services:
179.Bd -literal -offset indent
180service -rv
181.Ed
182.Pp
183The following programmable completion entry can be used in
184.Xr csh 1
185for the names and common commands of the rc.d scripts:
186.Bd -literal -offset indent
187complete service 'c/-/(e l r v)/' 'p/1/`service -l`/' \e
188		 'n/*/(start stop reload restart \e
189		 status rcvar onestart onestop)/'
190.Ed
191.Pp
192The following programmable completion entry can be used in
193.Xr bash 1 Pq Pa ports/shells/bash
194for the names of the rc.d scripts:
195.Bd -literal -offset indent
196_service () {
197	local cur
198	cur=${COMP_WORDS[COMP_CWORD]}
199	COMPREPLY=( $( compgen -W '$( service -l )' -- $cur ) )
200	return 0
201}
202complete -F _service service
203.Ed
204.Sh SEE ALSO
205.Xr bash 1 Pq Pa ports/shells/bash ,
206.Xr rc.conf 5 ,
207.Xr rc 8 ,
208.Xr rcorder 8 ,
209.Xr sysrc 8
210.Sh HISTORY
211The
212.Nm
213utility first appeared in
214.Fx 7.3 .
215.Sh AUTHORS
216This
217manual page was written by
218.An Douglas Barton Aq Mt dougb@FreeBSD.org .
219