Wed, 13 Aug 2014 21:01:00 +0200
Write logs and output to temp until a configuration variable exists.
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@0 | 40 | ***********************************************************/ |
michael@0 | 41 | |
michael@0 | 42 | // import module dependencies |
michael@0 | 43 | var forkserv = require('forever-monitor'); |
michael@0 | 44 | |
michael@0 | 45 | |
michael@0 | 46 | // configure a child process to daemonize |
michael@0 | 47 | var childproc = new (forkserv.Monitor)('app.js', { |
michael@0 | 48 | max: 4, |
michael@0 | 49 | silent: true, |
michael@4 | 50 | pidFile: '/tmp/mdnsgw.pid', |
michael@4 | 51 | logFile: '/tmp/mdnsgw.log', |
michael@4 | 52 | outFile: '/tmp/mdnsgw.out', |
michael@4 | 53 | errFile: '/tmp/mdnsgw.err', |
michael@0 | 54 | options: [] |
michael@0 | 55 | }); |
michael@0 | 56 | |
michael@0 | 57 | childproc.on('exit', function () { |
michael@0 | 58 | console.log('app.js has exited after 4 restarts'); |
michael@0 | 59 | }); |
michael@0 | 60 | |
michael@0 | 61 | // fork a child |
michael@0 | 62 | childproc.start(); |
michael@4 | 63 | |
michael@4 | 64 | //// daemonize by exit |
michael@4 | 65 | //that doesn't work |
michael@4 | 66 | //process.exit(0); |