xref: /freebsd/usr.sbin/service/service.8 (revision 62a52c15422470f97fc7b311d89c83f910bcc1b1)
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 January 29, 2024
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 v
49.Op Fl E Ar var=value
50.Ar script
51.Ar command
52.Sh DESCRIPTION
53The
54.Nm
55command is an easy interface to the rc.d system.
56Its primary purpose is to start and stop services provided
57by the rc.d scripts.
58When used for this purpose it will set the same restricted
59environment that is in use at boot time
60.Po
61see
62.Sx ENVIRONMENT
63.Pc .
64It can also be used to list
65the scripts using various criteria.
66.Pp
67The set of permissible values for
68.Ar command
69depends on the particular rc.d script being invoked.
70For a list of standard commands which are supported by most rc.d
71scripts, see
72.Xr rc 8 .
73.Pp
74The options are as follows:
75.Bl -tag -width F1
76.It Fl E Ar var=value
77Set the environment variable
78.Ar var
79to the specified
80.Ar value
81before starting the script.
82This option can be used multiple times.
83.It Fl e
84List services that are enabled.
85The list of scripts to check is compiled using
86.Xr rcorder 8
87the same way that it is done in
88.Xr rc 8 ,
89then that list of scripts is checked for an
90.Qq rcvar
91assignment.
92If present the script is checked to see if it is enabled.
93.It Fl j Ar jail
94Perform the given actions under the named jail.
95The
96.Ar jail
97argument can be either a jail ID or a jail name.
98.It Fl l
99List all files in
100.Pa /etc/rc.d
101and the local startup directories.
102As described in
103.Xr rc.conf 5
104this is usually
105.Pa /usr/local/etc/rc.d .
106All files will be listed whether they are an actual
107rc.d script or not.
108.It Fl R
109Restart all enabled local services.
110.It Fl r
111Generate the
112.Xr rcorder 8
113as in
114.Fl e
115above, but list all of the files, not just what is enabled.
116.It Fl v
117Be slightly more verbose.
118.El
119.Sh ENVIRONMENT
120When used to run rc.d scripts the
121.Nm
122command sets
123.Ev HOME
124to
125.Pa /
126and
127.Ev PATH
128to
129.Pa /sbin:/bin:/usr/sbin:/usr/bin
130which is how they are set in
131.Pa /etc/rc
132at boot time.
133If the
134.Fl E
135option is used, the corresponding variable is set accordingly.
136.Sh EXIT STATUS
137.Ex -std
138.Sh EXAMPLES
139These are some examples of the most common service commands.
140For a full list of commands available in most rc.d scripts, see
141.Xr rc 8 .
142.Pp
143Enable a service, then start it:
144.Bd -literal -offset -indent
145service sshd enable
146service sshd start
147.Ed
148.Pp
149Stop a service, then disable it:
150.Bd -literal -offset -indent
151service sshd stop
152service sshd disable
153.Ed
154.Pp
155Start a service which is not enabled:
156.Bd -literal -offset -indent
157service sshd onestart
158.Ed
159.Pp
160Report the status of a service:
161.Bd -literal -offset -ident
162service named status
163.Ed
164.Pp
165Restart a service running in a jail:
166.Bd -literal -offset -indent
167service -j dns named restart
168.Ed
169.Pp
170Start a service with a specific environment variable set:
171.Bd -literal -offset -indent
172service -E LC_ALL=C.UTF-8 named start
173.Ed
174.Pp
175Report a verbose listing of all available services:
176.Bd -literal -offset -indent
177service -rv
178.Ed
179.Pp
180The following programmable completion entry can be used in
181.Xr csh 1
182for the names and common commands of the rc.d scripts:
183.Bd -literal -offset indent
184complete service 'c/-/(e l r v)/' 'p/1/`service -l`/' \e
185		 'n/*/(start stop reload restart \e
186		 status rcvar onestart onestop)/'
187.Ed
188.Pp
189The following programmable completion entry can be used in
190.Xr bash 1
191for the names of the rc.d scripts:
192.Bd -literal -offset -ident
193_service () {
194	local cur
195	cur=${COMP_WORDS[COMP_CWORD]}
196	COMPREPLY=( $( compgen -W '$( service -l )' -- $cur ) )
197	return 0
198}
199complete -F _service service
200.Ed
201.Sh SEE ALSO
202.Xr bash 1 Pq Pa ports/shells/bash ,
203.Xr rc.conf 5 ,
204.Xr rc 8 ,
205.Xr rcorder 8 ,
206.Xr sysrc 8
207.Sh HISTORY
208The
209.Nm
210utility first appeared in
211.Fx 7.3 .
212.Sh AUTHORS
213This
214manual page was written by
215.An Douglas Barton Aq Mt dougb@FreeBSD.org .
216