I'd like my machine to kick off a Jupyter notebook server on boot. Python being what it is, this has to happen inside a virtual environment, and Jupyter being what it is none of this should be run as root. So I want to do the simplest thing and have it activate a virtual environment and then run the server instance as me. I can't for the life of me get it to actually start the service when I reboot.
When I try it this way:
...it won't start, even when I start it manually, giving the error "Running as root is not recommended. Use --allow-root to bypass." which indicates that me setting the jupyter_user variable to "glen" isn't working as I expect. But when I replace the line that starts the service with
the service starts fine when I do it manually; however, it doesn't start on boot, and in /var/log/messages I get a "Bad su to glen".
When I try it this way:
#!/bin/sh
# PROVIDE: jupyter
. /etc/rc.subr
name="jupyter"
rcvar="${name}_enable"
jupyter_user="glen"
start_cmd="${name}_start"
stop_cmd="${name}_stop"
jupyter_start() {
# Activate the virtual environment and start Jupyter
. /home/glen/jupyter-venv/bin/activate && jupyter-lab --no-browser --port=8888 --ip=0.0.0.0
}
jupyter_stop() {
# Find and kill the Jupyter process
pkill -f "jupyter-lab"
}
load_rc_config $name
run_rc_command "$@"
...it won't start, even when I start it manually, giving the error "Running as root is not recommended. Use --allow-root to bypass." which indicates that me setting the jupyter_user variable to "glen" isn't working as I expect. But when I replace the line that starts the service with
su -l glen -c ". /home/glen/jupyter-venv/bin/activate && jupyter-lab --no-browser --port=8888 --ip=0.0.0.0"
the service starts fine when I do it manually; however, it doesn't start on boot, and in /var/log/messages I get a "Bad su to glen".