Skip to content

Commit 50fa39c

Browse files
authored
Merge pull request #11394 from owncloud/fix_server_data_race
fix: supervisor won't cause data races
2 parents 4dfead2 + 3f14bc4 commit 50fa39c

File tree

1 file changed

+51
-41
lines changed

1 file changed

+51
-41
lines changed

ocis/pkg/runtime/service/service.go

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
"github.com/owncloud/ocis/v2/ocis-pkg/runner"
1717
authapp "github.com/owncloud/ocis/v2/services/auth-app/pkg/command"
18+
"github.com/urfave/cli/v2"
1819

1920
"github.com/cenkalti/backoff"
2021
"github.com/mohae/deepcopy"
@@ -120,6 +121,15 @@ func NewService(ctx context.Context, options ...Option) (*Service, error) {
120121
cfg: opts.Config,
121122
}
122123

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+
123133
// populate services
124134
reg := func(priority int, name string, exec func(context.Context, *ociscfg.Config) error) {
125135
if s.Services[priority] == nil {
@@ -132,14 +142,14 @@ func NewService(ctx context.Context, options ...Option) (*Service, error) {
132142
reg(0, opts.Config.Nats.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
133143
cfg.Nats.Context = ctx
134144
cfg.Nats.Commons = cfg.Commons
135-
return nats.Execute(cfg.Nats)
145+
return runServerCommand(ctx, nats.Server(cfg.Nats))
136146
})
137147

138148
// gateway is in priority group 1. It needs to start before the reva services
139149
reg(1, opts.Config.Gateway.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
140150
cfg.Gateway.Context = ctx
141151
cfg.Gateway.Commons = cfg.Commons
142-
return gateway.Execute(cfg.Gateway)
152+
return runServerCommand(ctx, gateway.Server(cfg.Gateway))
143153
})
144154

145155
// priority group 2 is empty for now
@@ -148,157 +158,157 @@ func NewService(ctx context.Context, options ...Option) (*Service, error) {
148158
reg(3, opts.Config.Activitylog.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
149159
cfg.Activitylog.Context = ctx
150160
cfg.Activitylog.Commons = cfg.Commons
151-
return activitylog.Execute(cfg.Activitylog)
161+
return runServerCommand(ctx, activitylog.Server(cfg.Activitylog))
152162
})
153163
reg(3, opts.Config.AppProvider.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
154164
cfg.AppProvider.Context = ctx
155165
cfg.AppProvider.Commons = cfg.Commons
156-
return appProvider.Execute(cfg.AppProvider)
166+
return runServerCommand(ctx, appProvider.Server(cfg.AppProvider))
157167
})
158168
reg(3, opts.Config.AppRegistry.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
159169
cfg.AppRegistry.Context = ctx
160170
cfg.AppRegistry.Commons = cfg.Commons
161-
return appRegistry.Execute(cfg.AppRegistry)
171+
return runServerCommand(ctx, appRegistry.Server(cfg.AppRegistry))
162172
})
163173
reg(3, opts.Config.AuthBasic.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
164174
cfg.AuthBasic.Context = ctx
165175
cfg.AuthBasic.Commons = cfg.Commons
166-
return authbasic.Execute(cfg.AuthBasic)
176+
return runServerCommand(ctx, authbasic.Server(cfg.AuthBasic))
167177
})
168178
reg(3, opts.Config.AuthMachine.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
169179
cfg.AuthMachine.Context = ctx
170180
cfg.AuthMachine.Commons = cfg.Commons
171-
return authmachine.Execute(cfg.AuthMachine)
181+
return runServerCommand(ctx, authmachine.Server(cfg.AuthMachine))
172182
})
173183
reg(3, opts.Config.AuthService.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
174184
cfg.AuthService.Context = ctx
175185
cfg.AuthService.Commons = cfg.Commons
176-
return authservice.Execute(cfg.AuthService)
186+
return runServerCommand(ctx, authservice.Server(cfg.AuthService))
177187
})
178188
reg(3, opts.Config.Clientlog.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
179189
cfg.Clientlog.Context = ctx
180190
cfg.Clientlog.Commons = cfg.Commons
181-
return clientlog.Execute(cfg.Clientlog)
191+
return runServerCommand(ctx, clientlog.Server(cfg.Clientlog))
182192
})
183193
reg(3, opts.Config.EventHistory.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
184194
cfg.EventHistory.Context = ctx
185195
cfg.EventHistory.Commons = cfg.Commons
186-
return eventhistory.Execute(cfg.EventHistory)
196+
return runServerCommand(ctx, eventhistory.Server(cfg.EventHistory))
187197
})
188198
reg(3, opts.Config.Graph.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
189199
cfg.Graph.Context = ctx
190200
cfg.Graph.Commons = cfg.Commons
191-
return graph.Execute(cfg.Graph)
201+
return runServerCommand(ctx, graph.Server(cfg.Graph))
192202
})
193203
reg(3, opts.Config.Groups.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
194204
cfg.Groups.Context = ctx
195205
cfg.Groups.Commons = cfg.Commons
196-
return groups.Execute(cfg.Groups)
206+
return runServerCommand(ctx, groups.Server(cfg.Groups))
197207
})
198208
reg(3, opts.Config.IDM.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
199209
cfg.IDM.Context = ctx
200210
cfg.IDM.Commons = cfg.Commons
201-
return idm.Execute(cfg.IDM)
211+
return runServerCommand(ctx, idm.Server(cfg.IDM))
202212
})
203213
reg(3, opts.Config.OCDav.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
204214
cfg.OCDav.Context = ctx
205215
cfg.OCDav.Commons = cfg.Commons
206-
return ocdav.Execute(cfg.OCDav)
216+
return runServerCommand(ctx, ocdav.Server(cfg.OCDav))
207217
})
208218
reg(3, opts.Config.OCS.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
209219
cfg.OCS.Context = ctx
210220
cfg.OCS.Commons = cfg.Commons
211-
return ocs.Execute(cfg.OCS)
221+
return runServerCommand(ctx, ocs.Server(cfg.OCS))
212222
})
213223
reg(3, opts.Config.Postprocessing.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
214224
cfg.Postprocessing.Context = ctx
215225
cfg.Postprocessing.Commons = cfg.Commons
216-
return postprocessing.Execute(cfg.Postprocessing)
226+
return runServerCommand(ctx, postprocessing.Server(cfg.Postprocessing))
217227
})
218228
reg(3, opts.Config.Search.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
219229
cfg.Search.Context = ctx
220230
cfg.Search.Commons = cfg.Commons
221-
return search.Execute(cfg.Search)
231+
return runServerCommand(ctx, search.Server(cfg.Search))
222232
})
223233
reg(3, opts.Config.Settings.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
224234
cfg.Settings.Context = ctx
225235
cfg.Settings.Commons = cfg.Commons
226-
return settings.Execute(cfg.Settings)
236+
return runServerCommand(ctx, settings.Server(cfg.Settings))
227237
})
228238
reg(3, opts.Config.StoragePublicLink.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
229239
cfg.StoragePublicLink.Context = ctx
230240
cfg.StoragePublicLink.Commons = cfg.Commons
231-
return storagepublic.Execute(cfg.StoragePublicLink)
241+
return runServerCommand(ctx, storagepublic.Server(cfg.StoragePublicLink))
232242
})
233243
reg(3, opts.Config.StorageShares.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
234244
cfg.StorageShares.Context = ctx
235245
cfg.StorageShares.Commons = cfg.Commons
236-
return storageshares.Execute(cfg.StorageShares)
246+
return runServerCommand(ctx, storageshares.Server(cfg.StorageShares))
237247
})
238248
reg(3, opts.Config.StorageSystem.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
239249
cfg.StorageSystem.Context = ctx
240250
cfg.StorageSystem.Commons = cfg.Commons
241-
return storageSystem.Execute(cfg.StorageSystem)
251+
return runServerCommand(ctx, storageSystem.Server(cfg.StorageSystem))
242252
})
243253
reg(3, opts.Config.StorageUsers.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
244254
cfg.StorageUsers.Context = ctx
245255
cfg.StorageUsers.Commons = cfg.Commons
246-
return storageusers.Execute(cfg.StorageUsers)
256+
return runServerCommand(ctx, storageusers.Server(cfg.StorageUsers))
247257
})
248258
reg(3, opts.Config.Thumbnails.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
249259
cfg.Thumbnails.Context = ctx
250260
cfg.Thumbnails.Commons = cfg.Commons
251-
return thumbnails.Execute(cfg.Thumbnails)
261+
return runServerCommand(ctx, thumbnails.Server(cfg.Thumbnails))
252262
})
253263
reg(3, opts.Config.Userlog.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
254264
cfg.Userlog.Context = ctx
255265
cfg.Userlog.Commons = cfg.Commons
256-
return userlog.Execute(cfg.Userlog)
266+
return runServerCommand(ctx, userlog.Server(cfg.Userlog))
257267
})
258268
reg(3, opts.Config.Users.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
259269
cfg.Users.Context = ctx
260270
cfg.Users.Commons = cfg.Commons
261-
return users.Execute(cfg.Users)
271+
return runServerCommand(ctx, users.Server(cfg.Users))
262272
})
263273
reg(3, opts.Config.Web.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
264274
cfg.Web.Context = ctx
265275
cfg.Web.Commons = cfg.Commons
266-
return web.Execute(cfg.Web)
276+
return runServerCommand(ctx, web.Server(cfg.Web))
267277
})
268278
reg(3, opts.Config.WebDAV.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
269279
cfg.WebDAV.Context = ctx
270280
cfg.WebDAV.Commons = cfg.Commons
271-
return webdav.Execute(cfg.WebDAV)
281+
return runServerCommand(ctx, webdav.Server(cfg.WebDAV))
272282
})
273283
reg(3, opts.Config.Webfinger.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
274284
cfg.Webfinger.Context = ctx
275285
cfg.Webfinger.Commons = cfg.Commons
276-
return webfinger.Execute(cfg.Webfinger)
286+
return runServerCommand(ctx, webfinger.Server(cfg.Webfinger))
277287
})
278288
reg(3, opts.Config.IDP.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
279289
cfg.IDP.Context = ctx
280290
cfg.IDP.Commons = cfg.Commons
281-
return idp.Execute(cfg.IDP)
291+
return runServerCommand(ctx, idp.Server(cfg.IDP))
282292
})
283293
reg(3, opts.Config.Proxy.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
284294
cfg.Proxy.Context = ctx
285295
cfg.Proxy.Commons = cfg.Commons
286-
return proxy.Execute(cfg.Proxy)
296+
return runServerCommand(ctx, proxy.Server(cfg.Proxy))
287297
})
288298
reg(3, opts.Config.Sharing.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
289299
cfg.Sharing.Context = ctx
290300
cfg.Sharing.Commons = cfg.Commons
291-
return sharing.Execute(cfg.Sharing)
301+
return runServerCommand(ctx, sharing.Server(cfg.Sharing))
292302
})
293303
reg(3, opts.Config.SSE.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
294304
cfg.SSE.Context = ctx
295305
cfg.SSE.Commons = cfg.Commons
296-
return sse.Execute(cfg.SSE)
306+
return runServerCommand(ctx, sse.Server(cfg.SSE))
297307
})
298308
reg(3, opts.Config.OCM.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
299309
cfg.OCM.Context = ctx
300310
cfg.OCM.Commons = cfg.Commons
301-
return ocm.Execute(cfg.OCM)
311+
return runServerCommand(ctx, ocm.Server(cfg.OCM))
302312
})
303313

304314
// 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) {
307317
reg(4, opts.Config.Frontend.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
308318
cfg.Frontend.Context = ctx
309319
cfg.Frontend.Commons = cfg.Commons
310-
return frontend.Execute(cfg.Frontend)
320+
return runServerCommand(ctx, frontend.Server(cfg.Frontend))
311321
})
312322

313323
// populate optional services
@@ -317,32 +327,32 @@ func NewService(ctx context.Context, options ...Option) (*Service, error) {
317327
areg(opts.Config.Antivirus.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
318328
cfg.Antivirus.Context = ctx
319329
// cfg.Antivirus.Commons = cfg.Commons // antivirus holds no Commons atm
320-
return antivirus.Execute(cfg.Antivirus)
330+
return runServerCommand(ctx, antivirus.Server(cfg.Antivirus))
321331
})
322332
areg(opts.Config.Audit.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
323333
cfg.Audit.Context = ctx
324334
cfg.Audit.Commons = cfg.Commons
325-
return audit.Execute(cfg.Audit)
335+
return runServerCommand(ctx, audit.Server(cfg.Audit))
326336
})
327337
areg(opts.Config.AuthApp.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
328338
cfg.AuthApp.Context = ctx
329339
cfg.AuthApp.Commons = cfg.Commons
330-
return authapp.Execute(cfg.AuthApp)
340+
return runServerCommand(ctx, authapp.Server(cfg.AuthApp))
331341
})
332342
areg(opts.Config.Policies.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
333343
cfg.Policies.Context = ctx
334344
cfg.Policies.Commons = cfg.Commons
335-
return policies.Execute(cfg.Policies)
345+
return runServerCommand(ctx, policies.Server(cfg.Policies))
336346
})
337347
areg(opts.Config.Invitations.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
338348
cfg.Invitations.Context = ctx
339349
cfg.Invitations.Commons = cfg.Commons
340-
return invitations.Execute(cfg.Invitations)
350+
return runServerCommand(ctx, invitations.Server(cfg.Invitations))
341351
})
342352
areg(opts.Config.Notifications.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
343353
cfg.Notifications.Context = ctx
344354
cfg.Notifications.Commons = cfg.Commons
345-
return notifications.Execute(cfg.Notifications)
355+
return runServerCommand(ctx, notifications.Server(cfg.Notifications))
346356
})
347357

348358
return s, nil
@@ -361,7 +371,7 @@ func Start(ctx context.Context, o ...Option) error {
361371
}
362372

363373
// cancel the context when a signal is received.
364-
var cancel context.CancelFunc
374+
var cancel context.CancelFunc = func() {}
365375
if ctx == nil {
366376
ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...)
367377
defer cancel()

0 commit comments

Comments
 (0)