Tizen 2.1 base
[platform/upstream/sysvinit.git] / packaging / service
1 #!/bin/sh
2
3 ###########################################################################
4 # /usr/bin/service
5 #
6 # A convenient wrapper for the /etc/init.d init scripts.
7 #
8 # This script is a modified version of the /sbin/service utility found on
9 # Red Hat/Fedora systems (licensed GPLv2+).
10 #
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 #
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation; either version 2 of the License, or
18 # (at your option) any later version.
19 #
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28 #
29 # On Debian GNU/Linux systems, the complete text of the GNU General
30 # Public License can be found in `/usr/share/common-licenses/GPL-2'.
31 ###########################################################################
32
33
34 is_ignored_file() {
35         case "$1" in
36                 skeleton | README | *.dpkg-dist | *.dpkg-old | rc | rcS | single | reboot | bootclean.sh)
37                         return 0
38                 ;;
39         esac
40         return 1
41 }
42
43 VERSION="`basename $0` ver. 0.91-ubuntu1"
44 USAGE="Usage: `basename $0` < option > | --status-all | \
45 [ service_name [ command | --full-restart ] ]"
46 SERVICE=
47 SERVICEDIR="/etc/init.d"
48 OPTIONS=
49
50 if [ $# -eq 0 ]; then
51    echo "${USAGE}" >&2
52    exit 1
53 fi
54
55 cd /
56 while [ $# -gt 0 ]; do
57   case "${1}" in
58     --help | -h | --h* )
59        echo "${USAGE}" >&2
60        exit 0
61        ;;
62     --version | -V )
63        echo "${VERSION}" >&2
64        exit 0
65        ;;
66     *)
67        if [ -z "${SERVICE}" -a $# -eq 1 -a "${1}" = "--status-all" ]; then
68           cd ${SERVICEDIR}
69           for SERVICE in * ; do
70             case "${SERVICE}" in
71               functions | halt | killall | single| linuxconf| kudzu)
72                   ;;
73               *)
74                 if ! is_ignored_file "${SERVICE}" \
75                     && [ -x "${SERVICEDIR}/${SERVICE}" ]; then
76                         if ! grep -qs "\Wstatus)" "$SERVICE"; then
77                           #printf " %s %-60s %s\n" "[?]" "$SERVICE:" "unknown" 1>&2
78                           echo " [ ? ]  $SERVICE" 1>&2
79                           continue
80                         else
81                           out=$(env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status 2>&1)
82                           if [ "$?" = "0" -a -n "$out" ]; then
83                             #printf " %s %-60s %s\n" "[+]" "$SERVICE:" "running"
84                             echo " [ + ]  $SERVICE"
85                             continue
86                           else
87                             #printf " %s %-60s %s\n" "[-]" "$SERVICE:" "NOT running"
88                             echo " [ - ]  $SERVICE"
89                             continue
90                           fi
91                         fi
92                   #env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status
93                 fi
94                 ;;
95             esac
96           done
97           exit 0
98        elif [ $# -eq 2 -a "${2}" = "--full-restart" ]; then
99           SERVICE="${1}"
100           if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
101             env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" stop
102             env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" start
103             exit $?
104           fi
105        elif [ -z "${SERVICE}" ]; then
106          SERVICE="${1}"
107        else
108          OPTIONS="${OPTIONS} ${1}"
109        fi
110        shift
111        ;;
112    esac
113 done
114
115 if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
116    env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" ${OPTIONS}
117 else
118    echo "${SERVICE}: unrecognized service" >&2
119    exit 1
120 fi