summaryrefslogtreecommitdiff
path: root/etc/llmnrd-init-script
blob: 82ecc4e8242cf96725eb7df99a3cb954eae38d74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/sh
#
# License: Copyright 2020 SpinetiX. This file is licensed
#          under the terms of the GNU General Public License version 2.
#          This program is licensed "as is" without any warranty of any
#          kind, whether express or implied.
#
# Copyright 1999-2003 MontaVista Software, Inc.
# Copyright 2002, 2003, 2004 Sony Corporation
# Copyright 2002, 2003, 2004 Matsushita Electric Industrial Co., Ltd.
#
### BEGIN INIT INFO
# Required-Start:
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 5
# Default-Stop:
# Short-Description: Starting/stopping llmnrd
# Description: Starting/stopping llmnrd
### END INIT INFO

# Init script information
NAME=llmnrd
DESC="llmnrd"

# Individual Daemon information
DAEMON=/usr/sbin/llmnrd
ARGS="-6 -d -s"
BASENAME=llmnrd

# Load init script configuration
DISABLE_LLMNRD=
[ -f /etc/default/$NAME ] && . /etc/default/$NAME

# Source the init script functions
. /etc/init.d/functions

# Verify daemons are installed
if [ ! -x $DAEMON -a "$1" != "stop" ]; then
    echo -n "Not starting $DESC $NAME, $DAEMON not installed"
    echo
    exit 0
fi

if [ -n "$DISABLE_LLMNRD" -a "$1" != "stop" ]; then
    echo -n "Not starting $DESC $NAME, disabled via /etc/default/$NAME"
    echo
    exit 0
fi

start() {
    local RET

    echo -n "Starting $DESC: "

    echo -n "$NAME "

    start-stop-daemon --start -u llmnrd -n llmnrd -p /run/llmnrd/pid -c llmnrd -x $DAEMON -- $ARGS
    RET=$?
    if [ $RET -eq 0 ]; then
        success; echo
    else
        failure; echo
        return 1
    fi
        
    return 0
}

stop () {
    local RET

    echo -n "Stopping $DESC: $NAME "
    start-stop-daemon --stop -u llmnrd -n llmnrd -p /run/llmnrd/pid -q
    RET=$?
    if [ $RET -eq 0 ]; then
        success; echo
    else
        failure; echo
        return 1
    fi

    return 0
}

restart() {
    local RET

    echo "Restarting $DESC..."
    stop
    start
    RET=$?

    return $RET
}

condrestart() {
    local RET

    pidofproc $BASENAME >/dev/null
    RET=$?
    if [ $RET -eq 0 ]; then
        restart
        RET=$?
    else
        RET=1
    fi

    return $RET
}

reload() {
    local RET pid

    # llmnrd has no support for HUP, so just restart
    condrestart
}

forcereload() {
    local RET

    reload
    RET=$?
    if [ $RET -ne 0 ]; then
        restart
        RET=$?
    fi

    return $RET
}

parse() {
    case "$1" in
        start)
            start
            return $?
            ;;
        stop)
            stop
            return $?
            ;;
        restart)
            restart
            return $?
            ;;
        condrestart|try-restart)
            condrestart
            return $?
            ;;
        reload)
            reload
            return $?
            ;;
        force-reload)
            forcereload
            return $?
            ;;
        status)
            status $BASENAME
            return $?
            ;;
        *)
            echo "Usage: $NAME " \
                "{start|stop|restart|condrestart|reload|force-reload|status}" >&2
            ;;
    esac

    return 1
}

parse $@