Last active
June 23, 2020 23:19
-
-
Save xuru/9606466bb723955d4447ee23304f6872 to your computer and use it in GitHub Desktop.
template
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 | |
set -e | |
# This script stops a SageMaker notebook once it's idle for more than 1 hour (default time) | |
# You can change the idle time for stop using the environment variable below. | |
# If you want the notebook the stop only if no browsers are open, remove the --ignore-connections flag | |
IDLE_TIME=10800 | |
echo "Fetching the autostop script" | |
wget https://raw.githubusercontent.com/aws-samples/amazon-sagemaker-notebook-instance-lifecycle-config-samples/master/scripts/auto-stop-idle/autostop.py | |
echo "Starting the SageMaker autostop script in cron" | |
(crontab -l 2>/dev/null; echo "5 * * * * /usr/bin/python $PWD/autostop.py --time $IDLE_TIME") | crontab - | |
# This script sets username and email address in Git config | |
sudo -u ec2-user -i <<EOF | |
git config --global user.name "${gitConfig.name}" | |
git config --global user.email "${gitConfig.email}" | |
EOF | |
# Set PYTHONPATH (modified from https://github.com/aws-samples/amazon-sagemaker-notebook-instance-lifecycle-config-samples/blob/master/scripts/set-env-variable/on-start.sh) | |
touch /etc/profile.d/jupyter-env.sh | |
echo "export PYTHONPATH=/home/ec2-user/SageMaker/oslo" >> /etc/profile.d/jupyter-env.sh | |
initctl restart jupyter-server --no-wait |
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
export const templatized = (template: string, vars = {}) => { | |
const handler = new Function( | |
"vars", | |
[ | |
"const tagged = ( " + Object.keys(vars).join(", ") + " ) =>", | |
"`" + template + "`", | |
"return tagged(...Object.values(vars))", | |
].join("\n"), | |
); | |
return handler(vars); | |
}; | |
let templateString1 = fs.readFileSync("./onStart.sh", "utf8"); | |
console.log(templatized(templateString1, { | |
gitConfig: {name: "Some Body", email: "[email protected]"}, | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment