xref: /freebsd/usr.sbin/service/service.8 (revision edf8578117e8844e02c0121147f45e4609b30680)
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 November 9, 2021
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 options are as follows:
68.Bl -tag -width F1
69.It Fl E Ar var=value
70Set the environment variable
71.Ar var
72to the specified
73.Ar value
74before starting the script.
75This option can be used multiple times.
76.It Fl e
77List services that are enabled.
78The list of scripts to check is compiled using
79.Xr rcorder 8
80the same way that it is done in
81.Xr rc 8 ,
82then that list of scripts is checked for an
83.Qq rcvar
84assignment.
85If present the script is checked to see if it is enabled.
86.It Fl j Ar jail
87Perform the given actions under the named jail.
88The
89.Ar jail
90argument can be either a jail ID or a jail name.
91.It Fl l
92List all files in
93.Pa /etc/rc.d
94and the local startup directories.
95As described in
96.Xr rc.conf 5
97this is usually
98.Pa /usr/local/etc/rc.d .
99All files will be listed whether they are an actual
100rc.d script or not.
101.It Fl R
102Restart all enabled local services.
103.It Fl r
104Generate the
105.Xr rcorder 8
106as in
107.Fl e
108above, but list all of the files, not just what is enabled.
109.It Fl v
110Be slightly more verbose.
111.El
112.Sh ENVIRONMENT
113When used to run rc.d scripts the
114.Nm
115command sets
116.Ev HOME
117to
118.Pa /
119and
120.Ev PATH
121to
122.Pa /sbin:/bin:/usr/sbin:/usr/bin
123which is how they are set in
124.Pa /etc/rc
125at boot time.
126If the
127.Fl E
128option is used, the corresponding variable is set accordingly.
129.Sh EXIT STATUS
130.Ex -std
131.Sh EXAMPLES
132The following are examples of typical usage of the
133.Nm
134command:
135.Bd -literal -offset -ident
136service named status
137service -j dns named status
138service -E LC_ALL=C.UTF-8 named start
139service -rv
140.Ed
141.Pp
142The following programmable completion entry can be used in
143.Xr csh 1
144for the names and common commands of the rc.d scripts:
145.Bd -literal -offset indent
146complete service 'c/-/(e l r v)/' 'p/1/`service -l`/' \e
147		 'n/*/(start stop reload restart \e
148		 status rcvar onestart onestop)/'
149.Ed
150.Pp
151The following programmable completion entry can be used in
152.Xr bash 1
153for the names of the rc.d scripts:
154.Bd -literal -offset -ident
155_service () {
156	local cur
157	cur=${COMP_WORDS[COMP_CWORD]}
158	COMPREPLY=( $( compgen -W '$( service -l )' -- $cur ) )
159	return 0
160}
161complete -F _service service
162.Ed
163.Sh SEE ALSO
164.Xr bash 1 Pq Pa ports/shells/bash ,
165.Xr rc.conf 5 ,
166.Xr rc 8 ,
167.Xr rcorder 8
168.Sh HISTORY
169The
170.Nm
171utility first appeared in
172.Fx 7.3 .
173.Sh AUTHORS
174This
175manual page was written by
176.An Douglas Barton Aq Mt dougb@FreeBSD.org .
177