add gateway (part)
[arvados.git] / services / boot / postgresql.go
1 package main
2
3 import (
4         "context"
5         "os"
6         "time"
7 )
8
9 var postgresql = &pgBooter{}
10
11 type pgBooter struct {}
12
13 func (pb *pgBooter) Boot(ctx context.Context) error {
14         os.Setenv("LANG", "en_US.utf8")
15         // TODO: return nil if this isn't the database host.
16         if pb.check(ctx) == nil {
17                 return nil
18         }
19         if err := (&osPackage{
20                 Debian: "locales",
21         }).Boot(ctx); err != nil {
22                 return err
23         }
24         if err := command("bash", "-c", "echo ${LANG} UTF-8 | tee -a /etc/locale.gen && locale-gen -a").Run(); err != nil {
25                 return err
26         }
27         if err := (&osPackage{
28                 Debian: "postgresql",
29         }).Boot(ctx); err != nil {
30                 return err
31         }
32         if err := command("service", "postgresql", "start").Run(); err != nil {
33                 return err
34         }
35         return waitCheck(ctx, 30*time.Second, pb.check)
36 }
37
38 func (pb *pgBooter) check(ctx context.Context) error {
39         return command("pg_isready").Run()
40 }