SERVICE(8) | System Manager's Manual | SERVICE(8) |
service
— run or
list system services
service |
[-elv ] |
service |
[-ev ] rc_script_name
[rc_script_name ...] |
service |
[-v ] rc_script_name
action |
The service
command is a simple interface
to the services startup system.
Its purpose is to list the services or invoke actions on them as
provided by the rc.d(8) scripts.
When used to invoke rc.d scripts,
service
will set the same environment that is used
at boot time.
The options are as follows:
-e
rcvar
assignment and if
present, checked to see if it is enabled. If one or more
rc_script_name are specified, only those are
checked. The rc_script_name arguments are always
specified without a path prefix.-l
rc_directories
as defined in
rc.conf(5)). A script will
be listed unless it has the nostart
keyword
enabled. Scripts are listed in the order the rc.d
system runs them at system boot time.-v
rc_directories
are defined or in which
directory the rc.d script was found when an
action is invoked.The -e
and -l
options are mutually exclusive. Only one of those may be used.
When used to invoke rc.d scripts, the
service
command sets
umask(2) to
022
, HOME
to
/, and PATH
to
/sbin:/bin:/usr/sbin:/usr/bin
which is how they are
set in /etc/rc at boot time. The
action is typically one of
start
, restart
, or
status
, but can be any other argument supported by
the rc_script_name.
service
exits with status 0 when
successful, status 1 when -e
was given and no
enabled script was found, or when an action is to be
performed, but the rc_script_name given does not
exist, or status >1 if another error occurs.
These are typical usages of the service
command:
# service sshd restart Stopping sshd. Starting sshd.
$ service -v inetd status inetd is located in /etc/rc.d inetd is running as pid 1713.
$ if service -e inetd >/dev/null; then echo inetd is enabled; fi inetd is enabled
$ if service -e foobar >/dev/null; then echo foobar is enabled; fi
$ service -ve ccd motd hostapd my_pkg rc_directories is /etc/rc.d /usr/pkg/etc/rc.d /etc/rc.d/ccd /usr/pkg/etc/rc.d/my_pkg /etc/rc.d/motd
In the last example,
hostapd(8) was apparently
left disabled and the additional directory
/usr/pkg/etc/rc.d was configured by redefining the
variable rc_directories
in
rc.conf; further, my_pkg=yes
must have also been set.
The service
utility first appeared in
NetBSD 7.0.
Written for FreeBSD by Douglas Barton <dougb@FreeBSD.org>.
Adapted and extended to NetBSD by Adrian Steinmann <ast@marabu.ch>.
March 12, 2023 | NetBSD 10.99 |