There are many ways to parse in variable into the nginx config file.
Some uses set_by_lua
which is offered by lua-nginx-module.
Some use envstubst
to populate varilabes into a template file.
Today I am going to show you how to do that with njs
the JS scripting engine for nginx.
## /etc/nginx/fetch_env.js
function fetch_upstream_host(r) {
return process.env.UPSTREAM_HOST;
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
#!/bin/bash | |
if [ $1 = "1" ]; then | |
curl -XPOST -H "Content-type: application/json" -d '{"method":"passthrough", | |
"params": {"deviceId": "DEVICEID", | |
"requestData": "{\"system\":{\"set_relay_state\":{\"state\":1}}}" } | |
}' 'https://eu-wap.tplinkcloud.com?token=TOKEN' | |
else | |
curl -XPOST -H "Content-type: application/json" -d '{"method":"passthrough", | |
"params": {"deviceId": "DEVICEID", | |
"requestData": "{\"system\":{\"set_relay_state\":{\"state\":0}}}" } |
A docker entrypoint must ensure that after any initialization (environmanet setup etc.) the main docker
process must remain at PID 1. This is usually accomplished by using exec
as the last command (which
actually replaces the current process).
See also: https://docs.docker.com/engine/reference/builder/#entrypoint
An example entrypoint.sh
:
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
/** | |
* Check if a given ip is in a network | |
* @param string $ip IP to check in IPV4 format eg. 127.0.0.1 | |
* @param string $range IP/CIDR netmask eg. 127.0.0.0/24, also 127.0.0.1 is accepted and /32 assumed | |
* @return boolean true if the ip is in this range / false if not. | |
*/ | |
function ip_in_range( $ip, $range ) { | |
if ( strpos( $range, '/' ) == false ) { | |
$range .= '/32'; | |
} |
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
-- show running queries (pre 9.2) | |
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query | |
FROM pg_stat_activity | |
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%' | |
ORDER BY query_start desc; | |
-- show running queries (9.2) | |
SELECT pid, age(clock_timestamp(), query_start), usename, query | |
FROM pg_stat_activity | |
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' |
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
var net = require("net"); | |
process.on("uncaughtException", function(error) { | |
console.error(error); | |
}); | |
if (process.argv.length != 5) { | |
console.log("usage: %s <localport> <remotehost> <remoteport>", process.argv[1]); | |
process.exit(); | |
} |
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
#!/bin/bash | |
# | |
# Do a ping and output results as CSV. | |
# | |
# [email protected] | |
# 2011-12-23 | |
# | |
if [ $# -lt 1 ]; then | |
echo "Usage: $0 [--add-timestamp] <ping host>" |