Skip to content

Instantly share code, notes, and snippets.

@guweigang
Created May 13, 2016 02:52
Show Gist options
  • Save guweigang/8b23ec6fcc86f182c1bcc34a784e6979 to your computer and use it in GitHub Desktop.
Save guweigang/8b23ec6fcc86f182c1bcc34a784e6979 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Function to update the fpm configuration to make the service environment variables available
setEnvironmentVariable() {
if [ -z "$2" ]; then
echo "Environment variable '$1' not set."
return
fi
# Check whether variable already exists
if grep -q $1 /etc/php5/fpm/pool.d/www.conf; then
# Reset variable
sed -i "s/^env\[$1.*/env[$1] = $2/g" /etc/php5/fpm/pool.d/www.conf
else
# Add variable
echo "env[$1] = $2" >> /etc/php5/fpm/pool.d/www.conf
fi
}
echo "[ENV]"
# Grep for variables that look like docker set them (_PORT_)
for curVar in $(su - work -c 'env' | grep PHP_);do
# awk has split them by the equals sign
# Pass the name and value to our function
echo ${curVar}
key=$(echo ${curVar} | awk -F = '{print $1}')
val=$(echo ${curVar} | awk -F = '{print $2}')
setEnvironmentVariable ${key} ${val}
done
echo "---------------------"
echo "Restart PHP-FPM ..."
kill -TERM $(cat /var/run/php5-fpm.pid)
echo "DONE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment