Start Jupyter or Jupyter-lab on startup of ec-2 instance.


Start Jupyter or Jupyter-lab on startup of ec-2 instance.

Edit the crontab by running

sudo crontab -e


and add the following

@reboot su ec2-user -c "/home/ec2-user/.start_jupyter.sh"


Create a file 

vi /home/ec2-user/.start_jupyter.sh

and add the following

cd /home/ec2-user

source /home/ec2-user/.bashrc

source /opt/intel/openvino/bin/setupvars.sh

/home/ec2-user/.local/bin/jupyter notebook --no-browser --NotebookApp.allow_password_change=False --NotebookApp.token="$INSTANCE_ID" --ip 0.0.0.0 --port 8888 > /tmp/jupyter.out 2>&1 &


We can leave this option to true, but changing password is not working...
--NotebookApp.allow_password_change=False because change password is not working. It is a bug in Jupyter. See https://github.com/jupyter/notebook/issues/3842

Give executable file permissions.

chmod 755 .start_jupyter.sh 

Debugging

sudo cat /var/log/cron

Also,

cat /tmp/jupyter.out 


If you want to set password randomly on EC2-Instance:

TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`

INSTANCE_ID=`curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id`


cd /home/ec2-user

source /home/ec2-user/.bashrc

source /opt/intel/openvino/bin/setupvars.sh

/home/ec2-user/.local/bin/jupyter notebook --no-browser --NotebookApp.allow_password_change=False --NotebookApp.token="$INSTANCE_ID" --ip 0.0.0.0 --port 8888 > /tmp/jupyter.out 2>&1 &


See:

No comments:

Post a Comment

Python contextlib for Timing Python code

If you've ever found yourself needing to measure the execution time of specific portions of your Python code, the `contextlib` module o...