1
1
var fs = require ( 'fs' ) ,
2
2
path = require ( 'path' ) ,
3
3
util = require ( 'util' ) ,
4
+ events = require ( 'events' ) ,
4
5
dnode = require ( 'dnode' ) ,
5
- EventEmitter2 = require ( 'eventemitter2' ) . EventEmitter2 ,
6
6
portfinder = require ( 'portfinder' ) ,
7
- forever = require ( '../forever' ) ,
8
- SystemVAdapter = require ( './adapter/systemv' ) ;
9
-
7
+ forever = require ( '../../forever' ) ,
8
+ SystemVAdapter = require ( './adapters/systemv' ) ;
10
9
11
10
// options
12
11
// directories {log, pid, conf, run, local}
13
- var ForeverService = module . exports = function ForeverService ( options ) {
12
+ var Service = module . exports = function Service ( options ) {
14
13
EventEmitter2 . call ( this ) ;
15
14
options = options || { } ;
16
15
@@ -27,21 +26,17 @@ var ForeverService = module.exports = function ForeverService(options) {
27
26
28
27
this . servers = [ ] ;
29
28
if ( typeof options . adapter === 'string' ) {
30
- options . adapter = ForeverService . adapter [ options . adapter ] ;
29
+ options . adapter = Service . adapter [ options . adapter ] ;
31
30
}
32
31
33
32
AdapterType = options . adapter || SystemVAdapter ;
34
33
this . adapter = new AdapterType ( this ) ;
35
34
console . log ( this . adapter ) ;
36
35
} ;
37
36
38
- util . inherits ( ForeverService , EventEmitter2 ) ;
39
-
40
- fs . readdirSync ( path . join ( __dirname , 'adapter' ) ) . forEach ( function loadAdapter ( adapterModule ) {
41
- ForeverService [ adapterModule ] = require ( path . join ( __dirname , 'adapter' , adapterModule ) ) ;
42
- } ) ;
37
+ util . inherits ( Service , events . EventEmitter ) ;
43
38
44
- ForeverService . prototype . startServer = function startServer ( callback ) {
39
+ Service . prototype . startServer = function startServer ( callback ) {
45
40
var socket = path . join ( forever . config . get ( 'sockPath' ) , 'forever.sock' ) ,
46
41
monitors = [ ] ,
47
42
self = this ,
@@ -80,7 +75,7 @@ ForeverService.prototype.startServer = function startServer(callback) {
80
75
return this ;
81
76
} ;
82
77
83
- ForeverService . prototype . listen = function listen ( server ) {
78
+ Service . prototype . listen = function listen ( server ) {
84
79
var dnodeServer = dnode ( this ) ;
85
80
86
81
this . servers . push ( dnodeServer ) ;
@@ -93,7 +88,7 @@ ForeverService.prototype.listen = function listen(server) {
93
88
return this ;
94
89
} ;
95
90
96
- ForeverService . prototype . load = function load ( ) {
91
+ Service . prototype . load = function load ( ) {
97
92
var self = this ;
98
93
this . adapter . load ( function onLoaded ( applications ) {
99
94
console . error ( arguments ) ;
@@ -119,7 +114,7 @@ ForeverService.prototype.load = function load() {
119
114
// DOES NOT START THE APPLICATION
120
115
// call's the service manager's add method
121
116
//
122
- ForeverService . prototype . add = function add ( file , options , callback ) {
117
+ Service . prototype . add = function add ( file , options , callback ) {
123
118
console . log ( arguments ) ;
124
119
if ( this . paused ) {
125
120
return callback && callback ( new Error ( 'foreverd is paused' ) ) ;
@@ -133,7 +128,7 @@ ForeverService.prototype.add = function add(file, options, callback) {
133
128
// remove the application from the service manager
134
129
// call's the service manager's remove method
135
130
//
136
- ForeverService . prototype . remove = function remove ( file , options , callback ) {
131
+ Service . prototype . remove = function remove ( file , options , callback ) {
137
132
if ( this . paused ) {
138
133
return callback ( new Error ( 'foreverd is paused' ) ) ;
139
134
}
@@ -177,7 +172,7 @@ ForeverService.prototype.remove = function remove(file, options, callback) {
177
172
// installs all the required to run foreverd
178
173
// call's the service manager's install(options)
179
174
//
180
- ForeverService . prototype . install = function install ( callback ) {
175
+ Service . prototype . install = function install ( callback ) {
181
176
this . adapter . install ( callback ) ;
182
177
return this ;
183
178
} ;
@@ -187,7 +182,7 @@ ForeverService.prototype.install = function install(callback) {
187
182
// uninstalls all the required to run foreverd
188
183
// call's the service manager's uninstall(options)
189
184
//
190
- ForeverService . prototype . uninstall = function uninstall ( callback ) {
185
+ Service . prototype . uninstall = function uninstall ( callback ) {
191
186
this . adapter . uninstall ( callback ) ;
192
187
return this ;
193
188
} ;
@@ -196,7 +191,7 @@ ForeverService.prototype.uninstall = function uninstall(callback) {
196
191
// Function start()
197
192
// calls the appropriate OS functionality to start this service
198
193
//
199
- ForeverService . prototype . start = function start ( callback ) {
194
+ Service . prototype . start = function start ( callback ) {
200
195
this . adapter . start ( callback ) ;
201
196
return this ;
202
197
} ;
@@ -205,7 +200,7 @@ ForeverService.prototype.start = function start(callback) {
205
200
// Function run()
206
201
// creates monitors for all the services
207
202
//
208
- ForeverService . prototype . run = function run ( callback ) {
203
+ Service . prototype . run = function run ( callback ) {
209
204
var self = this ;
210
205
this . adapter . run ( function adapterStarted ( ) {
211
206
console . error ( self . applications ) ;
@@ -224,7 +219,7 @@ ForeverService.prototype.run = function run(callback) {
224
219
//
225
220
// Function stop(monitors)
226
221
//
227
- ForeverService . prototype . stop = function stop ( callback ) {
222
+ Service . prototype . stop = function stop ( callback ) {
228
223
var self = this ;
229
224
this . adapter . start ( function adapterStopped ( ) {
230
225
self . applications . forEach ( function stopApplication ( application ) {
@@ -240,7 +235,7 @@ ForeverService.prototype.stop = function stop(callback) {
240
235
//
241
236
// Function restart()
242
237
//
243
- ForeverService . prototype . restart = function restart ( callback ) {
238
+ Service . prototype . restart = function restart ( callback ) {
244
239
var self = this ;
245
240
this . adapter . start ( function adapterRestarted ( ) {
246
241
self . applications . forEach ( function restartApplication ( application ) {
@@ -257,7 +252,7 @@ ForeverService.prototype.restart = function restart(callback) {
257
252
// Function pause()
258
253
// disables adding / removing applications
259
254
//
260
- ForeverService . prototype . pause = function pause ( callback ) {
255
+ Service . prototype . pause = function pause ( callback ) {
261
256
this . paused = true ;
262
257
if ( callback ) {
263
258
callback ( ) ;
@@ -270,7 +265,7 @@ ForeverService.prototype.pause = function pause(callback) {
270
265
// Function resume()
271
266
// reenables adding / removing applications
272
267
//
273
- ForeverService . prototype . resume = function resume ( callback ) {
268
+ Service . prototype . resume = function resume ( callback ) {
274
269
this . paused = false ;
275
270
if ( callback ) {
276
271
callback ( ) ;
@@ -279,7 +274,7 @@ ForeverService.prototype.resume = function resume(callback) {
279
274
return this ;
280
275
} ;
281
276
282
- ForeverService . prototype . list = function list ( callback ) {
277
+ Service . prototype . list = function list ( callback ) {
283
278
this . adapter . list ( callback ) ;
284
279
return this ;
285
280
} ;
0 commit comments