xref: /netbsd-src/usr.sbin/service/service.8 (revision e3da17cc3a2bdc06b85cee5f49e5aae1cb601af7)
1.\"	$NetBSD: service.8,v 1.6 2023/03/14 21:50:25 uwe Exp $
2.\"
3.\" Copyright (c) 2009 Douglas Barton
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25.\" SUCH DAMAGE.
26.\"
27.Dd March 12, 2023
28.Dt SERVICE 8
29.Os
30.Sh NAME
31.Nm service
32.Nd run or list system services
33.Sh SYNOPSIS
34.Nm
35.Op Fl elv
36.Nm
37.Op Fl ev
38.Ar rc_script_name Op Ar rc_script_name Ar ...
39.Nm
40.Op Fl v
41.Ar rc_script_name action
42.Sh DESCRIPTION
43The
44.Nm
45command is a simple interface to the services startup system.
46.Pp
47Its purpose is to list the services or invoke actions on them
48as provided by the
49.Xr rc.d 8
50scripts.
51When used to invoke
52.Pa rc.d
53scripts,
54.Nm
55will set the same environment that is used at boot time.
56.Pp
57The options are as follows:
58.Bl -tag -width Fl
59.It Fl e
60List services that are enabled.
61The list of scripts is compiled using
62.Xr rcorder 8
63the same way as is done in
64.Xr rc 8 ;
65each script is first checked for an
66.Dv rcvar
67assignment and if present,
68checked to see if it is enabled.
69If one or more
70.Ar rc_script_name
71are specified, only those are checked.
72The
73.Ar rc_script_name
74arguments are always specified without a path prefix.
75.It Fl l
76List all files in
77.Pa /etc/rc.d
78.Po
79the default of
80.Ev rc_directories
81as defined in
82.Xr rc.conf 5
83.Pc .
84A script will be listed unless it has the
85.Dv nostart
86keyword enabled.
87Scripts are listed in the order the
88.Pa rc.d
89system runs them at system boot time.
90.It Fl v
91Report what
92.Dv rc_directories
93are defined or in which directory the
94.Pa rc.d
95script was found when an
96.Ar action
97is invoked.
98.El
99.Pp
100The
101.Fl e
102and
103.Fl l
104options are mutually exclusive.
105Only one of those may be used.
106.Sh ENVIRONMENT
107When used to invoke
108.Pa rc.d
109scripts, the
110.Nm
111command sets
112.Xr umask 2
113to
114.Li 022 ,
115.Ev HOME
116to
117.Pa / ,
118and
119.Ev PATH
120to
121.Li /sbin:/bin:/usr/sbin:/usr/bin
122which is how they are set in
123.Pa /etc/rc
124at boot time.
125The
126.Ar action
127is typically one of
128.Cm start ,
129.Cm restart ,
130or
131.Cm status ,
132but can be any other argument supported by the
133.Fa rc_script_name .
134.Sh EXIT STATUS
135.Nm
136exits with status 0 when successful,
137status 1 when
138.Fl e
139was given and no enabled script was found,
140or when an
141.Ar action
142is to be performed, but the
143.Ar rc_script_name
144given does not exist,
145or
146status >1 if another error occurs.
147.Sh EXAMPLES
148These are typical usages of the
149.Nm
150command:
151.Bd -literal
152# service sshd restart
153Stopping sshd.
154Starting sshd.
155.Ed
156.Bd -literal
157$ service -v inetd status
158inetd is located in /etc/rc.d
159inetd is running as pid 1713.
160.Ed
161.Bd -literal
162$ if service -e inetd >/dev/null; then echo inetd is enabled; fi
163inetd is enabled
164.Ed
165.Bd -literal
166$ if service -e foobar >/dev/null; then echo foobar is enabled; fi
167.Ed
168.Bd -literal
169$ service -ve ccd motd hostapd my_pkg
170rc_directories is /etc/rc.d /usr/pkg/etc/rc.d
171/etc/rc.d/ccd
172/usr/pkg/etc/rc.d/my_pkg
173/etc/rc.d/motd
174.Ed
175.Pp
176In the last example,
177.Xr hostapd 8
178was apparently left disabled and the additional directory
179.Pa /usr/pkg/etc/rc.d
180was configured by redefining the variable
181.Dv rc_directories
182in
183.Pa rc.conf ;
184further,
185.Li my_pkg=yes
186must have also been set.
187.Sh SEE ALSO
188.Xr rc.conf 5 ,
189.Xr rc 8 ,
190.Xr rcorder 8
191.Sh HISTORY
192The
193.Nm
194utility first appeared in
195.Nx 7.0 .
196.Sh AUTHORS
197.An -nosplit
198Written for
199.Fx
200by
201.An Douglas Barton Aq Mt dougb@FreeBSD.org .
202.Pp
203Adapted and extended to
204.Nx
205by
206.An Adrian Steinmann Aq Mt ast@marabu.ch .
207