forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-02-17 557c24d082b6ecb9bfe5407b77ae43fa7650a5dc
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/sh
#
# collectd - start and stop the statistics collection daemon
# http://collectd.org/
#
# Copyright (C) 2005-2006 Florian Forster <octo@verplant.org>
# Copyright (C) 2006-2009 Sebastian Harl <tokkee@debian.org>
#
 
### BEGIN INIT INFO
# Provides:          collectd
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs
# Should-Start:      $network $named $syslog $time cpufrequtils
# Should-Stop:       $network $named $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: manage the statistics collection daemon
# Description:       collectd is the statistics collection daemon.
#                    It is a small daemon which collects system information
#                    periodically and provides mechanisms to monitor and store
#                    the values in a variety of ways.
### END INIT INFO
 
. /etc/init.d/functions
 
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
 
DISABLE=0
 
NAME=collectd
DAEMON=/usr/sbin/collectd
 
CONFIGFILE=/etc/collectd.conf
PIDFILE=/var/run/collectd.pid
 
USE_COLLECTDMON=1
COLLECTDMON_DAEMON=/usr/sbin/collectdmon
COLLECTDMON_PIDFILE=/var/run/collectdmon.pid
 
MAXWAIT=30
 
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
 
if [ -r /etc/default/$NAME ]; then
   . /etc/default/$NAME
fi
 
if test "$ENABLE_COREFILES" = 1; then
   ulimit -c unlimited
fi
 
if test "$USE_COLLECTDMON" = 1; then
   _PIDFILE="$COLLECTDMON_PIDFILE"
else
   _PIDFILE="$PIDFILE"
fi
 
# return:
#   0 if config is fine
#   1 if there is a syntax error
#   2 if there is no configuration
check_config() {
   if test ! -e "$CONFIGFILE"; then
       return 2
   fi
   if ! $DAEMON -t -C "$CONFIGFILE"; then
       return 1
   fi
   return 0
}
 
# return:
#   0 if the daemon has been started
#   1 if the daemon was already running
#   2 if the daemon could not be started
#   3 if the daemon was not supposed to be started
d_start() {
   if test "$DISABLE" != 0; then
       # we get here during restart
       echo "disabled by /etc/default/$NAME"
       return 3
   fi
 
   if test ! -e "$CONFIGFILE"; then
       # we get here during restart
       echo "disabled, no configuration ($CONFIGFILE) found"
       return 3
   fi
 
   check_config
   rc="$?"
   if test "$rc" -ne 0; then
       echo "not starting, configuration error"
       return 2
   fi
 
   if test "$USE_COLLECTDMON" = 1; then
       start-stop-daemon --start --quiet --oknodo --pidfile "$_PIDFILE" \
           --exec $COLLECTDMON_DAEMON -- -P "$_PIDFILE" -- -C "$CONFIGFILE" \
           || return 2
   else
       start-stop-daemon --start --quiet --oknodo --pidfile "$_PIDFILE" \
           --exec $DAEMON -- -C "$CONFIGFILE" -P "$_PIDFILE" \
           || return 2
   fi
   return 0
}
 
still_running_warning="
WARNING: $NAME might still be running.
In large setups it might take some time to write all pending data to
the disk. You can adjust the waiting time in /etc/default/collectd."
 
# return:
#   0 if the daemon has been stopped
#   1 if the daemon was already stopped
#   2 if daemon could not be stopped
d_stop() {
   PID=$( cat "$_PIDFILE" 2> /dev/null ) || true
 
   start-stop-daemon --stop --quiet --oknodo --pidfile "$_PIDFILE"
   rc="$?"
 
   if test "$rc" -eq 2; then
       return 2
   fi
 
   sleep 1
   if test -n "$PID" && kill -0 $PID 2> /dev/null; then
       i=0
       while kill -0 $PID 2> /dev/null; do
           i=$(( $i + 2 ))
           echo -n " ."
 
           if test $i -gt $MAXWAIT; then
               echo "$still_running_warning"
               return 2
           fi
 
           sleep 2
       done
       return "$rc"
   fi
   return "$rc"
}
 
# return:
#   0 if the daemon is running
#   3 if the daemon is stopped
d_status(){
   if test "$USE_COLLECTDMON" = 1; then
       status $COLLECTDMON_DAEMON
   else
       status $DAEMON
   fi
}
 
case "$1" in
   start)
       echo -n "Starting $NAME"
       d_start
       case "$?" in
           0|1) echo "." ;;
           *) exit 1 ;;
       esac
       ;;
   stop)
       echo -n "Stopping $NAME"
       d_stop
       case "$?" in
           0|1) echo "." ;;
           *) exit 1 ;;
       esac
       ;;
   status)
       d_status
       ;;
   restart|force-reload)
       echo -n "Restarting $NAME"
       check_config
       rc="$?"
       if test "$rc" -eq 1; then
           echo "not restarting, configuration error"
           exit 1
       fi
       d_stop
       rc="$?"
       case "$rc" in
           0|1)
               sleep 1
               d_start
               rc2="$?"
               case "$rc2" in
                   0|1) echo "." ;;
                   *) exit 1 ;;
               esac
               ;;
           *)
               exit 1
               ;;
       esac
       ;;
   *)
       echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
       exit 3
       ;;
esac
 
# vim: syntax=sh noexpandtab sw=4 ts=4 :