├── .gitignore ├── supervisord ├── .cupboard ├── lib ├── index.js └── api.js ├── package.json ├── project.sublime-project ├── project.tmproj ├── MIT-LICENSE.txt └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modulesnode_modules 2 | 3 | -------------------------------------------------------------------------------- /supervisord: -------------------------------------------------------------------------------- 1 | /Users/craig/Dropbox/Developer/public/supervisord -------------------------------------------------------------------------------- /.cupboard: -------------------------------------------------------------------------------- 1 | [commands] 2 | proj = subl --project project.sublime-project 3 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | var api = require('./api'); 2 | 3 | exports.connect = function(host) 4 | { 5 | return new api(host); 6 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "supervisord", 3 | "description": "Supervisord library for node.js", 4 | "version": "0.1.0", 5 | "author": "Craig Condon", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/crcn/node-supervisord.git" 9 | }, 10 | "dependencies": { 11 | "structr": "*", 12 | "xmlrpc": "*" 13 | }, 14 | "main": "./lib/index" 15 | } 16 | -------------------------------------------------------------------------------- /project.sublime-project: -------------------------------------------------------------------------------- 1 | { 2 | "folders": 3 | [ 4 | { 5 | "path": "." 6 | } 7 | ], 8 | "build_systems": 9 | [ 10 | { 11 | "name":"cbd make", 12 | "cmd":["cbd","make","supervisord"] 13 | }, 14 | { 15 | "name":"cbd start", 16 | "cmd":["cbd","start","supervisord"] 17 | }, 18 | { 19 | "name":"cbd make+start", 20 | "cmd":["cbd","make+start","supervisord"] 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /project.tmproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | documents 6 | 7 | 8 | name 9 | project 10 | regexFolderFilter 11 | !.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$ 12 | selected 13 | 14 | sourceDirectory 15 | 16 | 17 | 18 | fileHierarchyDrawerWidth 19 | 200 20 | metaData 21 | 22 | showFileHierarchyDrawer 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /MIT-LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Craig Condon 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### What's this? 2 | 3 | A node.js library for [supervisord](http://supervisord.org/). If you're not familiar with supervisord, it's much like [forever](https://github.com/indexzero/forever), [launchd](http://en.wikipedia.org/wiki/Launchd), upstart+monit, etc. 4 | 5 | 6 | 7 | ### Requirements 8 | 9 | 10 | - Node.js 11 | - Supervisord 12 | - NPM 13 | 14 | ### Installation 15 | 16 | npm install supervisord 17 | 18 | 19 | ### Example: 20 | 21 | 22 | ```javascript 23 | 24 | var supervisord = require('supervisord'); 25 | 26 | var client = supervisord.connect('http://localhost:9001'); 27 | 28 | 29 | client.startProcess('my-app', function(err, result) 30 | { 31 | 32 | }); 33 | 34 | //return all running processes by supervisord 35 | client.getAllProcessInfo(function(err, result) 36 | { 37 | console.log(result); 38 | 39 | /* 40 | [ { description: 'pid 22083, uptime 0:10:36', 41 | pid: 22083, 42 | stderr_logfile: '/tmp/test-stderr---supervisor-G27SFc.log', 43 | stop: 1316236587, 44 | logfile: '/tmp/test-stdout---supervisor-izrtu6.log', 45 | exitstatus: 0, 46 | spawnerr: '', 47 | now: 1316237455, 48 | group: 'app-1', 49 | name: 'app-1', 50 | statename: 'RUNNING', 51 | start: 1316236819, 52 | state: 20, 53 | stdout_logfile: '/tmp/test-stdout---supervisor-izrtu6.log' } ] 54 | */ 55 | }); 56 | 57 | ``` 58 | 59 | 60 | ### [Available Methods](http://supervisord.org/api.html?highlight=api): 61 | 62 | - getSupervisorVersion() 63 | - getIdentification() 64 | - getState() 65 | - getPID() 66 | - readLog() 67 | - clearLog() 68 | - shutdown() 69 | - restart() 70 | - getAllProcessInfo(name) 71 | - startProcess(name) 72 | - startAllProcesses() 73 | - startProcessGroup() 74 | - stopProcessGroup() 75 | - sendProcessStdin() 76 | - sendRemoteCommEvent() 77 | - addProcessGroup(name) 78 | - removeProcessGroup(name) 79 | - readProcessStdoutLog(name) 80 | - readProcessStderrLog(name, offset, length) 81 | - tailProcessStdoutLog(name, offset, length) 82 | - tailProcessStderrLog(name, offset, length) 83 | - clearProcessLogs(name) 84 | - clearAllProcesssLogs() 85 | - signalProcess(name, signal) 86 | - signalProcessGroup(name, signal) 87 | 88 | 89 | -------------------------------------------------------------------------------- /lib/api.js: -------------------------------------------------------------------------------- 1 | var xmlrpc = require('xmlrpc'), 2 | Url = require('url'); 3 | 4 | function api(host) { 5 | var hostParts = {}; 6 | 7 | if(typeof host == 'string') 8 | { 9 | if (host.indexOf('unix') === 0) { 10 | 11 | hostParts.socketPath = Url.parse(host).pathname; 12 | }else{ 13 | if (host.indexOf('http') !== 0) { 14 | host = 'http://' + host; 15 | } 16 | hostParts = Url.parse(host); 17 | 18 | if(hostParts.auth) 19 | { 20 | var authParts = hostParts.auth.split(':'); 21 | hostParts.user = authParts[0]; 22 | hostParts.pass = authParts[1]; 23 | } 24 | } 25 | } 26 | else if(host) 27 | { 28 | hostParts = host; 29 | } 30 | 31 | 32 | if(!hostParts.hostname) hostParts.hostname = 'localhost'; 33 | if(!hostParts.port) hostParts.port = 9001; 34 | 35 | if(hostParts.socketPath){ 36 | this.client = xmlrpc.createClient({ 37 | socketPath: hostParts.socketPath, 38 | path: '/RPC2', 39 | }); 40 | }else{ 41 | this.client = xmlrpc.createClient({ 42 | host: hostParts.hostname, 43 | port: hostParts.port, 44 | path: '/RPC2', 45 | basic_auth: { 46 | user: hostParts.user, 47 | pass: hostParts.pass 48 | } 49 | }); 50 | } 51 | } 52 | 53 | api.prototype._call = function(method, args, callback) 54 | { 55 | this.client.methodCall(method, args, callback); 56 | }; 57 | 58 | ['supervisor.addProcessGroup', 59 | 'supervisor.clearAllProcessLogs', 60 | 'supervisor.clearLog', 61 | 'supervisor.clearProcessLog', 62 | 'supervisor.clearProcessLogs', 63 | 'supervisor.getAPIVersion', 64 | 'supervisor.getAllConfigInfo', 65 | 'supervisor.getAllProcessInfo', 66 | 'supervisor.getIdentification', 67 | 'supervisor.getPID', 68 | 'supervisor.getProcessInfo', 69 | 'supervisor.getState', 70 | 'supervisor.getSupervisorVersion', 71 | 'supervisor.getVersion', 72 | 'supervisor.readLog', 73 | 'supervisor.readMainLog', 74 | 'supervisor.readProcessLog', 75 | 'supervisor.readProcessStderrLog', 76 | 'supervisor.readProcessStdoutLog', 77 | 'supervisor.reloadConfig', 78 | 'supervisor.removeProcessGroup', 79 | 'supervisor.restart', 80 | 'supervisor.sendProcessStdin', 81 | 'supervisor.sendRemoteCommEvent', 82 | 'supervisor.signalProcess', 83 | 'supervisor.signalProcessGroup', 84 | 'supervisor.shutdown', 85 | 'supervisor.startAllProcesses', 86 | 'supervisor.startProcess', 87 | 'supervisor.startProcessGroup', 88 | 'supervisor.stopAllProcesses', 89 | 'supervisor.stopProcess', 90 | 'supervisor.stopProcessGroup', 91 | 'supervisor.tailProcessLog', 92 | 'supervisor.tailProcessStderrLog', 93 | 'supervisor.tailProcessStdoutLog', 94 | 'system.listMethods', 95 | 'system.methodHelp', 96 | 'system.methodSignature', 97 | 'system.multicall'].forEach(function(property){ 98 | api.prototype[property.split('.').pop()] = function(){ 99 | var args = Array.prototype.slice.call(arguments); 100 | callback = args.pop(); 101 | this._call(property, args, callback); 102 | }; 103 | }); 104 | 105 | module.exports = api; 106 | --------------------------------------------------------------------------------