'How to run Jupyter Lab on every startup on amazon ec2 instance?

I have already tried user-data method and rc.local methods but none are working. I am not a pro so would like some help on this.

These are the 3 commands i want to run on every startup of ec2 instance:

  1. tmux (start a tmux session so i dont loose the data when connection resets)
  2. source pyenv/bin/activate (Activate the venv)
  3. jupyter-lab --ip 0.0.0.0 --no-browser --allow-root (run the jupyter lab)

I'm using a ubuntu ec2 instance btw. Thanks in advance.

If i can acheieve this using nohup instead of tmux i'd be willing to that as well.

I wasn't able to find a solution anywhere so any help is appreciated, thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source