-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from tgross/gh163_sighup_reload
Fix SIGHUP
- Loading branch information
Showing
15 changed files
with
305 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
integration_tests/fixtures/app/app-with-consul-prestart-sighup.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"consul": "consul:8500", | ||
"preStart": ["/reload-app-prestart.sh", "HUP"], | ||
"logging": { | ||
"level": "DEBUG", | ||
"format": "text" | ||
}, | ||
"services": [ | ||
{ | ||
"name": "app", | ||
"port": 8000, | ||
"health": "/usr/bin/curl --fail -s -o /dev/null http://localhost:8888", | ||
"poll": 1, | ||
"ttl": 5, | ||
"tags": ["application"] | ||
} | ||
], | ||
"backends": [ | ||
{ | ||
"name": "nginx", | ||
"poll": 7, | ||
"onChange": "/reload-app.sh" | ||
}, | ||
{ | ||
"name": "app", | ||
"poll": 5, | ||
"onChange": "/reload-app.sh", | ||
"tag": "application" | ||
} | ||
], | ||
"telemetry": { | ||
"port": 9090, | ||
"sensors": [ | ||
{ | ||
"namespace": "containerpilot", | ||
"subsystem": "app", | ||
"name": "some_counter", | ||
"help": "help text", | ||
"type": "counter", | ||
"poll": 1, | ||
"check": ["/sensor.sh", "count"] | ||
} | ||
] | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
integration_tests/fixtures/app/app-with-consul-prestart-sigusr1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"consul": "consul:8500", | ||
"preStart": ["/reload-app-prestart.sh", "USR1"], | ||
"logging": { | ||
"level": "DEBUG", | ||
"format": "text" | ||
}, | ||
"services": [ | ||
{ | ||
"name": "app", | ||
"port": 8000, | ||
"health": "/usr/bin/curl --fail -s -o /dev/null http://localhost:8000", | ||
"poll": 1, | ||
"ttl": 5, | ||
"tags": ["application"] | ||
} | ||
], | ||
"backends": [ | ||
{ | ||
"name": "nginx", | ||
"poll": 7, | ||
"onChange": "/reload-app.sh" | ||
}, | ||
{ | ||
"name": "app", | ||
"poll": 5, | ||
"onChange": "/reload-app.sh", | ||
"tag": "application" | ||
} | ||
], | ||
"telemetry": { | ||
"port": 9090, | ||
"sensors": [ | ||
{ | ||
"namespace": "containerpilot", | ||
"subsystem": "app", | ||
"name": "some_counter", | ||
"help": "help text", | ||
"type": "counter", | ||
"poll": 1, | ||
"check": ["/sensor.sh", "count"] | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
# Sends a signal to ContainerPilot during the preStart | ||
|
||
# wait a few seconds for the Consul container to become available | ||
n=0 | ||
while true | ||
do | ||
if [ n == 10 ]; then | ||
echo "Timed out waiting for Consul" | ||
exit 1; | ||
fi | ||
curl -Ls --fail http://consul:8500/v1/status/leader | grep 8300 && break | ||
n=$((n+1)) | ||
sleep 1 | ||
done | ||
|
||
if [[ ${1} == "HUP" ]]; then | ||
# Change our config to actually pass the healthcheck | ||
sed -i s/8888/8000/ /app-with-consul-prestart-sighup.json | ||
fi | ||
|
||
kill -${1} 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
integration_tests/fixtures/test_probe/src/test_sighup_prestart.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import "log" | ||
|
||
// The health check in the containerpilot config is intentionally | ||
// broken. The preStart script will fix the health check and then | ||
// SIGHUP to perform a config reload. | ||
func TestSigHupPrestart(args []string) bool { | ||
if len(args) != 1 { | ||
log.Println("TestSigHupPrestart requires 1 argument") | ||
log.Println(" - containerID: docker container to kill") | ||
return false | ||
} | ||
|
||
consul, err := NewConsulProbe() | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
// Wait for 1 healthy 'app' service to be registered with consul | ||
if err = consul.WaitForServices("app", "", 1); err != nil { | ||
log.Printf("Expected app to be healthy after SIGHUP: %s\n", err) | ||
return false | ||
} | ||
return true | ||
} |
34 changes: 34 additions & 0 deletions
34
integration_tests/fixtures/test_probe/src/test_sigusr1_prestart.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import "log" | ||
|
||
func TestSigUsr1Prestart(args []string) bool { | ||
if len(args) != 1 { | ||
log.Println("TestSigUsr1Prestart requires 1 argument") | ||
log.Println(" - containerID: docker container to kill") | ||
return false | ||
} | ||
|
||
docker, err := NewDockerProbe() | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
|
||
// Prestart will SIGUSR1 us into maintenance | ||
// Send SIGUSR1 to get us back out of maintenance | ||
if err = docker.SendSignal(args[0], SigUsr1); err != nil { | ||
log.Println(err) | ||
return false | ||
} | ||
|
||
// Wait for app to be healthy | ||
consul, err := NewConsulProbe() | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
if err = consul.WaitForServices("app", "", 1); err != nil { | ||
log.Printf("Expected app to be healthy after SIGUSR1: %s\n", err) | ||
return false | ||
} | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
integration_tests/tests/test_sighup_prestart/docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
consul: | ||
image: "cpfix_consul" | ||
mem_limit: 256m | ||
hostname: consul | ||
|
||
app: | ||
image: "cpfix_app" | ||
environment: | ||
- CONTAINERPILOT=file:///app-with-consul-prestart-sighup.json | ||
mem_limit: 512m | ||
links: | ||
- consul:consul | ||
volumes: | ||
- '${CONTAINERPILOT_BIN}:/bin/containerpilot:ro' | ||
|
||
test: | ||
image: "cpfix_test_probe" | ||
mem_limit: 128m | ||
links: | ||
- consul:consul | ||
- app:app | ||
volumes: | ||
- '/var/run/docker.sock:/var/run/docker.sock' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
docker-compose up -d consul app | ||
APP_ID="$(docker-compose ps -q app)" | ||
docker-compose run --no-deps test /go/bin/test_probe test_sighup_prestart $APP_ID > /dev/null 2>&1 | ||
result=$? | ||
TEST_ID=$(docker ps -l -f "ancestor=cpfix_test_probe" --format="{{.ID}}") | ||
if [ $result -ne 0 ]; then | ||
echo "==== TEST LOGS ====" | ||
docker logs $TEST_ID | ||
echo "==== APP LOGS ====" | ||
docker logs $APP_ID | ||
fi | ||
docker rm -f $TEST_ID > /dev/null 2>&1 | ||
exit $result |
Oops, something went wrong.