Skip to content

Instantly share code, notes, and snippets.

@witzatom
Last active December 18, 2019 10:42
Show Gist options
  • Save witzatom/af86296a3dbb444cb4f182887f1e76ae to your computer and use it in GitHub Desktop.
Save witzatom/af86296a3dbb444cb4f182887f1e76ae to your computer and use it in GitHub Desktop.
Script to use as a bootstrap step for polynote on EMR
#!/bin/bash
# Requirements (on non-EMR machines):
# * init-ctl or systemctl
# * packages python3.6 python3.6-venv python3.6-dev
# * python3 -V has to be 3.6+ (update-alternatives)
# * JAVA_HOME pointing to java 8 (openjdk or oracle)
# * SPARK_HOME set and included in PATH (see https://polynote.org/docs/01-installation.html)
set -ex
echo "Download and configure Polynote"
wget -N https://github.com/polynote/polynote/releases/download/0.2.10/polynote-dist.tar.gz -O /tmp/polynote-dist.tar.gz
tar -zxvpf /tmp/polynote-dist.tar.gz -C /tmp
cp /tmp/polynote/config-template.yml /tmp/polynote/config.yml
cat >> /tmp/polynote/config.yml <<- EOM
listen:
host: 0.0.0.0
port: 8192
spark:
spark.master: yarn
spark.submit.deployMode: cluster
spark.app.name: polynote
spark.driver.userClasspathFirst: true
spark.executor.userClasspathFirst: true
EOM
echo "Install Polynote"
sudo groupadd polynote | echo "group exists"
sudo usermod -aG polynote $USER
sudo rm -rf /opt/polynote
sudo mv /tmp/polynote /opt/
chown -R $USER /opt/polynote
echo "Instal python dependencies"
cd /opt/polynote
python3 -m venv polynote-env
source polynote-env/bin/activate && pip3 install jep jedi pyspark virtualenv pandas numpy matplotlib
if [[ `/sbin/init --version` =~ upstart ]]; then
echo "Configuring Polynote Upstart Service"
cat <<EOF > /tmp/polynote.conf
description "Polynote Server"
start on runlevel [2345]
stop on runlevel [016]
respawn
respawn limit unlimited
exec su -c "source /opt/polynote/polynote-env/bin/activate && /opt/polynote/polynote" $USER >> /var/log/polynote.log 2>&1
EOF
sudo mv /tmp/polynote.conf /etc/init/
sudo initctl reload-configuration
sudo initctl start polynote
elif [[ `systemctl` =~ -\.mount ]]; then
echo "Configuring Polynote Systemd Service"
cat <<EOF > /tmp/polynote.service
[Unit]
Description=Polynote Server
[Service]
Type=simple
User=$USER
ExecStart=/bin/bash -c "source /opt/polynote/polynote-env/bin/activate && /opt/polynote/polynote"
[Install]
WantedBy=multi-user.target
EOF
sudo mv /tmp/polynote.service /etc/systemd/system/
sudo chmod 644 /etc/systemd/system/polynote.service
sudo systemctl daemon-reload
sudo systemctl start polynote
else
echo "No service installed"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment