go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/logdog/appengine/cmd/coordinator/default/main.go (about) 1 // Copyright 2015 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Binary default is a simple AppEngine LUCI service. It supplies basic LUCI 16 // service frontend and backend functionality. 17 // 18 // No RPC requests should target this service; instead, they are redirected to 19 // the appropriate service via "dispatch.yaml". 20 package main 21 22 import ( 23 "net/http" 24 25 "go.chromium.org/luci/common/errors" 26 "go.chromium.org/luci/config/server/cfgmodule" 27 logsPb "go.chromium.org/luci/logdog/api/endpoints/coordinator/logs/v1" 28 registrationPb "go.chromium.org/luci/logdog/api/endpoints/coordinator/registration/v1" 29 servicesPb "go.chromium.org/luci/logdog/api/endpoints/coordinator/services/v1" 30 "go.chromium.org/luci/logdog/server/config" 31 32 "go.chromium.org/luci/server" 33 "go.chromium.org/luci/server/cron" 34 "go.chromium.org/luci/server/gaeemulation" 35 "go.chromium.org/luci/server/module" 36 "go.chromium.org/luci/server/router" 37 ) 38 39 // main is the entrypoint for the `default` service. 40 func main() { 41 modules := []module.Module{ 42 cfgmodule.NewModuleFromFlags(), 43 cron.NewModuleFromFlags(), 44 gaeemulation.NewModuleFromFlags(), // For datastore support. 45 } 46 47 server.Main(nil, modules, func(srv *server.Server) error { 48 // Install the in-memory cache for configs in datastore, warm it up. 49 srv.Context = config.WithStore(srv.Context, &config.Store{}) 50 if _, err := config.Config(srv.Context); err != nil { 51 return errors.Annotate(err, "failed to fetch the initial service config").Err() 52 } 53 54 // Register dummy pRPC services (for RPC explorer discovery only). 55 // 56 // Note that most of these services have dedicated services to 57 // handle them, and any RPCs sent to this module will automatically 58 // be routed to them via "dispatch.yaml". 59 logsPb.RegisterLogsServer(srv, dummyLogsService) 60 registrationPb.RegisterRegistrationServer(srv, dummyRegistrationService) 61 servicesPb.RegisterServicesServer(srv, dummyServicesService) 62 63 // Register cron job handlers. 64 cron.RegisterHandler("sync-configs", config.Sync) 65 66 // Register UI routes. 67 srv.Routes.GET("/", nil, func(c *router.Context) { 68 http.Redirect(c.Writer, c.Request, "/rpcexplorer/", http.StatusFound) 69 }) 70 srv.Routes.GET("/v/", nil, func(c *router.Context) { 71 path := "/logs/" + c.Request.URL.Query().Get("s") 72 http.Redirect(c.Writer, c.Request, path, http.StatusFound) 73 }) 74 return nil 75 }) 76 }