Try to make supervisor less broken
This commit is contained in:
parent
7f8402f52e
commit
ea35395027
|
@ -21,7 +21,6 @@ function computeImageHashes() {
|
||||||
}
|
}
|
||||||
imageHashes[lang] = imageHash;
|
imageHashes[lang] = imageHash;
|
||||||
}
|
}
|
||||||
console.log(imageHashes);
|
|
||||||
return imageHashes;
|
return imageHashes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,14 @@
|
||||||
Description=Riju online coding sandbox
|
Description=Riju online coding sandbox
|
||||||
Requires=docker.service
|
Requires=docker.service
|
||||||
After=docker.service
|
After=docker.service
|
||||||
|
StartLimitBurst=5
|
||||||
|
StartLimitIntervalSec=300
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=exec
|
Type=exec
|
||||||
ExecStart=riju-supervisor
|
ExecStart=riju-supervisor
|
||||||
Restart=always
|
Restart=always
|
||||||
|
RestartSec=5
|
||||||
Environment=AWS_REGION=$AWS_REGION
|
Environment=AWS_REGION=$AWS_REGION
|
||||||
Environment=S3_BUCKET=$S3_BUCKET
|
Environment=S3_BUCKET=$S3_BUCKET
|
||||||
Environment=SUPERVISOR_ACCESS_TOKEN=$SUPERVISOR_ACCESS_TOKEN
|
Environment=SUPERVISOR_ACCESS_TOKEN=$SUPERVISOR_ACCESS_TOKEN
|
||||||
|
|
|
@ -350,6 +350,7 @@ func (sv *supervisor) reload() error {
|
||||||
"-e", "ANALYTICS=1",
|
"-e", "ANALYTICS=1",
|
||||||
"--label", fmt.Sprintf("riju.deploy-config-hash=%s", deployCfgHash),
|
"--label", fmt.Sprintf("riju.deploy-config-hash=%s", deployCfgHash),
|
||||||
"--name", name,
|
"--name", name,
|
||||||
|
"--restart=unless-stopped",
|
||||||
fmt.Sprintf("riju:%s", deployCfg.AppImageTag),
|
fmt.Sprintf("riju:%s", deployCfg.AppImageTag),
|
||||||
)
|
)
|
||||||
dockerRun.Stdout = os.Stdout
|
dockerRun.Stdout = os.Stdout
|
||||||
|
@ -387,7 +388,7 @@ func (sv *supervisor) reload() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var rijuContainerRegexp = regexp.MustCompile(`^([^:]+):(.+)$`)
|
var rijuContainerRegexp = regexp.MustCompile(`^([^|]+):([^|]+)\|([^|]+)$`)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
supervisorCfg := supervisorConfig{}
|
supervisorCfg := supervisorConfig{}
|
||||||
|
@ -424,7 +425,7 @@ func main() {
|
||||||
|
|
||||||
dockerContainerLs := exec.Command(
|
dockerContainerLs := exec.Command(
|
||||||
"docker", "container", "ls", "-a",
|
"docker", "container", "ls", "-a",
|
||||||
"--format", "{{ .Names }}:{{ .CreatedAt }}",
|
"--format", "{{ .Names }}|{{ .CreatedAt }}|{{ .State }}",
|
||||||
)
|
)
|
||||||
dockerContainerLs.Stderr = os.Stderr
|
dockerContainerLs.Stderr = os.Stderr
|
||||||
out, err := dockerContainerLs.Output()
|
out, err := dockerContainerLs.Output()
|
||||||
|
@ -444,6 +445,17 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
running := match[3] == "running"
|
||||||
|
if !running {
|
||||||
|
log.Printf("deleting container %s as it is stopped\n", name)
|
||||||
|
dockerRm := exec.Command("docker", "rm", "-f", name)
|
||||||
|
dockerRm.Stdout = os.Stdout
|
||||||
|
dockerRm.Stderr = os.Stderr
|
||||||
|
if err := dockerRm.Run(); err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
if name == blueName {
|
if name == blueName {
|
||||||
blueRunningSince = &created
|
blueRunningSince = &created
|
||||||
continue
|
continue
|
||||||
|
@ -460,7 +472,7 @@ func main() {
|
||||||
if blueRunningSince == nil && greenRunningSince == nil {
|
if blueRunningSince == nil && greenRunningSince == nil {
|
||||||
log.Println("did not detect any existing containers")
|
log.Println("did not detect any existing containers")
|
||||||
isGreen = false
|
isGreen = false
|
||||||
isRunning = true
|
isRunning = false
|
||||||
} else if blueRunningSince != nil && greenRunningSince == nil {
|
} else if blueRunningSince != nil && greenRunningSince == nil {
|
||||||
log.Println("detected existing blue container")
|
log.Println("detected existing blue container")
|
||||||
isGreen = false
|
isGreen = false
|
||||||
|
@ -501,7 +513,7 @@ func main() {
|
||||||
name = blueName
|
name = blueName
|
||||||
}
|
}
|
||||||
dockerInspect := exec.Command(
|
dockerInspect := exec.Command(
|
||||||
"docker", "inspect", name, "-f",
|
"docker", "container", "inspect", name, "-f",
|
||||||
`{{ index .Config.Labels "riju.deploy-config-hash" }}`,
|
`{{ index .Config.Labels "riju.deploy-config-hash" }}`,
|
||||||
)
|
)
|
||||||
dockerInspect.Stderr = os.Stderr
|
dockerInspect.Stderr = os.Stderr
|
||||||
|
|
Loading…
Reference in New Issue