-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
4 changed files
with
27 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,3 @@ | ||
#!/usr/bin/env node | ||
|
||
var log = require('../lib/log')('info'); | ||
var Config = require('../lib/config')(log); | ||
var config = new Config(Config.config.config_file); | ||
var p = require('path'); | ||
var fs = require('fs'); | ||
var daemon = require("daemonize2").setup({ | ||
main: p.resolve(__dirname, "../app.js"), | ||
name: "redsmin", | ||
pidfile: p.resolve(__dirname, "../etc/redsmin.pid"), | ||
silent: true | ||
}); | ||
|
||
log.cli(); | ||
|
||
daemon.on("starting", function () { | ||
log.info("Starting redsmin daemon..."); | ||
log.debug("Connecting on Redis at " + config.redis); | ||
}).on("started", function (pid) { | ||
log.info("Redsmin daemon started. PID: " + pid); | ||
}).on("stopping", function () { | ||
log.info("Stopping redsmin daemon..."); | ||
}).on("stopped", function (pid) { | ||
log.info("Redsmin daemon stopped."); | ||
}).on("running", function (pid) { | ||
log.info("Redsmin daemon already running. PID: " + pid); | ||
}).on("notrunning", function () { | ||
log.info("Redsmin daemon is not running"); | ||
}).on("error", function (err) { | ||
log.error("Redsmin daemon failed to start: " + err.message); | ||
// log.error("-- Please create a report with the following text --"); | ||
// log.info(); | ||
// try{ | ||
// fs.readFileSync(p.resolve(__dirname, '../etc/log.log'), ); | ||
// } | ||
}); | ||
|
||
function usage() { | ||
log.info("Usage: [start|stop|kill|set_key|path|restart|reload|status]"); | ||
} | ||
|
||
if (!process.argv[2]) { | ||
return usage(); | ||
} | ||
|
||
switch (process.argv[2]) { | ||
|
||
case "start": | ||
// This will trigger an error if there is something with the configuration | ||
daemon.start().once("started", function () { | ||
process.exit(); | ||
}); | ||
break; | ||
|
||
case "stop": | ||
daemon.stop(); | ||
break; | ||
|
||
case "set_key": | ||
if (!process.env.RKEY) { | ||
return log.info('Usage: RKEY=REDSMIN_CONNECTION_KEY [RURL=redis://127.0.0.1:6379] [RAUTH=password] redsmin set_key'); | ||
} | ||
|
||
config.write(process.env.RKEY, process.env.RURL, process.env.RAUTH, function (err) { | ||
if (err) { | ||
log.error("Could not write the configuration file", err); | ||
return process.exit(1); | ||
} | ||
|
||
log.info("Configuration file written"); | ||
}); | ||
break; | ||
|
||
case "path": | ||
console.log(p.resolve(__dirname, '../')); | ||
break; | ||
|
||
case "kill": | ||
daemon.kill(); | ||
break; | ||
|
||
case "restart": | ||
if (daemon.status()) { | ||
daemon.stop().once("stopped", function () { | ||
daemon.start().once("started", function () { | ||
process.exit(); | ||
}); | ||
}); | ||
} else { | ||
daemon.start().once("started", function () { | ||
process.exit(); | ||
}); | ||
} | ||
break; | ||
|
||
case "status": | ||
var pid = daemon.status(); | ||
if (pid) log.info("Redmsin daemon running. PID: " + pid); | ||
else log.error("Redsmin daemon is not running."); | ||
break; | ||
|
||
default: | ||
usage(); | ||
} | ||
require('../app'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters