3 ###########################################################################
6 # A convenient wrapper for the /etc/init.d init scripts.
8 # This script is a modified version of the /sbin/service utility found on
9 # Red Hat/Fedora systems (licensed GPLv2+).
11 # Copyright (C) 2006 Red Hat, Inc. All rights reserved.
12 # Copyright (C) 2008 Canonical Ltd.
13 # * August 2008 - Dustin Kirkland <kirkland@canonical.com>
14 # Copyright (C) 2013 Michael Stapelberg <stapelberg@debian.org>
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 # On Debian GNU/Linux systems, the complete text of the GNU General
31 # Public License can be found in `/usr/share/common-licenses/GPL-2'.
32 ###########################################################################
37 skeleton | README |
*.dpkg-dist |
*.dpkg-old | rc | rcS | single | reboot | bootclean.sh
)
44 VERSION
=$
(@coreutils@
/bin
/basename $0)" ver. 19-04"
45 USAGE
="Usage: "$
(@coreutils@
/bin
/basename $0)" < option > | --status-all | \
46 [ service_name [ command | --full-restart ] ]"
49 SERVICEDIR
="/etc/init.d"
59 if [ -d /run
/systemd
/system
]; then
64 while [ $# -gt 0 ]; do
75 if [ -z "${SERVICE}" -a $# -eq 1 -a "${1}" = "--status-all" ]; then
76 if [ -d "${SERVICEDIR}" ]; then
80 functions | halt | killall | single| linuxconf| kudzu
)
83 if ! is_ignored_file
"${SERVICE}" \
84 && [ -x "${SERVICEDIR}/${SERVICE}" ]; then
85 out
=$
(env
-i LANG
="$LANG" LANGUAGE
="$LANGUAGE" LC_CTYPE
="$LC_CTYPE" LC_NUMERIC
="$LC_NUMERIC" LC_TIME
="$LC_TIME" LC_COLLATE
="$LC_COLLATE" LC_MONETARY
="$LC_MONETARY" LC_MESSAGES
="$LC_MESSAGES" LC_PAPER
="$LC_PAPER" LC_NAME
="$LC_NAME" LC_ADDRESS
="$LC_ADDRESS" LC_TELEPHONE
="$LC_TELEPHONE" LC_MEASUREMENT
="$LC_MEASUREMENT" LC_IDENTIFICATION
="$LC_IDENTIFICATION" LC_ALL
="$LC_ALL" PATH
="$PATH" TERM
="$TERM" "$SERVICEDIR/$SERVICE" status
2>&1)
87 if echo "$out" |
egrep -iq "usage:"; then
88 #printf " %s %-60s %s\n" "[?]" "$SERVICE:" "unknown" 1>&2
89 echo " [ ? ] $SERVICE" 1>&2
92 if [ "$retval" = "0" -a -n "$out" ]; then
93 #printf " %s %-60s %s\n" "[+]" "$SERVICE:" "running"
94 echo " [ + ] $SERVICE"
97 #printf " %s %-60s %s\n" "[-]" "$SERVICE:" "NOT running"
98 echo " [ - ] $SERVICE"
102 #env -i LANG="$LANG" LANGUAGE="$LANGUAGE" LC_CTYPE="$LC_CTYPE" LC_NUMERIC="$LC_NUMERIC" LC_TIME="$LC_TIME" LC_COLLATE="$LC_COLLATE" LC_MONETARY="$LC_MONETARY" LC_MESSAGES="$LC_MESSAGES" LC_PAPER="$LC_PAPER" LC_NAME="$LC_NAME" LC_ADDRESS="$LC_ADDRESS" LC_TELEPHONE="$LC_TELEPHONE" LC_MEASUREMENT="$LC_MEASUREMENT" LC_IDENTIFICATION="$LC_IDENTIFICATION" LC_ALL="$LC_ALL" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status
108 systemctl
$sctl_args list-units
111 elif [ $# -eq 2 -a "${2}" = "--full-restart" ]; then
113 # On systems using systemd, we just perform a normal restart:
114 # A restart with systemd is already a full restart.
115 if [ -n "$is_systemd" ]; then
118 if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
119 env
-i LANG
="$LANG" LANGUAGE
="$LANGUAGE" LC_CTYPE
="$LC_CTYPE" LC_NUMERIC
="$LC_NUMERIC" LC_TIME
="$LC_TIME" LC_COLLATE
="$LC_COLLATE" LC_MONETARY
="$LC_MONETARY" LC_MESSAGES
="$LC_MESSAGES" LC_PAPER
="$LC_PAPER" LC_NAME
="$LC_NAME" LC_ADDRESS
="$LC_ADDRESS" LC_TELEPHONE
="$LC_TELEPHONE" LC_MEASUREMENT
="$LC_MEASUREMENT" LC_IDENTIFICATION
="$LC_IDENTIFICATION" LC_ALL
="$LC_ALL" PATH
="$PATH" TERM
="$TERM" "$SERVICEDIR/$SERVICE" stop
120 env
-i LANG
="$LANG" LANGUAGE
="$LANGUAGE" LC_CTYPE
="$LC_CTYPE" LC_NUMERIC
="$LC_NUMERIC" LC_TIME
="$LC_TIME" LC_COLLATE
="$LC_COLLATE" LC_MONETARY
="$LC_MONETARY" LC_MESSAGES
="$LC_MESSAGES" LC_PAPER
="$LC_PAPER" LC_NAME
="$LC_NAME" LC_ADDRESS
="$LC_ADDRESS" LC_TELEPHONE
="$LC_TELEPHONE" LC_MEASUREMENT
="$LC_MEASUREMENT" LC_IDENTIFICATION
="$LC_IDENTIFICATION" LC_ALL
="$LC_ALL" PATH
="$PATH" TERM
="$TERM" "$SERVICEDIR/$SERVICE" start
124 elif [ -z "${SERVICE}" ]; then
126 elif [ -z "${ACTION}" ]; then
129 OPTIONS
="${OPTIONS} ${1}"
137 # Otherwise, use the traditional sysvinit
138 if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
139 exec env
-i LANG
="$LANG" LANGUAGE
="$LANGUAGE" LC_CTYPE
="$LC_CTYPE" LC_NUMERIC
="$LC_NUMERIC" LC_TIME
="$LC_TIME" LC_COLLATE
="$LC_COLLATE" LC_MONETARY
="$LC_MONETARY" LC_MESSAGES
="$LC_MESSAGES" LC_PAPER
="$LC_PAPER" LC_NAME
="$LC_NAME" LC_ADDRESS
="$LC_ADDRESS" LC_TELEPHONE
="$LC_TELEPHONE" LC_MEASUREMENT
="$LC_MEASUREMENT" LC_IDENTIFICATION
="$LC_IDENTIFICATION" LC_ALL
="$LC_ALL" PATH
="$PATH" TERM
="$TERM" "$SERVICEDIR/$SERVICE" ${ACTION} ${OPTIONS}
141 echo "${SERVICE}: unrecognized service" >&2
146 update_openrc_started_symlinks
() {
147 # maintain the symlinks of /run/openrc/started so that
148 # rc-status works with the service command as well
149 if [ -d /run
/openrc
/started
] ; then
152 if [ ! -h /run
/openrc
/started
/$SERVICE ] ; then
153 ln -s $SERVICEDIR/$SERVICE /run
/openrc
/started
/$SERVICE || true
157 rm /run
/openrc
/started
/$SERVICE || true
163 # When this machine is running systemd, standard service calls are turned into
165 if [ -n "$is_systemd" ]
167 UNIT
="${SERVICE%.sh}.service"
168 # avoid deadlocks during bootup and shutdown from units/hooks
169 # which call "invoke-rc.d service reload" and similar, since
170 # the synchronous wait plus systemd's normal behaviour of
171 # transactionally processing all dependencies first easily
172 # causes dependency loops
173 if ! systemctl
--quiet is-active multi-user.target
; then
174 sctl_args
="--job-mode=ignore-dependencies"
178 restart|status|try-restart
)
179 exec systemctl
$sctl_args ${ACTION} ${UNIT}
182 # Follow the principle of least surprise for SysV people:
183 # When running "service foo stop" and foo happens to be a service that
184 # has one or more .socket files, we also stop the .socket units.
185 # Users who need more control will use systemctl directly.
186 for unit
in $
(systemctl list-unit-files
--full --type=socket
2>/dev
/null |
sed -ne 's/\.socket\s*[a-z]*\s*$/.socket/p'); do
187 if [ "$(systemctl -p Triggers show $unit)" = "Triggers=${UNIT}" ]; then
188 systemctl
$sctl_args ${ACTION} $unit
191 exec systemctl
$sctl_args ${ACTION} ${UNIT}
194 _canreload
="$(systemctl -p CanReload show ${UNIT} 2>/dev/null)"
195 if [ "$_canreload" = "CanReload=no" ]; then
196 # The reload action falls back to the sysv init script just in case
197 # the systemd service file does not (yet) support reload for a
201 exec systemctl
$sctl_args reload
"${UNIT}"
205 exec systemctl
--signal=KILL
kill "${UNIT}"
208 _canreload
="$(systemctl -p CanReload show ${UNIT} 2>/dev/null)"
209 if [ "$_canreload" = "CanReload=no" ]; then
210 exec systemctl
$sctl_args restart
"${UNIT}"
212 exec systemctl
$sctl_args reload
"${UNIT}"
216 # We try to run non-standard actions by running
217 # the init script directly.
223 update_openrc_started_symlinks