···11+#!/bin/sh
22+33+###########################################################################
44+# /usr/bin/service
55+#
66+# A convenient wrapper for the /etc/init.d init scripts.
77+#
88+# This script is a modified version of the /sbin/service utility found on
99+# Red Hat/Fedora systems (licensed GPLv2+).
1010+#
1111+# Copyright (C) 2006 Red Hat, Inc. All rights reserved.
1212+# Copyright (C) 2008 Canonical Ltd.
1313+# * August 2008 - Dustin Kirkland <kirkland@canonical.com>
1414+# Copyright (C) 2013 Michael Stapelberg <stapelberg@debian.org>
1515+#
1616+# This program is free software; you can redistribute it and/or modify
1717+# it under the terms of the GNU General Public License as published by
1818+# the Free Software Foundation; either version 2 of the License, or
1919+# (at your option) any later version.
2020+#
2121+# This program is distributed in the hope that it will be useful,
2222+# but WITHOUT ANY WARRANTY; without even the implied warranty of
2323+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2424+# GNU General Public License for more details.
2525+#
2626+# You should have received a copy of the GNU General Public License
2727+# along with this program; if not, write to the Free Software
2828+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2929+#
3030+# On Debian GNU/Linux systems, the complete text of the GNU General
3131+# Public License can be found in `/usr/share/common-licenses/GPL-2'.
3232+###########################################################################
3333+3434+3535+is_ignored_file() {
3636+ case "$1" in
3737+ skeleton | README | *.dpkg-dist | *.dpkg-old | rc | rcS | single | reboot | bootclean.sh)
3838+ return 0
3939+ ;;
4040+ esac
4141+ return 1
4242+}
4343+4444+VERSION=$(@coreutils@/bin/basename $0)" ver. 0.91-ubuntu1"
4545+USAGE="Usage: "$(@coreutils@/bin/basename $0)" < option > | --status-all | \
4646+[ service_name [ command | --full-restart ] ]"
4747+SERVICE=
4848+ACTION=
4949+SERVICEDIR="/etc/init.d"
5050+OPTIONS=
5151+is_systemd=
5252+5353+5454+if [ $# -eq 0 ]; then
5555+ echo "${USAGE}" >&2
5656+ exit 1
5757+fi
5858+5959+if [ -d /run/systemd/system ]; then
6060+ is_systemd=1
6161+fi
6262+6363+cd /
6464+while [ $# -gt 0 ]; do
6565+ case "${1}" in
6666+ --help | -h | --h* )
6767+ echo "${USAGE}" >&2
6868+ exit 0
6969+ ;;
7070+ --version | -V )
7171+ echo "${VERSION}" >&2
7272+ exit 0
7373+ ;;
7474+ *)
7575+ if [ -z "${SERVICE}" -a $# -eq 1 -a "${1}" = "--status-all" ]; then
7676+ if [ -d "${SERVICEDIR}" ]; then
7777+ cd ${SERVICEDIR}
7878+ for SERVICE in * ; do
7979+ case "${SERVICE}" in
8080+ functions | halt | killall | single| linuxconf| kudzu)
8181+ ;;
8282+ *)
8383+ if ! is_ignored_file "${SERVICE}" \
8484+ && [ -x "${SERVICEDIR}/${SERVICE}" ]; then
8585+ 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)
8686+ retval=$?
8787+ if echo "$out" | egrep -iq "usage:"; then
8888+ #printf " %s %-60s %s\n" "[?]" "$SERVICE:" "unknown" 1>&2
8989+ echo " [ ? ] $SERVICE" 1>&2
9090+ continue
9191+ else
9292+ if [ "$retval" = "0" -a -n "$out" ]; then
9393+ #printf " %s %-60s %s\n" "[+]" "$SERVICE:" "running"
9494+ echo " [ + ] $SERVICE"
9595+ continue
9696+ else
9797+ #printf " %s %-60s %s\n" "[-]" "$SERVICE:" "NOT running"
9898+ echo " [ - ] $SERVICE"
9999+ continue
100100+ fi
101101+ fi
102102+ #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
103103+ fi
104104+ ;;
105105+ esac
106106+ done
107107+ else
108108+ systemctl $sctl_args list-units
109109+ fi
110110+ exit 0
111111+ elif [ $# -eq 2 -a "${2}" = "--full-restart" ]; then
112112+ SERVICE="${1}"
113113+ # On systems using systemd, we just perform a normal restart:
114114+ # A restart with systemd is already a full restart.
115115+ if [ -n "$is_systemd" ]; then
116116+ ACTION="restart"
117117+ else
118118+ if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
119119+ 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
120120+ 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
121121+ exit $?
122122+ fi
123123+ fi
124124+ elif [ -z "${SERVICE}" ]; then
125125+ SERVICE="${1}"
126126+ elif [ -z "${ACTION}" ]; then
127127+ ACTION="${1}"
128128+ else
129129+ OPTIONS="${OPTIONS} ${1}"
130130+ fi
131131+ shift
132132+ ;;
133133+ esac
134134+done
135135+136136+# Operate against system upstart, not session
137137+unset UPSTART_SESSION
138138+if [ -r "/etc/init/${SERVICE}.conf" ] && which initctl >/dev/null \
139139+ && initctl version 2>/dev/null | grep -q upstart \
140140+ && initctl status ${SERVICE} 2>/dev/null 1>/dev/null
141141+then
142142+ # Upstart configuration exists for this job and we're running on upstart
143143+ case "${ACTION}" in
144144+ start|stop|status|reload)
145145+ # Action is a valid upstart action
146146+ exec ${ACTION} ${SERVICE} ${OPTIONS}
147147+ ;;
148148+ restart|force-reload)
149149+ # Map restart to the usual sysvinit behavior.
150150+ # Map force-reload to restart as per Debian policy 9.3.2,
151151+ # since there is no way to know if "reload" is supported
152152+ stop ${SERVICE} ${OPTIONS} || :
153153+ exec start ${SERVICE} ${OPTIONS}
154154+ ;;
155155+ esac
156156+fi
157157+158158+159159+run_via_sysvinit() {
160160+ # Otherwise, use the traditional sysvinit
161161+ if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
162162+ 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}
163163+ else
164164+ echo "${SERVICE}: unrecognized service" >&2
165165+ exit 1
166166+ fi
167167+}
168168+169169+update_openrc_started_symlinks() {
170170+ # maintain the symlinks of /run/openrc/started so that
171171+ # rc-status works with the service command as well
172172+ if [ -d /run/openrc/started ] ; then
173173+ case "${ACTION}" in
174174+ start)
175175+ if [ ! -h /run/openrc/started/$SERVICE ] ; then
176176+ ln -s $SERVICEDIR/$SERVICE /run/openrc/started/$SERVICE || true
177177+ fi
178178+ ;;
179179+ stop)
180180+ rm /run/openrc/started/$SERVICE || true
181181+ ;;
182182+ esac
183183+ fi
184184+}
185185+186186+# When this machine is running systemd, standard service calls are turned into
187187+# systemctl calls.
188188+if [ -n "$is_systemd" ]
189189+then
190190+ UNIT="${SERVICE%.sh}.service"
191191+ # avoid deadlocks during bootup and shutdown from units/hooks
192192+ # which call "invoke-rc.d service reload" and similar, since
193193+ # the synchronous wait plus systemd's normal behaviour of
194194+ # transactionally processing all dependencies first easily
195195+ # causes dependency loops
196196+ if ! systemctl --quiet is-active multi-user.target; then
197197+ sctl_args="--job-mode=ignore-dependencies"
198198+ fi
199199+200200+ case "${ACTION}" in
201201+ restart|status)
202202+ exec systemctl $sctl_args ${ACTION} ${UNIT}
203203+ ;;
204204+ start|stop)
205205+ # Follow the principle of least surprise for SysV people:
206206+ # When running "service foo stop" and foo happens to be a service that
207207+ # has one or more .socket files, we also stop the .socket units.
208208+ # Users who need more control will use systemctl directly.
209209+ for unit in $(systemctl list-unit-files --full --type=socket 2>/dev/null | sed -ne 's/\.socket\s*[a-z]*\s*$/.socket/p'); do
210210+ if [ "$(systemctl -p Triggers show $unit)" = "Triggers=${UNIT}" ]; then
211211+ systemctl $sctl_args ${ACTION} $unit
212212+ fi
213213+ done
214214+ exec systemctl $sctl_args ${ACTION} ${UNIT}
215215+ ;;
216216+ reload)
217217+ _canreload="$(SYSTEMCTL -p CanReload show ${UNIT} 2>/dev/null)"
218218+ if [ "$_canreload" = "CanReload=no" ]; then
219219+ # The reload action falls back to the sysv init script just in case
220220+ # the systemd service file does not (yet) support reload for a
221221+ # specific service.
222222+ run_via_sysvinit
223223+ else
224224+ exec systemctl $sctl_args reload "${UNIT}"
225225+ fi
226226+ ;;
227227+ force-stop)
228228+ exec systemctl --signal=KILL kill "${UNIT}"
229229+ ;;
230230+ force-reload)
231231+ _canreload="$(systemctl -p CanReload show ${UNIT} 2>/dev/null)"
232232+ if [ "$_canreload" = "CanReload=no" ]; then
233233+ exec systemctl $sctl_args restart "${UNIT}"
234234+ else
235235+ exec systemctl $sctl_args reload "${UNIT}"
236236+ fi
237237+ ;;
238238+ *)
239239+ # We try to run non-standard actions by running
240240+ # the init script directly.
241241+ run_via_sysvinit
242242+ ;;
243243+ esac
244244+fi
245245+246246+update_openrc_started_symlinks
247247+run_via_sysvinit