NBash

Форк
0
110 строк · 3.4 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2012, 2013, 2016, 2017, 2021  Etersoft
4
# Copyright (C) 2012, 2013, 2016, 2017, 2021  Vitaly Lipatov <lav@etersoft.ru>
5
#
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Affero General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Affero General Public License for more details.
15
#
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#
19

20
# FIXME: sudo ask password, but we do not print command before
21
is_service_running()
22
{
23
    local SERVICE="$1"
24
    local OUTPUT
25
    # TODO: real status can be checked only with grep output
26
    case $SERVICETYPE in
27
        service-chkconfig|service-upstart)
28
            if is_anyservice $1 ; then
29
                OUTPUT="$(sudorun anyservice $1 status 2>/dev/null)" || return 1
30
                echo "$OUTPUT" | grep -q "is stopped" && return 1
31
                return 0
32
            fi
33
            OUTPUT="$(sudorun service $1 status 2>/dev/null)" || return 1
34
            echo "$OUTPUT" | grep -q "is stopped" && return 1
35
            return 0
36
            ;;
37
        service-initd|service-update)
38
            sudorun $INITDIR/$1 status >/dev/null 2>/dev/null
39
            ;;
40
        systemd)
41
            a='' systemctl status $1 >/dev/null 2>/dev/null
42
            ;;
43
        runit)
44
            sudorun sv status "$SERVICE" >/dev/null 2>/dev/null
45
            ;;
46
        *)
47
            fatal "Have no suitable command for $SERVICETYPE"
48
            ;;
49
    esac
50
}
51

52
# FIXME: sudo ask password, but we do not print command before
53
is_service_autostart()
54
{
55
    local SERVICE="$1"
56

57
    case $SERVICETYPE in
58
        service-chkconfig|service-upstart)
59
            if is_anyservice $SERVICE; then
60
                $ANYSERVICE $SERVICE isautostarted
61
                return
62
            fi
63

64
            # FIXME: check for current runlevel
65
            LC_ALL=C sudorun chkconfig $1 --list | grep -q "[35]:on"
66
            ;;
67
        service-initd|service-update)
68
            test -L "$(echo /etc/rc5.d/S??$1)"
69
            ;;
70
        systemd)
71
            a='' systemctl is-enabled $1
72
            ;;
73
        runit)
74
            test -L "/var/service/$SERVICE"
75
            ;;
76
        *)
77
            fatal "Have no suitable command for $SERVICETYPE"
78
            ;;
79
    esac
80
}
81

82
serv_status()
83
{
84
    is_service_autostart $1 && echo "Service $1 is scheduled to run on startup" || echo "Service $1 will NOT run on startup"
85

86
    local SERVICE="$1"
87
    shift
88

89
    case $SERVICETYPE in
90
        service-chkconfig|service-upstart)
91
            if is_anyservice $SERVICE ; then
92
                sudocmd anyservice $SERVICE status
93
                return
94
            fi
95
            sudocmd service $SERVICE status "$@"
96
            ;;
97
        service-update)
98
            sudocmd $INITDIR/$SERVICE status "$@"
99
            ;;
100
        systemd)
101
            docmd systemctl -l status $SERVICE "$@"
102
            ;;
103
        runit)
104
            sudocmd sv status "$SERVICE"
105
            ;;
106
        *)
107
            fatal "Have no suitable command for $SERVICETYPE"
108
            ;;
109
    esac
110
}
111

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.