xref: /aosp_15_r20/external/openthread/tools/harness-simulation/posix/etc/commissionerd (revision cfb92d1480a9e65faed56933e9c12405f45898b4)
1#!/bin/sh
2#
3#  Copyright (c) 2022, The OpenThread Authors.
4#  All rights reserved.
5#
6#  Redistribution and use in source and binary forms, with or without
7#  modification, are permitted provided that the following conditions are met:
8#  1. Redistributions of source code must retain the above copyright
9#     notice, this list of conditions and the following disclaimer.
10#  2. Redistributions in binary form must reproduce the above copyright
11#     notice, this list of conditions and the following disclaimer in the
12#     documentation and/or other materials provided with the distribution.
13#  3. Neither the name of the copyright holder nor the
14#     names of its contributors may be used to endorse or promote products
15#     derived from this software without specific prior written permission.
16#
17#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27#  POSSIBILITY OF SUCH DAMAGE.
28#
29### BEGIN INIT INFO
30# Provides:          commissionerd
31# Required-Start:
32# Required-Stop:
33# Should-Start:
34# Should-Stop:
35# Default-Start:     2 3 4 5
36# Default-Stop:      0 1 6
37# Short-Description: OT-commissioner daemon
38# Description: OT-commissioner daemon
39### END INIT INFO
40
41set -e
42
43PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
44DESC="OT-commissioner daemon"
45NAME=commissionerd
46DAEMON=/usr/bin/python2
47PIDFILE=/var/run/commissionerd.pid
48
49# shellcheck source=/dev/null
50. /lib/lsb/init-functions
51# shellcheck source=/dev/null
52. /lib/init/vars.sh
53
54start_commissionerd()
55{
56    if [ -e $PIDFILE ]; then
57        if $0 status >/dev/null; then
58            log_success_msg "$DESC already started; not starting."
59            return
60        else
61            log_success_msg "Removing stale PID file $PIDFILE."
62            rm -f $PIDFILE
63        fi
64    fi
65
66    log_daemon_msg "Starting $DESC" "$NAME"
67    start-stop-daemon --start --quiet \
68        --pidfile $PIDFILE --make-pidfile \
69        -b --exec $DAEMON -- \
70        -u /usr/local/bin/commissionerd.py -c /usr/local/bin/commissioner-cli
71    log_end_msg $?
72}
73
74stop_commissionerd()
75{
76    log_daemon_msg "Stopping $DESC" "$NAME"
77    start-stop-daemon --stop --retry 5 --quiet --oknodo \
78        --pidfile $PIDFILE --remove-pidfile
79    log_end_msg $?
80}
81
82case "$1" in
83    start)
84        start_commissionerd
85        ;;
86    restart | reload | force-reload)
87        stop_commissionerd
88        start_commissionerd
89        ;;
90    stop | force-stop)
91        stop_commissionerd
92        ;;
93    status)
94        status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
95        ;;
96    *)
97        log_action_msg "Usage: /etc/init.d/$NAME {start | stop | status | restart | reload | force-reload}"
98        exit 2
99        ;;
100esac
101