Skip to content

Commit df8211a

Browse files
committed
packaging for 0.3
1 parent 7c2f168 commit df8211a

File tree

8 files changed

+112
-61
lines changed

8 files changed

+112
-61
lines changed

Makefile

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ TEST_FILES = test-status.js \
55
src/scripts/modules/cpuinfo.js \
66
src/scripts/modules/sainsmartrelay.js
77

8-
DESTDIR = /
8+
DESTDIR ?=
9+
10+
PKGVERSION ?= 0.3
911

1012
# Where any app files are installed
1113
RUNDIR = /usr/share/brewable
@@ -16,9 +18,18 @@ USER = pi
1618
# Where daemon log files will be
1719
LOGDIR = /var/log/brewable
1820

21+
# PID file
22+
PIDFILE = /var/run/brewable/pid
23+
24+
# Default server port
25+
PORT = 8888
26+
27+
# Default interval (seconds) between checking job progress
28+
INTERVAL = 60
29+
1930

2031

21-
build: default.conf client server
32+
default: brewable
2233

2334

2435
test: test.js
@@ -29,45 +40,60 @@ default.conf: default.conf.in
2940
-e 's:%RUNDIR%:$(RUNDIR):' \
3041
-e 's:%USER%:$(USER):' \
3142
-e 's:%LOGDIR%:$(LOGDIR):' \
43+
-e 's:%PIDFILE%:$(PIDFILE):' \
44+
-e 's:%PORT%:$(PORT):' \
45+
-e 's:%INTERVAL%:$(INTERVAL):' \
3246
> default.conf
3347

3448
node_modules:
3549
npm install
3650

37-
#client: node_modules
38-
client:
51+
client: node_modules
3952
./node_modules/.bin/rollup --config client.config.js
53+
touch client
4054

4155
test.js: $(TEST_FILES)
4256
./node_modules/.bin/rollup --config test.config.js
4357
chmod a+x test.js
4458

45-
#server: node_modules
46-
server:
59+
server: node_modules src/scripts/brewable.js
4760
patch -p0 < websocket-no-binaries.diff
4861
./node_modules/.bin/rollup --config server.config.js
4962
patch -p0 -R < websocket-no-binaries.diff
5063
chmod a+x build/js/brewableserverbundle.js
64+
touch server
5165

5266

53-
brewable: server client
67+
brewable: server client makeself.make
5468
./makeself.make
5569

56-
install: build brewable
70+
install: brewable default.conf
5771
mkdir -p $(DESTDIR)/etc/default
5872
mkdir -p $(DESTDIR)/etc/init.d
5973
mkdir -p $(DESTDIR)/usr/bin
6074
install -m 0755 brewable $(DESTDIR)/usr/bin
6175
install -m 0644 default.conf $(DESTDIR)/etc/default/brewable
6276
install -m 0755 rcbrewable $(DESTDIR)/etc/init.d/brewable
63-
bash -c './postinst configure'
77+
# bash -c './postinst configure'
78+
79+
uninstall:
80+
rm $(DESTDIR)/etc/default/brewable
81+
rm $(DESTDIR)/etc/init.d/brewable
82+
rm $(DESTDIR)/usr/bin/brewable
83+
84+
pkg: brewable default.conf rcbrewable
85+
rm -rf brewable-$(PKGVERSION); mkdir -p brewable-$(PKGVERSION);
86+
install -m 0755 brewable brewable-$(PKGVERSION)
87+
install -m 0755 default.conf brewable-$(PKGVERSION)
88+
install -m 0755 rcbrewable brewable-$(PKGVERSION)
89+
install -m 0755 Makefile brewable-$(PKGVERSION)
90+
tar cvf brewable-$(PKGVERSION)-armv61-1.tar.gz brewable-$(PKGVERSION)
91+
6492

6593
clean:
66-
rm -f default.conf
67-
rm -rf build
68-
rm -f test.js
94+
rm -rf default.conf test.js brewable-$(PKGVERSION)*
6995

70-
distclean:
71-
rm -rf node_modules
96+
distclean: clean
97+
rm -rf node_modules brewable client server
7298

73-
.PHONY: default.conf node_modules brewable test
99+
.PHONY:

client.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default {
1919
targets: [
2020
{ dest: 'build/js/brewableclientbundle.js', format: 'iife' },
2121
],
22-
sourceMap: 'inline',
22+
sourceMap: 'none',
2323
plugins: [
2424
progress({
2525
clearLine: true // default: true

default.conf.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
BREWABLE_RUN_DIR=%RUNDIR%
33
BREWABLE_USER=%USER%
44
BREWABLE_LOG_DIR=%LOGDIR%
5+
BREWABLE_PID_FILE=%PIDFILE%
6+
BREWABLE_PORT=%PORT%
7+
BREWABLE_JOBCHECKINTERVAL=%INTERVAL%

makeself.make

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
NODEEXE=$(which node)
44
BREWTEMPDIR=`mktemp -d /tmp/brewtemp.XXXXXX` || exit 1
5-
TARGET=build/brewable
6-
echo "Making self in $BREWTEMPDIR"
5+
TARGET=$(pwd)/brewable
76

87
echo './node brewableserverbundle.js "$@"' > $BREWTEMPDIR/run.sh
98
chmod a+x $BREWTEMPDIR/run.sh
109
cp $NODEEXE $BREWTEMPDIR
11-
cp -p build/js/brewable* $BREWTEMPDIR
12-
makeself $BREWTEMPDIR $TARGET 0.7 ./run.sh
10+
cp -p build/js/brewable*.js $BREWTEMPDIR
11+
makeself --noprogress --nox11 $BREWTEMPDIR $TARGET 0.3 ./run.sh
1312
sed -i -e 's/quiet="n"/quiet="y"/' \
14-
-e 's/noprogress=n/noprogress=y/' \
1513
$TARGET
1614

1715
rm -rf $BREWTEMPDIR

rcbrewable

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
# Copyright (c) 2016 Christoph Willing (Brisbane, Australia)
3+
# Copyright (c) 2016-2017 Christoph Willing (Brisbane, Australia)
44
# All rights reserved.
55
#
66
# Author: Christoph Willing, 2016
@@ -14,7 +14,7 @@
1414
# Default-Start: 3 5
1515
# Default-Stop: 0 1 2 6
1616
# Short-Description: brewable temperature controller daemon
17-
# Description: The brewable daemon starts a tornado web server
17+
# Description: The brewable daemon starts a nodejs web server
1818
# enabling remote browser control of a temperature control system.
1919
# We want it to be active in runlevels 3 and 5,
2020
# as these are the runlevels with the network available.
@@ -31,31 +31,55 @@ test -r $BREWABLE_CONFIG || { echo "$BREWABLE_CONFIG not found";
3131
. $BREWABLE_CONFIG
3232

3333
# Check for server file
34-
BREWABLE_SERVER=$BREWABLE_RUN_DIR/brewable
34+
BREWABLE_SERVER=/usr/bin/brewable
3535
test -x $BREWABLE_SERVER || { echo "$BREWABLE_SERVER not installed";
3636
if [ "$1" = "stop" ]; then exit 0;
3737
else exit 5; fi; }
3838

3939
brewable_start () {
4040
echo "Starting brewable"
41+
42+
# Ensure the pid can be written by the application
43+
PIDDIR=$(dirname $BREWABLE_PID_FILE)
44+
mkdir -p $PIDDIR
45+
chown $BREWABLE_USER $PIDDIR
46+
47+
# Ensure logs can be written somewhere
4148
mkdir -p $BREWABLE_LOG_DIR
4249
touch /var/log/brewable/brewable_stdout.log
4350
touch /var/log/brewable/brewable_stderr.log
4451
chown -R $BREWABLE_USER:$BREWABLE_USER $BREWABLE_LOG_DIR
52+
53+
mkdir -p BREWABLE_RUN_DIR
4554
cd $BREWABLE_RUN_DIR
46-
su -c $BREWABLE_SERVER $BREWABLE_USER \
55+
su -c \
56+
$BREWABLE_SERVER \
57+
$BREWABLE_USER \
58+
-- \
59+
port=$BREWABLE_PORT \
60+
interval=$BREWABLE_JOBCHECKINTERVAL \
4761
1>/var/log/brewable/brewable_stdout.log \
4862
2>/var/log/brewable/brewable_stderr.log \
4963
&
5064
}
5165

5266
brewable_stop () {
5367
echo "Stopping brewable"
54-
ps -ef \
55-
| grep -v grep \
56-
| grep "python $BREWABLE_SERVER" \
57-
| awk '{print $2}' \
58-
| xargs kill
68+
69+
pid=$(cat $BREWABLE_PID_FILE)
70+
case $pid in
71+
''|*[!0-9]*)
72+
ps -ef \
73+
| grep -v grep \
74+
| grep "node brewable" \
75+
| awk '{print $2}' \
76+
| xargs kill -HUP
77+
;;
78+
79+
*)
80+
kill -HUP $pid
81+
;;
82+
esac
5983
}
6084

6185
case "$1" in

src/scripts/brewable.js

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11

2-
//var events = require('events');
3-
//import events from 'events';
4-
5-
//var server = require("./modules/server");
6-
//var router = require("./modules/router");
7-
//var requestHandlers = require("./modules/requestHandlers");
8-
//var Queue = require("./modules/queue.js");
9-
//var gpioworker = require("./modules/gpioworker");
10-
112
import start from "./modules/server";
12-
//import router from "./modules/router";
133
import route from "./modules/router";
144
import { index as rhindex } from "./modules/requestHandlers";
155
import { favicon as rhfavicon } from "./modules/requestHandlers";
@@ -18,6 +8,19 @@ import { ws as rhws } from "./modules/requestHandlers";
188
import Queue from "./modules/queue";
199
import { gpioWorker as gpioworker } from "./modules/gpioworker";
2010

11+
var fs = require("fs");
12+
var path = require("path");
13+
14+
var DEFAULT_PORT = 8888;
15+
var DEFAULT_JOBCHECK_INTERVAL = 60;
16+
var PIDDIR = "/var/run/brewable";
17+
18+
19+
console.log("pid=" + process.pid);
20+
if (fs.existsSync(PIDDIR)) {
21+
process.umask(0);
22+
fs.writeFile(path.join(PIDDIR, "pid"), process.pid.toString(), {mode:parseInt('0644',8)});
23+
}
2124

2225
// Command line options
2326
var options = {};
@@ -28,7 +31,7 @@ process.argv.forEach((val) => {
2831
var opt = val.split('=');
2932
options[opt[0]] = opt[1];
3033
}
31-
if (val == "help") {
34+
if (val == "help" || val == "--help") {
3235
showUsage();
3336
process.exit();
3437
}
@@ -37,31 +40,30 @@ process.argv.forEach((val) => {
3740
if ("port" in options) {
3841
options.port = parseInt(options.port);
3942
} else {
40-
options.port = 8888;
43+
options.port = DEFAULT_PORT;
4144
}
42-
//console.log("options: " + JSON.stringify(options));
4345

4446
if ("interval" in options) {
4547
options.jobCheckInterval = parseInt(options.interval);
4648
} else {
47-
options.jobCheckInterval = 30; // seconds
49+
options.jobCheckInterval = DEFAULT_JOBCHECK_INTERVAL; // seconds
4850
}
49-
//console.log("options: " + JSON.stringify(options));
5051

5152
function showUsage() {
5253
console.log("\nUsage:");
53-
console.log(" brewable [options]");
54+
console.log(" \x1b[4mbrewable [options]\x1b[0m");
5455
console.log("\nOptions:");
55-
console.log(" port=<n>");
56+
console.log(" \x1b[4mport=<n>\x1b[0m");
5657
console.log(" where <n> is a valid port number (default is 8888)");
57-
console.log("\n interval=<n>");
58+
console.log("\n \x1b[4minterval=<n>\x1b[0m");
5859
console.log(" where <n> is the interval, in seconds, between processings of current jobs");
59-
console.log(" (default is 60)");
60+
console.log(" (default is " + DEFAULT_JOBCHECK_INTERVAL + ")");
61+
console.log("\n \x1b[4mhelp\x1b[0m");
62+
console.log(" show this usage message.");
6063
console.log("\nExample:");
6164
console.log(" brewable port=8686 interval=30\n");
6265
}
6366

64-
//global.eventEmitter = new events.EventEmitter();
6567
import { eventEmitter } from "./modules/gpioworker";
6668
var clients = [];
6769

@@ -86,8 +88,6 @@ var messageWaiting = function () {
8688
};
8789

8890
var input_queue = new Queue({'name':'input_queue','interval':200, 'action':messageWaiting});
89-
//var output_queue = new Queue({'name':'output_queue'});
90-
//var output_queue = new Queue({'action':function(){console.log("SOME action!");}});
9191
var output_queue = new Queue({'name':'output_queue', 'action':updateClients});
9292

9393

@@ -109,19 +109,18 @@ input_queue.start();
109109
output_queue.start();
110110
start(route, handle, clients, input_queue, options);
111111

112+
/* millseconds i.e.
113+
10000 = 10s
114+
30000 = 30s
115+
*/
112116
setInterval( function() {
113117
//console.log("\nDoing device updates");
114118
worker.updateDevices();
115119
}, 2000);
116120

117-
/* millseconds i.e.
118-
10000 = 10s
119-
30000 = 30s
120-
*/
121121
setInterval( function() {
122-
console.log("jobCheckInterval = " + new Date());
122+
//console.log("jobCheckInterval = " + new Date());
123123
worker.processRunningJobs();
124-
//}, (30000 + Math.floor((Math.random() * 1000) + 1)));
125124
}, ((1000 * options.jobCheckInterval) + Math.floor((Math.random() * 1000) + 1)));
126125

127126
process.on('SIGHUP', () => {
@@ -141,5 +140,4 @@ process.on('SIGTERM', () => {
141140
});
142141

143142

144-
145143
/* ex:set ai shiftwidth=2 inputtab=spaces smarttab noautotab: */

src/scripts/modules/gpioworker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ gpioWorker.prototype.setupJobRun = function (options) {
545545
};
546546

547547
gpioWorker.prototype.processRunningJobs = function () {
548-
console.log("processRunningJobs()");
548+
//console.log("processRunningJobs()");
549549
//this.runningJobs.forEach( function (job, index) {
550550
this.runningJobs.forEach( function (job) {
551551
//console.log("Process job: " + index + " (" + job.jobName + ")");

test-status.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
//import { default as gpio } from './src/scripts/modules/jsogpio';
1+
import { default as gpio } from './src/scripts/modules/jsogpio';
2+
3+
console.log("pid=" + process.pid);
24

35
var options = {};
46
process.argv.forEach((val, index) => {

0 commit comments

Comments
 (0)