aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md20
-rw-r--r--gulpfile.js27
-rw-r--r--src/DillerConfig.js3
-rw-r--r--src/web/DillerWeb.js3
-rw-r--r--systemd/.gitignore1
-rw-r--r--systemd/diller-mqtt.template.service13
-rw-r--r--systemd/diller-web.template.service13
7 files changed, 76 insertions, 4 deletions
diff --git a/README.md b/README.md
index 387098c..aada0ac 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,26 @@ Run Diller:
This assumes that you have `gulp` installed globally. If you don't you can run `./node_modules/.bin/gulp`.
+## Installing services under Systemd
+
+Generate service configuration:
+
+ grunt gen-systemd
+
+Install services
+
+ sudo ln -s `pwd`/systemd/diller-mqtt.service /etc/systemd/system
+ sudo ln -s `pwd`/systemd/diller-web.service /etc/systemd/system
+ sudo systemctl --system daemon-reload
+
+Start daemons
+
+ sudo systemctl start diller-mqtt
+ sudo systemctl start diller-web
+
+ sudo systemctl status diller-mqtt
+ sudo systemctl status diller-web
+
# MQTT topics
/diller
diff --git a/gulpfile.js b/gulpfile.js
index ae66565..724a0b1 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -2,7 +2,9 @@ var gulp = require('gulp-help')(require('gulp'));
var bower = require('gulp-bower');
var nodemon = require('gulp-nodemon');
var path = require('path');
-var spawn = require('child_process').spawn
+var fs = require('fs');
+var spawn = require('child_process').spawn;
+var _ = require('lodash');
gulp.task('bower', function () {
return bower()
@@ -19,7 +21,6 @@ function readable(state, daemon) {
'--color'
]);
- //console.log('bunyan', bunyan);
bunyan.stdout.pipe(process.stdout);
bunyan.stderr.pipe(process.stderr);
@@ -72,4 +73,26 @@ gulp.task('diller-web', ['bower'], function () {
});
});
+gulp.task('gen-systemd', function () {
+ var config = {
+ WorkingDirectory: process.cwd(),
+ User: process.env.USER,
+ Group: process.env.USER,
+ NODE_ENV: 'prod'
+ };
+
+ function gen(inPath, outPath) {
+ var content = '' + fs.readFileSync(inPath);
+
+ _.each(config, function (value, key) {
+ content = content.replace('%' + key + '%', value);
+ });
+
+ fs.writeFileSync(outPath, content);
+ }
+
+ gen('systemd/diller-mqtt.template.service', 'systemd/diller-mqtt.service');
+ gen('systemd/diller-web.template.service', 'systemd/diller-web.service');
+});
+
gulp.task('default', ['bower']);
diff --git a/src/DillerConfig.js b/src/DillerConfig.js
index 652561a..81ff046 100644
--- a/src/DillerConfig.js
+++ b/src/DillerConfig.js
@@ -53,11 +53,14 @@ function configureLogging(app) {
}
function DillerConfig() {
+ var httpPort = process.env.HTTP_PORT || 8080;
+
return {
isProd: isProd,
updateDillerRpc: !isProd(),
mqttUrl: mqttUrl,
postgresqlConfig: postgresqlConfig,
+ httpPort: httpPort,
configureLogging: configureLogging,
log: function () {
return log;
diff --git a/src/web/DillerWeb.js b/src/web/DillerWeb.js
index a5bdf6b..c261af7 100644
--- a/src/web/DillerWeb.js
+++ b/src/web/DillerWeb.js
@@ -105,8 +105,7 @@ function DillerWeb(diller, db, config) {
}
function listen() {
- var port = process.env.HTTP_PORT || 8080;
- app.listen(port);
+ app.listen(config.httpPort);
}
function generateRpc() {
diff --git a/systemd/.gitignore b/systemd/.gitignore
new file mode 100644
index 0000000..0e3ad1b
--- /dev/null
+++ b/systemd/.gitignore
@@ -0,0 +1 @@
+*.service
diff --git a/systemd/diller-mqtt.template.service b/systemd/diller-mqtt.template.service
new file mode 100644
index 0000000..30bd78f
--- /dev/null
+++ b/systemd/diller-mqtt.template.service
@@ -0,0 +1,13 @@
+[Service]
+ExecStart=/usr/bin/nodejs diller-mqtt.js
+WorkingDirectory=%WorkingDirectory%
+Restart=always
+StandardOutput=syslog
+StandardError=syslog
+SyslogIdentifier=diller
+User=%User%
+Group=%Group%
+Environment=NODE_ENV=%NODE_ENV%
+
+[Install]
+WantedBy=multi-user.target
diff --git a/systemd/diller-web.template.service b/systemd/diller-web.template.service
new file mode 100644
index 0000000..ad48fa5
--- /dev/null
+++ b/systemd/diller-web.template.service
@@ -0,0 +1,13 @@
+[Service]
+ExecStart=/usr/bin/nodejs diller-web.js
+WorkingDirectory=%WorkingDirectory%
+Restart=always
+StandardOutput=syslog
+StandardError=syslog
+SyslogIdentifier=diller
+User=%User%
+Group=%Group%
+Environment=NODE_ENV=%NODE_ENV% HTTP_PORT=1337
+
+[Install]
+WantedBy=multi-user.target