Skip to content

Commit 68202c4

Browse files
committed
Added ubuntu init.d example config
1 parent 41a5c25 commit 68202c4

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

contrib/beaver-init.d

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/bash -
2+
### BEGIN INIT INFO
3+
# Provides: beaver
4+
# Required-Start: $local_fs $remote_fs $network
5+
# Required-Stop: $local_fs $remote_fs $network
6+
# Default-Start: 2 3 4 5
7+
# Default-Stop: 0 1 6
8+
# Short-Description: Start up the Beaver at boot time
9+
# Description: Enable Log Sender provided by beaver.
10+
### END INIT INFO
11+
12+
13+
BEAVER_NAME='beaver'
14+
BEAVER_CMD='beaver -t stdout -c /etc/beaver/beaver.conf'
15+
BEAVER_PID='/var/run/logstash_beaver.pid'
16+
BEAVER_USER='beaver'
17+
BEAVER_LOG='/var/log/logstash_beaver.log'
18+
19+
20+
PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
21+
export PATH
22+
IFS=$' \t\n'
23+
export IFS
24+
25+
BEAVER_BIN="$(which "${BEAVER_NAME}")"
26+
27+
[ -r /etc/init.d/functions ] && . /etc/init.d/functions
28+
[ -r /lib/lsb/init-functions ] && . /lib/lsb/init-functions
29+
[ -r "/etc/default/${BEAVER_NAME}" ] && . "/etc/default/${BEAVER_NAME}"
30+
31+
do_start() {
32+
test -f "${BEAVER_BIN}" || exit 0
33+
if is_up
34+
then
35+
echo $'Log Sender server daemon already started.'
36+
return 0
37+
fi
38+
echo -n $"Log Sender server daemon: ${BEAVER_NAME}"
39+
su - "${BEAVER_USER}" -s '/bin/bash' -c "${BEAVER_CMD} >> ${BEAVER_LOG} 2>&1 & echo \$! > ${BEAVER_PID}"
40+
echo '.'
41+
}
42+
43+
do_stop() {
44+
test -f "${BEAVER_BIN}" || exit 0
45+
if ! is_up
46+
then
47+
echo $'Log Sender server daemon already stopped.'
48+
return 0
49+
fi
50+
echo -n $"Stopping Log Sender server daemon: ${BEAVER_NAME}"
51+
do_kill
52+
while is_up
53+
do
54+
echo -n '.'
55+
sleep 1
56+
done
57+
echo '.'
58+
}
59+
60+
beaver_pid() {
61+
tail -1 "${BEAVER_PID}" 2> /dev/null
62+
}
63+
64+
is_up() {
65+
PID="$(beaver_pid)"
66+
[ x"${PID}" != x ] && ps -p "${PID}" -o comm h 2> /dev/null | grep -qFw "${BEAVER_NAME}"
67+
}
68+
69+
do_kill() {
70+
PID="$(beaver_pid)"
71+
[ x"${PID}" != x ] && su - "${BEAVER_USER}" -c "kill -TERM ${PID}"
72+
}
73+
74+
do_restart() {
75+
test -f "${BEAVER_BIN}" || exit 0
76+
do_stop
77+
sleep 1
78+
do_start
79+
}
80+
81+
do_status() {
82+
test -f "${BEAVER_BIN}" || exit 0
83+
if is_up
84+
then
85+
echo "${BEAVER_NAME} is running."
86+
exit 0
87+
else
88+
echo "${BEAVER_NAME} is not running."
89+
exit 1
90+
fi
91+
}
92+
93+
do_usage() {
94+
echo $"Usage: $0 {start | stop | restart | force-reload | status}"
95+
exit 1
96+
}
97+
98+
case "$1" in
99+
start)
100+
do_start
101+
exit "$?"
102+
;;
103+
stop)
104+
do_stop
105+
exit "$?"
106+
;;
107+
restart|force-reload)
108+
do_restart
109+
exit "$?"
110+
;;
111+
status)
112+
do_status
113+
;;
114+
*)
115+
do_usage
116+
;;
117+
esac

0 commit comments

Comments
 (0)