MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / startPool

Function startPool

main.go:187–236  ·  view source on GitHub ↗
(pool Service, lifecycle service.Lifecycle)

Source from the content-addressed store, hash-verified

185}
186
187func startPool(pool Service, lifecycle service.Lifecycle) error {
188 starting := make(chan struct{})
189 lifecycle.OnStarting(
190 func(s service.Service, l service.Lifecycle) {
191 starting <- struct{}{}
192 },
193 )
194 go func() {
195 _ = lifecycle.Run()
196 }()
197
198 <-starting
199
200 exitSignalList := []os.Signal{os.Interrupt, os.Kill, syscall.SIGINT, syscall.SIGTERM}
201 rotateSignalList := []os.Signal{syscall.SIGHUP}
202 exitSignals := make(chan os.Signal, 1)
203 rotateSignals := make(chan os.Signal, 1)
204 signal.Notify(exitSignals, exitSignalList...)
205 signal.Notify(rotateSignals, rotateSignalList...)
206 go func() {
207 if _, ok := <-exitSignals; ok {
208 // ok means the channel wasn't closed
209 shutdownContext, cancelFunc := context.WithTimeout(
210 context.Background(),
211 20*time.Second,
212 )
213 defer cancelFunc()
214 lifecycle.Stop(
215 shutdownContext,
216 )
217 }
218 }()
219 go func() {
220 for {
221 if _, ok := <-rotateSignals; ok {
222 err := pool.RotateLogs()
223 if err != nil {
224 panic(err)
225 }
226 } else {
227 break
228 }
229 }
230 }()
231 err := lifecycle.Wait()
232 signal.Ignore(rotateSignalList...)
233 signal.Ignore(exitSignalList...)
234 close(exitSignals)
235 return err
236}
237
238func generateHostKeys(configFile string, cfg *config.AppConfig, logger log.Logger) error {
239 if err := cfg.SSH.GenerateHostKey(); err != nil {

Callers 1

startServicesFunction · 0.85

Calls 5

OnStartingMethod · 0.65
RunMethod · 0.65
StopMethod · 0.65
RotateLogsMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected