11#! /bin/bash
22
33GEOWAVE_VER=${1:- $GEOWAVE_VERSION_TOKEN }
4-
54JUPYTER_PASSWORD=${2-geowave}
65
6+ is_master () {
7+ if [ $( jq ' .isMaster' /mnt/var/lib/info/instance.json) = ' true' ]; then
8+ return 0
9+ else
10+ return 1
11+ fi
12+ }
13+
714# I've externalized commands into library functions for clarity, download and source
815if [ ! -f /tmp/create-configure-kernel.sh ]; then
916 aws s3 cp s3://geowave/$GEOWAVE_VERSION_URL_TOKEN /scripts/emr/jupyter/create-configure-kernel.sh /tmp/create-configure-kernel.sh
1017fi
11- source /tmp/create-configure-kernel.sh
18+
19+ if [ ! -f /tmp/install-conda.sh ]; then
20+ aws s3 cp s3://geowave/$GEOWAVE_VERSION_URL_TOKEN /scripts/emr/jupyter/install-conda.sh /tmp/install-conda.sh
21+ sudo chmod +x /tmp/install-conda.sh
22+ fi
1223
1324# The EMR customize hooks run _before_ everything else, so Spark is not yet ready
1425THIS_SCRIPT=" $( realpath " ${BASH_SOURCE[0]} " ) "
@@ -22,48 +33,20 @@ if [ ! -f "$RUN_FLAG" ]; then
2233 exit 0 # Bail and let EMR finish initializing
2334fi
2435
25- # Install conda
26- wget https://repo.continuum.io/miniconda/Miniconda3-4.2.12-Linux-x86_64.sh -O $HOME /miniconda.sh
27-
2836# Download example notebooks from s3
29- aws s3 sync s3://geowave-notebooks/$GEOWAVE_VERSION_URL_TOKEN /notebooks/ $HOME /notebooks/
30-
31- # Modify the file permissions to allow execution within this shell
32- chmod +x $HOME /miniconda.sh
33-
34- # Install miniconda and output directory to ~/conda
35- $HOME /miniconda.sh -b -p $HOME /conda
36-
37- # Add Conda to the path
38- printf ' \nexport PATH=$HOME/conda/bin:$PATH' >> $HOME /.bashrc
39-
40- # Source the new PATH
41- source $HOME /.bashrc
37+ aws s3 sync s3://geowave-notebooks/latest/notebooks/ $HOME /notebooks/
4238
43- # Setup conda to use the correct channel for pixiedust prerequisites
44- conda config --set always_yes yes --set changeps1 no
45- conda config -f --add channels conda-forge
46-
47- # Install the necessary components for jupyter and pixiedust
48- conda install jupyter matplotlib numpy pandas pyyaml requests shapely folium owslib
49-
50- # cleanup
51- rm ~ /miniconda.sh
39+ source /tmp/install-conda.sh
5240
5341echo bootstrap_conda.sh completed. PATH now: $PATH
5442
5543echo Performing pixiedust and jupyter kernel setup.
5644
57- # setup python 3.5 in the master and workers
58- printf " \nexport PYSPARK_PYTHON=$HOME /conda/bin/python3.5" >> $HOME /.bashrc
59- printf " \nexport PYSPARK_DRIVER_PYTHON=$HOME /conda/bin/python3.5" >> $HOME /.bashrc
60- # This was added because Upstart doesn't capture user environment variables before loading jupyter
61- printf " \nexport HOSTNAME=$HOSTNAME " >> $HOME /.bashrc
62- source $HOME /.bashrc
45+ source /tmp/create-configure-kernel.sh $GEOWAVE_VER
46+
47+ source /etc/profile.d/conda.sh
6348
64- pip install --upgrade pip
65- # Pandas added to install again because conda-forge misses correct pytz dependency version
66- pip install pixiedust ipywidgets ipyleaflet geomet pandas shapely folium owslib
49+ conda install jupyter
6750
6851jupyter nbextension enable --py --sys-prefix ipyleaflet
6952jupyter nbextension enable --py --sys-prefix widgetsnbextension
@@ -81,8 +64,29 @@ printf "\nc.NotebookApp.ip = '*'" >> $HOME/.jupyter/jupyter_notebook_config.py
8164printf " \nc.NotebookApp.notebook_dir = '$HOME /notebooks/'" >> $HOME /.jupyter/jupyter_notebook_config.py
8265printf " \nc.NotebookApp.port = 9000" >> $HOME /.jupyter/jupyter_notebook_config.py
8366
84- # Install Jupyter Kernel components on master node
85- if is_master ; then
86- install_kernel
87- fi
67+ # Adding Jupyter to Upstart so it can be run at bootstrap
68+ cd $HOME
69+ sudo cat << EOF > $HOME /jupyter.conf
70+ description "Jupyter"
71+
72+ start on runlevel [2345]
73+ stop on runlevel [016]
74+
75+ respawn
76+ respawn limit 0 10
77+
78+ env HOME=$HOME
79+ script
80+ . $HOME /.bashrc
81+ exec start-stop-daemon --start -c hadoop --exec $HOME /conda/bin/jupyter-notebook
82+ end script
83+ EOF
84+ sudo mv $HOME /jupyter.conf /etc/init/
85+ sudo chown root:root /etc/init/jupyter.conf
86+
87+ # be sure that jupyter daemon is registered in initctl
88+ sudo initctl reload-configuration
89+
90+ # start jupyter daemon
91+ sudo initctl start jupyter
8892
0 commit comments