From 0cdeee314ddc0bc0abd3f1be7f398ddffb551b6b Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Sun, 7 Aug 2016 13:26:20 +0200 Subject: [PATCH] Cleaned up initial config loading Added WorkingDirectory to service unit in readme --- README.md | 1 + index.js | 28 ++++++++-------------------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index c50af7c..748beca 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Description=SecurityCam server [Service] ExecStart=/usr/local/bin/node /srv/securitycam/index.js +WorkingDirectory=/srv/securitycam Restart=always RestartSec=10 # Restart service after 10 seconds if node service crashes StandardOutput=syslog # Output to syslog diff --git a/index.js b/index.js index 628c707..0c599d8 100644 --- a/index.js +++ b/index.js @@ -225,27 +225,15 @@ app.get('/capture/:camId', function(req, res) } }); -var watcher = chokidar.watch('./config.js'); -var firstLoad = true; +loadConfig(); + +var watcher = chokidar.watch('./config.js', +{ + ignoreInitial: true +}); watcher.on('all', function() { - if (!firstLoad) - logger.verbose('Configuration change detected, reloading...'); - + logger.verbose('Configuration change detected, reloading...'); loadConfig(); - firstLoad = false; -}); - - -// It looks like the add event from chokidar will always be fired immediately, -// at least on Windows, but I couldn't find anything in the documentation so -// let's not make that assumption and double-check. -setTimeout(function() -{ - if (firstLoad) - { - loadConfig(); - firstLoad = false; - } -}, 1000); \ No newline at end of file +}); \ No newline at end of file