Skip to content

Commit

Permalink
Merge pull request #72 from pornel/master
Browse files Browse the repository at this point in the history
Basic support for Ubuntu 16
  • Loading branch information
arvind-agarwal authored Oct 12, 2016
2 parents 8ac17df + 10d6dbf commit adf4483
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Platforms supported
* Amazon Linux
* Redhat Linux
* CentOS
* Ubuntu (< 15.04)
* Ubuntu (upstart, sysv fallback for >= 15.04, no systemd support)
* Debian
* Raspbian
* OSMC Linux
Expand Down
13 changes: 7 additions & 6 deletions bin/forever-service
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
var installer = require('../lib/installer');
var platforms = require('../lib/platforms');
var path = require('path');
var shell = require('shelljs');

platforms.get(function(err, platform){
console.log('forever-service version '+require('../package.json').version+'\n');
if(err || !platform){
if(err || !platform){
console.error('This platform is not yet supported by forever-service');
console.error('To help us add this platform, please contibute to https://github.com/zapty/forever-service\n');
return;
Expand All @@ -17,7 +18,7 @@ platforms.get(function(err, platform){

program
.version(require('../package.json').version)


program
.command('install [service]')
Expand Down Expand Up @@ -52,7 +53,7 @@ platforms.get(function(err, platform){
var ctx = Object.create(platform);
ctx.service = service;

if(options.script)
if(options.script)
ctx.script = options.script;
else
ctx.script = 'app.js';
Expand Down Expand Up @@ -152,7 +153,7 @@ platforms.get(function(err, platform){
console.error('Service name missing');
return 3;
}

console.log('Platform - '+platform.os);

var ctx = Object.create(platform);
Expand All @@ -179,7 +180,7 @@ platforms.get(function(err, platform){
console.log(' Command help:\n')
console.log(' forever-service install --help');
console.log(' forever-service delete --help\n');
}
}

});

Expand Down Expand Up @@ -215,4 +216,4 @@ function getCmdPath(cmd){
} else {
console.log(cmd + 'path not found');
}
}
}
8 changes: 3 additions & 5 deletions lib/installer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
var fs = require('fs'),
path = require('path');
scriptBuilder = require('./scriptBuilder'),
shell = require('shelljs');

path = require('path'),
scriptBuilder = require('./scriptBuilder');

exports.validateScriptName = function(scriptname){
if(scriptname && scriptname[0] === path.sep)
Expand Down Expand Up @@ -32,4 +30,4 @@ exports.delete = function(ctx, callback){
exports.splitEnvVariables=function(envVars){
//Split at space, but ignore space inside quotes..
return envVars.match(/(?:[^\s"']+|["'][^"']*["'])+/g);
}
}
1 change: 1 addition & 0 deletions package.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"walker": "~1.0.6"
},
"devDependencies": {
"fs-extra": "^0.30.0",
"mocha": "*",
"should": "*"
},
Expand Down
14 changes: 5 additions & 9 deletions templates/sysvinit/installer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
var os = require('os'),
scriptBuilder = require('../../lib/scriptBuilder'),
async = require('async'),
var async = require('async'),
shell = require('shelljs'),
fs = require('fs');

Expand All @@ -19,7 +17,8 @@ exports.initialize=function(){
}
} else if (fs.existsSync('/etc/os-release')){
var contents = fs.readFileSync('/etc/os-release','utf8');
if( contents && contents.match(/ID=(debian|bunsenlabs|raspbian|osmc|"elementary OS")/g) ){
if (/ID=(debian|bunsenlabs|raspbian|osmc|"elementary OS")/.test(contents) ||
(!fs.existsSync('/sbin/upstart') && /ID_LIKE=debian/.test(contents))) { // Matches Ubuntu 15+ with systemd only
return {
os: getPrettyName(contents),
platform: 'sysvinit',
Expand Down Expand Up @@ -73,16 +72,13 @@ exports.install=function(ctx, scripts, callback){
}
],
function(err, results){
//if(err) console.error('Error while provisioing service\n'+err);
callback(err,
{
callback(err, {
help: 'Commands to interact with service '+ctx.service+'\n'+
'Start - "sudo service '+ctx.service+' start"\n'+
'Stop - "sudo service '+ctx.service+' stop"\n'+
'Status - "sudo service '+ctx.service+' status"\n'+
'Restart - "sudo service '+ctx.service+' restart"'
}
);
});
}
);
}
Expand Down
22 changes: 12 additions & 10 deletions templates/upstart/installer.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
var os = require('os'),
scriptBuilder = require('../../lib/scriptBuilder'),
async = require('async'),
var async = require('async'),
shell = require('shelljs'),
fs = require('fs');

exports.initialize=function(){
if (!fs.existsSync('/sbin/upstart')) {
return;
}

if(fs.existsSync('/etc/lsb-release')){
if (fs.existsSync('/etc/lsb-release')){
var contents = fs.readFileSync('/etc/lsb-release','utf8');
var r = /DISTRIB_DESCRIPTION\=['"](.*)['"]/gm;
if( contents && contents.match(/(DISTRIB_ID=Ubuntu)/g) ){
var osmatch = r.exec(contents);
if(osmatch.length < 2) return;
if (contents && contents.match(/(DISTRIB_ID=Ubuntu)/g) ){
var osmatch = /DISTRIB_DESCRIPTION\=['"](.*)['"]/gm.exec(contents);
if (!osmatch || osmatch.length < 2) {
return;
}

return {
os: osmatch[1],
Expand Down Expand Up @@ -61,7 +63,7 @@ exports.install=function(ctx, scripts, callback){
],
function(err, results){
//if(err) console.error('Error while provisioing service\n'+err);
callback(err,
callback(err,
{
help: 'Commands to interact with service '+ctx.service+'\n'+
'Start - "sudo start '+ctx.service+'"\n'+
Expand Down Expand Up @@ -143,4 +145,4 @@ exports.delete=function(ctx, scripts, callback){
}
);
}
}
}

0 comments on commit adf4483

Please sign in to comment.