-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrcbrewable
executable file
·105 lines (89 loc) · 2.52 KB
/
rcbrewable
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
#!/bin/sh
# Copyright (c) 2016-2017 Christoph Willing (Brisbane, Australia)
# All rights reserved.
#
# Author: Christoph Willing, 2016
#
# /etc/init.d/brewable
### BEGIN INIT INFO
# Provides: brewable
# Required-Start: $local_fs $network $syslog
# Required-Stop: $local_fs $network $syslog
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: brewable temperature controller daemon
# Description: The brewable daemon starts a nodejs web server
# enabling remote browser control of a temperature control system.
# We want it to be active in runlevels 3 and 5,
# as these are the runlevels with the network available.
### END INIT INFO
# Check for config file
BREWABLE_CONFIG=/etc/default/brewable
test -r $BREWABLE_CONFIG || { echo "$BREWABLE_CONFIG not found";
if [ "$1" = "stop" ]; then exit 0;
else exit 5; fi; }
# Read config
. $BREWABLE_CONFIG
# Check for server file
BREWABLE_SERVER=/usr/bin/brewable
test -x $BREWABLE_SERVER || { echo "$BREWABLE_SERVER not installed";
if [ "$1" = "stop" ]; then exit 0;
else exit 5; fi; }
brewable_start () {
echo "Starting brewable"
# Ensure the pid can be written by the application
PIDDIR=$(dirname $BREWABLE_PID_FILE)
mkdir -p $PIDDIR
chown $BREWABLE_USER $PIDDIR
# Ensure logs can be written somewhere
mkdir -p $BREWABLE_LOG_DIR
touch /var/log/brewable/brewable_stdout.log
touch /var/log/brewable/brewable_stderr.log
chown -R $BREWABLE_USER:$BREWABLE_USER $BREWABLE_LOG_DIR
mkdir -p $BREWABLE_RUN_DIR
cd $BREWABLE_RUN_DIR
su -c \
$BREWABLE_SERVER \
$BREWABLE_USER \
-- \
port=$BREWABLE_PORT \
interval=$BREWABLE_JOBCHECKINTERVAL \
1>>/var/log/brewable/brewable_stdout.log \
2>>/var/log/brewable/brewable_stderr.log \
&
}
brewable_stop () {
echo "Stopping brewable"
pid=$(cat $BREWABLE_PID_FILE)
case $pid in
''|*[!0-9]*)
ps -ef \
| grep -v grep \
| grep "node brewable" \
| awk '{print $2}' \
| xargs kill -HUP
;;
*)
kill -HUP $pid
;;
esac
}
case "$1" in
start)
brewable_start
;;
stop)
brewable_stop
;;
restart)
brewable_stop
sleep 1
brewable_start
;;
*)
echo "Usage: /etc/init.d/brewable start|stop|restart"
exit 1
;;
esac
exit 0
# ex:set ai shiftwidth=4 inputtab=spaces smarttab noautotab: