src/bin/fork.js

Thu, 14 Aug 2014 19:14:04 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 14 Aug 2014 19:14:04 +0200
changeset 9
3d4d0e0dd4de
parent 5
ee8de27ff264
permissions
-rwxr-xr-x

Change root path to (more) approximate typical launch environment.

michael@0 1 #! /usr/bin/env nodejs
michael@0 2 //
michael@0 3 // mDNSGw - Zero Configuration DNS Gateway for Mesh Networks
michael@0 4 // Copyright © 2014 Michael Schloh von Bennewitz <michael@schloh.com>
michael@0 5 //
michael@0 6 // Permission to use, copy, modify, and/or distribute this software for
michael@0 7 // any purpose with or without fee is hereby granted, provided that the
michael@0 8 // above copyright notice and this permission notice appear in all copies.
michael@0 9 //
michael@0 10 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
michael@0 11 // WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
michael@0 12 // WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
michael@0 13 // AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
michael@0 14 // DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
michael@0 15 // PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
michael@0 16 // ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
michael@0 17 // THIS SOFTWARE.
michael@0 18 //
michael@0 19 // This file is part of mDNSGw, a Zero configuration DNS gateway
michael@0 20 // which can be found at http://dev.europalab.com/mdnsgw/
michael@0 21 //
michael@0 22 // fork.js: ECMA JavaScript implementation
michael@0 23 //
michael@0 24
michael@0 25 /***********************************************************
michael@0 26 | ____ _ _ ____ ____ |
michael@0 27 | _ __ ___ | _ \| \ | / ___| / ___|_ __ |
michael@0 28 | | '_ ` _ \| | | | \| \___ \| | _\ \ /\ / / |
michael@0 29 | | | | | | | |_| | |\ |___) | |_| |\ V V / |
michael@0 30 | |_| |_| |_|____/|_| \_|____/ \____| \_/\_/ |
michael@0 31 | |
michael@0 32 | Requirements: Redis server with standard configuration |
michael@0 33 | NodeJS and NPM modules (see package.json) |
michael@0 34 | |
michael@0 35 | Execute: To start this application, launch it with the |
michael@0 36 | script named fork.js: $ ./fork.js |
michael@0 37 | |
michael@0 38 | Support: http://list.europalab.com/mailman/mdnsgs/ |
michael@0 39 | |
michael@9 40 | Test: dig @nodeapp.host.tld A realhost.local |
michael@9 41 | |
michael@0 42 ***********************************************************/
michael@0 43
michael@0 44 // import module dependencies
michael@0 45 var forkserv = require('forever-monitor');
michael@0 46
michael@0 47
michael@0 48 // configure a child process to daemonize
michael@9 49 var childproc = new (forkserv.Monitor)('src/lib/app.js', {
michael@0 50 max: 4,
michael@0 51 silent: true,
michael@4 52 pidFile: '/tmp/mdnsgw.pid',
michael@4 53 logFile: '/tmp/mdnsgw.log',
michael@4 54 outFile: '/tmp/mdnsgw.out',
michael@4 55 errFile: '/tmp/mdnsgw.err',
michael@0 56 options: []
michael@0 57 });
michael@0 58
michael@0 59 childproc.on('exit', function () {
michael@0 60 console.log('app.js has exited after 4 restarts');
michael@0 61 });
michael@0 62
michael@0 63 // fork a child
michael@0 64 childproc.start();
michael@4 65
michael@4 66 //// daemonize by exit
michael@4 67 //that doesn't work
michael@4 68 //process.exit(0);

mercurial