-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
96 additions
and
67 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,2 @@ | ||
#!/bin/sh | ||
set -x | ||
|
||
_init () { | ||
scheme="http://" | ||
address="$(netstat -nplt 2>/dev/null | awk ' /(.*\/laravel-echo-serv)/ { gsub(":::","127.0.0.1:",$4); print $4}')" | ||
resource="/socket.io/socket.io.js" | ||
start=$(stat -c "%Y" /proc/1) | ||
} | ||
|
||
fn_health_check () { | ||
# In distributed environment like Swarm, traffic is routed | ||
# to a container only when it reports a `healthy` status. So, we exit | ||
# with 0 to ensure healthy status till distributed service starts (120s). | ||
# | ||
# Refer: https://github.com/moby/moby/pull/28938#issuecomment-301753272 | ||
if [[ $(( $(date +%s) - start )) -lt 120 ]]; then | ||
exit 0 | ||
else | ||
# Get the http response code | ||
http_response=$(curl -s -k -o /dev/null -w "%{http_code}" ${scheme}${address}${resource}) | ||
|
||
# Get the http response body | ||
http_response_body=$(curl -k -s ${scheme}${address}${resource}) | ||
|
||
# server returns response 403 and body "SSL required" if non-TLS | ||
# connection is attempted on a TLS-configured server. Change | ||
# the scheme and try again | ||
if [[ "$http_response" = "403" ]] && [[ "$http_response_body" = "SSL required" ]]; then | ||
scheme="https://" | ||
http_response=$(curl -s -k -o /dev/null -w "%{http_code}" ${scheme}${address}${resource}) | ||
fi | ||
|
||
# If http_response is 200 - server is up. | ||
[[ "$http_response" = "200" ]] | ||
fi | ||
} | ||
|
||
_init && fn_health_check | ||
node /usr/local/src/healthcheck.js |
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 @@ | ||
{ | ||
"apiOriginAllow": {}, | ||
"authEndpoint": "/broadcasting/auth", | ||
"authHost": "http://localhost", | ||
"clients": [], | ||
"database": "sqlite", | ||
"databaseConfig": { | ||
"sqlite": { | ||
"databasePath": "/database/laravel-echo-server.sqlite" | ||
}, | ||
"publishPresence": true | ||
}, | ||
"devMode": false, | ||
"host": null, | ||
"port": 6001, | ||
"protocol": "http", | ||
"sslCertPath": "", | ||
"sslKeyPath": "", | ||
"sslCertChainPath": "", | ||
"sslPassphrase": "", | ||
"socketio": { | ||
"path": "/example.io" | ||
}, | ||
"subscribers": {"http": 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// See https://blog.sixeyed.com/docker-healthchecks-why-not-to-use-curl-or-iwr/ | ||
|
||
var http = require("http"); | ||
var config = {}; | ||
|
||
try { | ||
config = require("/app/laravel-echo-server.json"); | ||
} catch (error) { | ||
} | ||
|
||
var options = { | ||
host : "localhost", | ||
port : config.port | 6001, | ||
path : `${config.socketio && config.socketio.path ? config.socketio.path : '/socket.io'}/socket.io.js`, | ||
timeout : 2000 | ||
}; | ||
|
||
var request = http.request(options, (res) => { | ||
console.log(`STATUS: ${res.statusCode}`); | ||
if (res.statusCode == 200) { | ||
process.exit(0); | ||
} else { | ||
process.exit(1); | ||
} | ||
}); | ||
|
||
request.on('error', function(err) { | ||
console.log('ERROR'); | ||
process.exit(1); | ||
}); | ||
|
||
request.end(); |