Skip to content

Instantly share code, notes, and snippets.

@krohne
Last active January 11, 2019 20:21
Show Gist options
  • Save krohne/3268aedbae3445cd59d6c78efa9fbb3b to your computer and use it in GitHub Desktop.
Save krohne/3268aedbae3445cd59d6c78efa9fbb3b to your computer and use it in GitHub Desktop.
Turn logging level up or down on remote platform
#!/bin/bash
# Your bastion username should be in ~/.ssh/config
# on|off platform [container]
# on preprod tripnotificationagent
export setting=$1
export platform=$2
export container=$3
if [ -z ${container} ]; then export container=$(grep '"name":\s*"\w*",' $PWD/package.json | awk -F '"' '{ print $4 }'); fi
export service="rmpay_${container}_1"
case $setting in
on)
ssh $platform /bin/bash << EOF
docker cp $service:/usr/src/app/launch.sh .
sed -i '/DEBUG=.*/c\export NODE_APP_LOGLEVEL=debug\nexport NODE_APPLICATION_LOGLEVEL=debug\nexport NODE_DEBUG='*'\nDEBUG='*' node --optimize_for_size --max_old_space_size=$DOCKER_NODE_VM_HEAP_LIMIT server.js &' launch.sh
docker cp launch.sh $service:/usr/src/app/launch.sh
docker restart $service
EOF
;;
off)
ssh $platform /bin/bash << EOF
docker cp $service:/usr/src/app/launch.sh .
sed -i '/export NODE_.*/d' launch.sh
sed -i 's/DEBUG=.*/DEBUG=${NODE_APPLICATION_DEBUG} node --optimize_for_size --max_old_space_size=$DOCKER_NODE_VM_HEAP_LIMIT server.js &/' launch.sh
docker cp launch.sh $service:/usr/src/app/launch.sh
docker restart $service
EOF
;;
*)
echo "Logging parameter must be set to 'on' or 'off'"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment