Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

removed execSync dependency

  • Loading branch information...
commit 2a053bf97f3ea2757bce9584b752a4d1ea9b971b 1 parent 9b0633e
Bryan Paluch authored
Showing with 83 additions and 68 deletions.
  1. +81 −65 bin/create-upstart-monit.js
  2. +2 −3 package.json
View
146 bin/create-upstart-monit.js
@@ -7,8 +7,7 @@
var program = require('commander');
var swig = require('swig');
var fs = require('fs');
-var execSync = require('execSync');
-
+var exec = require('child_process').exec;
var abort = false;
program
.version('0.0.1')
@@ -23,9 +22,6 @@ if (!program.port){
process.exit(1);
abort = true;
}
-var nodeloc = execSync.stdout('which node');
-nodeloc = nodeloc.replace(/[\n\r]/g, '');
-console.log('using node location ' + nodeloc);
if (!program.user) program.user = 'ubuntu';
if (!program.homedir) program.homedir = '/home/ubuntu';
@@ -38,66 +34,85 @@ if(!info.description || !info.main || !info.name || !info.author){
}
var eol ="\n";
-//----------------------Upstart Template
-var upstart = [
-"description \"{{description}}\""
-,"author \"{{author}}\""
-,"env USER={{user}}"
-,"start on runlevel [2345]"
-,"stop on runlevel [!2345]"
-,"script"
-," export HOME=\"{{home}}\""
-," chdir {{workingdir}}"
-," exec start-stop-daemon --chdir {{workingdir}} --start --make-pidfile --pidfile /var/run/{{appname}}.pid --chuid $USER --exec {{nodeloc}} {{workingdir}}/{{appexec}} >> /var/log/{{appname}}.log 2>&1"
-,"end script"
+var nodeloc;
+var child = exec('which node', function(error, stdout, stderr){
+ if(error !== null){
+ console.log('problem getting node path, is node in your path?');
+ process.exit(1);
+ }
+ nodeloc = stdout;
+ nodeloc = nodeloc.replace(/[\n\r]/g, '');
+ if(nodeloc){
+ console.log('using node location ' + nodeloc);
+ start();
+ }
+ else{
+ console.log('no nodelocation, is node in your path?');
+ process.exit(1);
+ }
+});
-,"pre-start script"
-," echo \"[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting\" >> /var/log/{{appname}}.log"
-,"end script"
-,"pre-stop script"
-," echo \"[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping\" >> /var/log/{{appname}}.log"
-,"end script"
-].join(eol);
-//------------------------ End Upstart Template
-//----------------------- Send template values
-var upopts = {
- description : info.description,
- author: info.author,
- home: program.homedir,
- user: program.user,
- workingdir: process.cwd(),
- appname: info.name,
- appexec: info.main,
- nodeloc: nodeloc
- }
-var uptpl = swig.compile(upstart);
-var upstartFile = uptpl(upopts);
-//-----------------------------------------
+function start(){
+ //----------------------Upstart Template
+ var upstart = [
+ "description \"{{description}}\""
+ ,"author \"{{author}}\""
+ ,"env USER={{user}}"
+ ,"start on runlevel [2345]"
+ ,"stop on runlevel [!2345]"
+ ,"script"
+ ," export HOME=\"{{home}}\""
+ ," chdir {{workingdir}}"
+ ," exec start-stop-daemon --chdir {{workingdir}} --start --make-pidfile --pidfile /var/run/{{appname}}.pid --chuid $USER --exec {{nodeloc}} {{workingdir}}/{{appexec}} >> /var/log/{{appname}}.log 2>&1"
+ ,"end script"
+ ,"pre-start script"
+ ," echo \"[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting\" >> /var/log/{{appname}}.log"
+ ,"end script"
+ ,"pre-stop script"
+ ," echo \"[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping\" >> /var/log/{{appname}}.log"
+ ,"end script"
+ ].join(eol);
+ //------------------------ End Upstart Template
+ //----------------------- Send template values
+ var upopts = {
+ description : info.description,
+ author: info.author,
+ home: program.homedir,
+ user: program.user,
+ workingdir: process.cwd(),
+ appname: info.name,
+ appexec: info.main,
+ nodeloc: nodeloc
+ }
+ var uptpl = swig.compile(upstart);
+ var upstartFile = uptpl(upopts);
+ //-----------------------------------------
-//----------------Create Upstart file
-if(!(fs.existsSync(process.cwd() + '/.deployscripts/')) && !abort){
- console.log('creating deploy scripts directory');
- fs.mkdirSync(process.cwd() + '/.deployscripts');
-}
-var upfd = fs.openSync(process.cwd() + '/.deployscripts/' + upopts.appname + '.conf', 'w+')
-fs.writeSync(upfd,upstartFile);
-console.log('upstart file written to ' + process.cwd() + '/.deployscripts/' + upopts.appname + '.conf');
-//-----------------Done Upstart File
-//----------------- monit template
-var monit = [
-," #!monit"
-," check process {{appname}} with pidfile \"/var/run/{{appname}}.pid\""
-," start program = \"/sbin/start {{appname}}\""
-," stop program = \"/sbin/stop {{appname}}\""
-," if failed port {{port}} protocol HTTP"
-," request /"
-," with timeout 10 seconds"
-," then restart"
-].join(eol);
-var monopts = {
+ //----------------Create Upstart file
+ if(!(fs.existsSync(process.cwd() + '/.deployscripts/')) && !abort){
+ console.log('creating deploy scripts directory');
+ fs.mkdirSync(process.cwd() + '/.deployscripts');
+ }
+ var upfd = fs.openSync(process.cwd() + '/.deployscripts/' + upopts.appname + '.conf', 'w+')
+ fs.writeSync(upfd,upstartFile);
+ console.log('upstart file written to ' + process.cwd() + '/.deployscripts/' + upopts.appname + '.conf');
+
+ //-----------------Done Upstart File
+ //----------------- monit template
+ var monit = [
+ ," #!monit"
+ ," check process {{appname}} with pidfile \"/var/run/{{appname}}.pid\""
+ ," start program = \"/sbin/start {{appname}}\""
+ ," stop program = \"/sbin/stop {{appname}}\""
+ ," if failed port {{port}} protocol HTTP"
+ ," request /"
+ ," with timeout 10 seconds"
+ ," then restart"
+ ].join(eol);
+ var monopts = {
description : info.description,
author: info.author,
home: program.homedir,
@@ -107,8 +122,9 @@ var monopts = {
appexec: info.main,
port: program.port,
}
-var montpl = swig.compile(monit);
-var monstartFile = montpl(monopts);
-var monfd = fs.openSync(process.cwd() + '/.deployscripts/' + monopts.appname + '.monit.conf', 'w+')
-fs.writeSync(monfd,monstartFile);
-console.log('monit file written to ' + process.cwd() + '/.deployscripts/' + monopts.appname + '.monit.conf');
+ var montpl = swig.compile(monit);
+ var monstartFile = montpl(monopts);
+ var monfd = fs.openSync(process.cwd() + '/.deployscripts/' + monopts.appname + '.monit.conf', 'w+')
+ fs.writeSync(monfd,monstartFile);
+ console.log('monit file written to ' + process.cwd() + '/.deployscripts/' + monopts.appname + '.monit.conf');
+}
View
5 package.json
@@ -1,12 +1,11 @@
{
"name": "create-upstart-monit",
- "version": "0.0.1",
+ "version": "0.0.2",
"description": "Creates upstart and monit files for deploying services",
"main": "server.js",
"dependencies": {
"commander": "~1.1.1",
- "swig": "~0.13.3",
- "execSync": "0.0.1"
+ "swig": "~0.13.3"
},
"devDependencies": {},
"scripts": {
Please sign in to comment.
Something went wrong with that request. Please try again.