Skip to content

Instantly share code, notes, and snippets.

@xuru
Last active June 23, 2020 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xuru/9606466bb723955d4447ee23304f6872 to your computer and use it in GitHub Desktop.
Save xuru/9606466bb723955d4447ee23304f6872 to your computer and use it in GitHub Desktop.
template
#!/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
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: "somebody@somewhere.com"},
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment