@@ -15,6 +15,7 @@ import (
15
15
16
16
"github.com/owncloud/ocis/v2/ocis-pkg/runner"
17
17
authapp "github.com/owncloud/ocis/v2/services/auth-app/pkg/command"
18
+ "github.com/urfave/cli/v2"
18
19
19
20
"github.com/cenkalti/backoff"
20
21
"github.com/mohae/deepcopy"
@@ -120,6 +121,15 @@ func NewService(ctx context.Context, options ...Option) (*Service, error) {
120
121
cfg : opts .Config ,
121
122
}
122
123
124
+ // run server command
125
+ runServerCommand := func (ctx context.Context , server * cli.Command ) error {
126
+ cliCtx := & cli.Context {Context : ctx }
127
+ if err := server .Before (cliCtx ); err != nil {
128
+ return err
129
+ }
130
+ return server .Action (cliCtx )
131
+ }
132
+
123
133
// populate services
124
134
reg := func (priority int , name string , exec func (context.Context , * ociscfg.Config ) error ) {
125
135
if s .Services [priority ] == nil {
@@ -132,14 +142,14 @@ func NewService(ctx context.Context, options ...Option) (*Service, error) {
132
142
reg (0 , opts .Config .Nats .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
133
143
cfg .Nats .Context = ctx
134
144
cfg .Nats .Commons = cfg .Commons
135
- return nats .Execute (cfg .Nats )
145
+ return runServerCommand ( ctx , nats .Server (cfg .Nats ) )
136
146
})
137
147
138
148
// gateway is in priority group 1. It needs to start before the reva services
139
149
reg (1 , opts .Config .Gateway .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
140
150
cfg .Gateway .Context = ctx
141
151
cfg .Gateway .Commons = cfg .Commons
142
- return gateway .Execute (cfg .Gateway )
152
+ return runServerCommand ( ctx , gateway .Server (cfg .Gateway ) )
143
153
})
144
154
145
155
// priority group 2 is empty for now
@@ -148,157 +158,157 @@ func NewService(ctx context.Context, options ...Option) (*Service, error) {
148
158
reg (3 , opts .Config .Activitylog .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
149
159
cfg .Activitylog .Context = ctx
150
160
cfg .Activitylog .Commons = cfg .Commons
151
- return activitylog .Execute (cfg .Activitylog )
161
+ return runServerCommand ( ctx , activitylog .Server (cfg .Activitylog ) )
152
162
})
153
163
reg (3 , opts .Config .AppProvider .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
154
164
cfg .AppProvider .Context = ctx
155
165
cfg .AppProvider .Commons = cfg .Commons
156
- return appProvider .Execute (cfg .AppProvider )
166
+ return runServerCommand ( ctx , appProvider .Server (cfg .AppProvider ) )
157
167
})
158
168
reg (3 , opts .Config .AppRegistry .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
159
169
cfg .AppRegistry .Context = ctx
160
170
cfg .AppRegistry .Commons = cfg .Commons
161
- return appRegistry .Execute (cfg .AppRegistry )
171
+ return runServerCommand ( ctx , appRegistry .Server (cfg .AppRegistry ) )
162
172
})
163
173
reg (3 , opts .Config .AuthBasic .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
164
174
cfg .AuthBasic .Context = ctx
165
175
cfg .AuthBasic .Commons = cfg .Commons
166
- return authbasic .Execute (cfg .AuthBasic )
176
+ return runServerCommand ( ctx , authbasic .Server (cfg .AuthBasic ) )
167
177
})
168
178
reg (3 , opts .Config .AuthMachine .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
169
179
cfg .AuthMachine .Context = ctx
170
180
cfg .AuthMachine .Commons = cfg .Commons
171
- return authmachine .Execute (cfg .AuthMachine )
181
+ return runServerCommand ( ctx , authmachine .Server (cfg .AuthMachine ) )
172
182
})
173
183
reg (3 , opts .Config .AuthService .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
174
184
cfg .AuthService .Context = ctx
175
185
cfg .AuthService .Commons = cfg .Commons
176
- return authservice .Execute (cfg .AuthService )
186
+ return runServerCommand ( ctx , authservice .Server (cfg .AuthService ) )
177
187
})
178
188
reg (3 , opts .Config .Clientlog .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
179
189
cfg .Clientlog .Context = ctx
180
190
cfg .Clientlog .Commons = cfg .Commons
181
- return clientlog .Execute (cfg .Clientlog )
191
+ return runServerCommand ( ctx , clientlog .Server (cfg .Clientlog ) )
182
192
})
183
193
reg (3 , opts .Config .EventHistory .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
184
194
cfg .EventHistory .Context = ctx
185
195
cfg .EventHistory .Commons = cfg .Commons
186
- return eventhistory .Execute (cfg .EventHistory )
196
+ return runServerCommand ( ctx , eventhistory .Server (cfg .EventHistory ) )
187
197
})
188
198
reg (3 , opts .Config .Graph .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
189
199
cfg .Graph .Context = ctx
190
200
cfg .Graph .Commons = cfg .Commons
191
- return graph .Execute (cfg .Graph )
201
+ return runServerCommand ( ctx , graph .Server (cfg .Graph ) )
192
202
})
193
203
reg (3 , opts .Config .Groups .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
194
204
cfg .Groups .Context = ctx
195
205
cfg .Groups .Commons = cfg .Commons
196
- return groups .Execute (cfg .Groups )
206
+ return runServerCommand ( ctx , groups .Server (cfg .Groups ) )
197
207
})
198
208
reg (3 , opts .Config .IDM .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
199
209
cfg .IDM .Context = ctx
200
210
cfg .IDM .Commons = cfg .Commons
201
- return idm .Execute (cfg .IDM )
211
+ return runServerCommand ( ctx , idm .Server (cfg .IDM ) )
202
212
})
203
213
reg (3 , opts .Config .OCDav .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
204
214
cfg .OCDav .Context = ctx
205
215
cfg .OCDav .Commons = cfg .Commons
206
- return ocdav .Execute (cfg .OCDav )
216
+ return runServerCommand ( ctx , ocdav .Server (cfg .OCDav ) )
207
217
})
208
218
reg (3 , opts .Config .OCS .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
209
219
cfg .OCS .Context = ctx
210
220
cfg .OCS .Commons = cfg .Commons
211
- return ocs .Execute (cfg .OCS )
221
+ return runServerCommand ( ctx , ocs .Server (cfg .OCS ) )
212
222
})
213
223
reg (3 , opts .Config .Postprocessing .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
214
224
cfg .Postprocessing .Context = ctx
215
225
cfg .Postprocessing .Commons = cfg .Commons
216
- return postprocessing .Execute (cfg .Postprocessing )
226
+ return runServerCommand ( ctx , postprocessing .Server (cfg .Postprocessing ) )
217
227
})
218
228
reg (3 , opts .Config .Search .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
219
229
cfg .Search .Context = ctx
220
230
cfg .Search .Commons = cfg .Commons
221
- return search .Execute (cfg .Search )
231
+ return runServerCommand ( ctx , search .Server (cfg .Search ) )
222
232
})
223
233
reg (3 , opts .Config .Settings .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
224
234
cfg .Settings .Context = ctx
225
235
cfg .Settings .Commons = cfg .Commons
226
- return settings .Execute (cfg .Settings )
236
+ return runServerCommand ( ctx , settings .Server (cfg .Settings ) )
227
237
})
228
238
reg (3 , opts .Config .StoragePublicLink .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
229
239
cfg .StoragePublicLink .Context = ctx
230
240
cfg .StoragePublicLink .Commons = cfg .Commons
231
- return storagepublic .Execute (cfg .StoragePublicLink )
241
+ return runServerCommand ( ctx , storagepublic .Server (cfg .StoragePublicLink ) )
232
242
})
233
243
reg (3 , opts .Config .StorageShares .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
234
244
cfg .StorageShares .Context = ctx
235
245
cfg .StorageShares .Commons = cfg .Commons
236
- return storageshares .Execute (cfg .StorageShares )
246
+ return runServerCommand ( ctx , storageshares .Server (cfg .StorageShares ) )
237
247
})
238
248
reg (3 , opts .Config .StorageSystem .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
239
249
cfg .StorageSystem .Context = ctx
240
250
cfg .StorageSystem .Commons = cfg .Commons
241
- return storageSystem .Execute (cfg .StorageSystem )
251
+ return runServerCommand ( ctx , storageSystem .Server (cfg .StorageSystem ) )
242
252
})
243
253
reg (3 , opts .Config .StorageUsers .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
244
254
cfg .StorageUsers .Context = ctx
245
255
cfg .StorageUsers .Commons = cfg .Commons
246
- return storageusers .Execute (cfg .StorageUsers )
256
+ return runServerCommand ( ctx , storageusers .Server (cfg .StorageUsers ) )
247
257
})
248
258
reg (3 , opts .Config .Thumbnails .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
249
259
cfg .Thumbnails .Context = ctx
250
260
cfg .Thumbnails .Commons = cfg .Commons
251
- return thumbnails .Execute (cfg .Thumbnails )
261
+ return runServerCommand ( ctx , thumbnails .Server (cfg .Thumbnails ) )
252
262
})
253
263
reg (3 , opts .Config .Userlog .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
254
264
cfg .Userlog .Context = ctx
255
265
cfg .Userlog .Commons = cfg .Commons
256
- return userlog .Execute (cfg .Userlog )
266
+ return runServerCommand ( ctx , userlog .Server (cfg .Userlog ) )
257
267
})
258
268
reg (3 , opts .Config .Users .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
259
269
cfg .Users .Context = ctx
260
270
cfg .Users .Commons = cfg .Commons
261
- return users .Execute (cfg .Users )
271
+ return runServerCommand ( ctx , users .Server (cfg .Users ) )
262
272
})
263
273
reg (3 , opts .Config .Web .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
264
274
cfg .Web .Context = ctx
265
275
cfg .Web .Commons = cfg .Commons
266
- return web .Execute (cfg .Web )
276
+ return runServerCommand ( ctx , web .Server (cfg .Web ) )
267
277
})
268
278
reg (3 , opts .Config .WebDAV .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
269
279
cfg .WebDAV .Context = ctx
270
280
cfg .WebDAV .Commons = cfg .Commons
271
- return webdav .Execute (cfg .WebDAV )
281
+ return runServerCommand ( ctx , webdav .Server (cfg .WebDAV ) )
272
282
})
273
283
reg (3 , opts .Config .Webfinger .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
274
284
cfg .Webfinger .Context = ctx
275
285
cfg .Webfinger .Commons = cfg .Commons
276
- return webfinger .Execute (cfg .Webfinger )
286
+ return runServerCommand ( ctx , webfinger .Server (cfg .Webfinger ) )
277
287
})
278
288
reg (3 , opts .Config .IDP .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
279
289
cfg .IDP .Context = ctx
280
290
cfg .IDP .Commons = cfg .Commons
281
- return idp .Execute (cfg .IDP )
291
+ return runServerCommand ( ctx , idp .Server (cfg .IDP ) )
282
292
})
283
293
reg (3 , opts .Config .Proxy .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
284
294
cfg .Proxy .Context = ctx
285
295
cfg .Proxy .Commons = cfg .Commons
286
- return proxy .Execute (cfg .Proxy )
296
+ return runServerCommand ( ctx , proxy .Server (cfg .Proxy ) )
287
297
})
288
298
reg (3 , opts .Config .Sharing .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
289
299
cfg .Sharing .Context = ctx
290
300
cfg .Sharing .Commons = cfg .Commons
291
- return sharing .Execute (cfg .Sharing )
301
+ return runServerCommand ( ctx , sharing .Server (cfg .Sharing ) )
292
302
})
293
303
reg (3 , opts .Config .SSE .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
294
304
cfg .SSE .Context = ctx
295
305
cfg .SSE .Commons = cfg .Commons
296
- return sse .Execute (cfg .SSE )
306
+ return runServerCommand ( ctx , sse .Server (cfg .SSE ) )
297
307
})
298
308
reg (3 , opts .Config .OCM .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
299
309
cfg .OCM .Context = ctx
300
310
cfg .OCM .Commons = cfg .Commons
301
- return ocm .Execute (cfg .OCM )
311
+ return runServerCommand ( ctx , ocm .Server (cfg .OCM ) )
302
312
})
303
313
304
314
// out of some unknown reason ci gets angry when frontend service starts in priority group 3
@@ -307,7 +317,7 @@ func NewService(ctx context.Context, options ...Option) (*Service, error) {
307
317
reg (4 , opts .Config .Frontend .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
308
318
cfg .Frontend .Context = ctx
309
319
cfg .Frontend .Commons = cfg .Commons
310
- return frontend .Execute (cfg .Frontend )
320
+ return runServerCommand ( ctx , frontend .Server (cfg .Frontend ) )
311
321
})
312
322
313
323
// populate optional services
@@ -317,32 +327,32 @@ func NewService(ctx context.Context, options ...Option) (*Service, error) {
317
327
areg (opts .Config .Antivirus .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
318
328
cfg .Antivirus .Context = ctx
319
329
// cfg.Antivirus.Commons = cfg.Commons // antivirus holds no Commons atm
320
- return antivirus .Execute (cfg .Antivirus )
330
+ return runServerCommand ( ctx , antivirus .Server (cfg .Antivirus ) )
321
331
})
322
332
areg (opts .Config .Audit .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
323
333
cfg .Audit .Context = ctx
324
334
cfg .Audit .Commons = cfg .Commons
325
- return audit .Execute (cfg .Audit )
335
+ return runServerCommand ( ctx , audit .Server (cfg .Audit ) )
326
336
})
327
337
areg (opts .Config .AuthApp .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
328
338
cfg .AuthApp .Context = ctx
329
339
cfg .AuthApp .Commons = cfg .Commons
330
- return authapp .Execute (cfg .AuthApp )
340
+ return runServerCommand ( ctx , authapp .Server (cfg .AuthApp ) )
331
341
})
332
342
areg (opts .Config .Policies .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
333
343
cfg .Policies .Context = ctx
334
344
cfg .Policies .Commons = cfg .Commons
335
- return policies .Execute (cfg .Policies )
345
+ return runServerCommand ( ctx , policies .Server (cfg .Policies ) )
336
346
})
337
347
areg (opts .Config .Invitations .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
338
348
cfg .Invitations .Context = ctx
339
349
cfg .Invitations .Commons = cfg .Commons
340
- return invitations .Execute (cfg .Invitations )
350
+ return runServerCommand ( ctx , invitations .Server (cfg .Invitations ) )
341
351
})
342
352
areg (opts .Config .Notifications .Service .Name , func (ctx context.Context , cfg * ociscfg.Config ) error {
343
353
cfg .Notifications .Context = ctx
344
354
cfg .Notifications .Commons = cfg .Commons
345
- return notifications .Execute (cfg .Notifications )
355
+ return runServerCommand ( ctx , notifications .Server (cfg .Notifications ) )
346
356
})
347
357
348
358
return s , nil
@@ -361,7 +371,7 @@ func Start(ctx context.Context, o ...Option) error {
361
371
}
362
372
363
373
// cancel the context when a signal is received.
364
- var cancel context.CancelFunc
374
+ var cancel context.CancelFunc = func () {}
365
375
if ctx == nil {
366
376
ctx , cancel = signal .NotifyContext (context .Background (), runner .StopSignals ... )
367
377
defer cancel ()
0 commit comments