dev privileges, db
[arvados.git] / services / boot / postgresql.go
1 package main
2
3 import (
4         "context"
5         "time"
6 )
7
8 var postgresql = &pgBooter{}
9
10 type pgBooter struct {}
11
12 func (pb *pgBooter) Boot(ctx context.Context) error {
13         // TODO: return nil if this isn't the database host.
14         if pb.check(ctx) == nil {
15                 return nil
16         }
17         if err := (&osPackage{
18                 Debian: "postgresql",
19         }).Boot(ctx); err != nil {
20                 return err
21         }
22         if err := command("service", "postgresql", "start").Run(); err != nil {
23                 return err
24         }
25         return waitCheck(ctx, 30*time.Second, pb.check)
26 }
27
28 func (pb *pgBooter) check(ctx context.Context) error {
29         return command("pg_isready").Run()
30 }