stainlessai / micronaut-jupyter

A Micronaut configuration that integrates your app with an existing Jupyter installation.
https://stainlessai.github.io/micronaut-jupyter
Apache License 2.0
9 stars 5 forks source link

MJ-6 ⁃ "Install" kernel at startup #16

Closed stainlessbot closed 4 years ago

stainlessbot commented 4 years ago

At some point, the kernel.json file for the Micronaut kernel will have to be placed in one of the Jupyter kernels directories. The best time to do this would probably be during the application's startup. (Jupyter kernels can be updated without having to restart the Jupyter process, just a client refresh.) The best way to detect when the application starts up is to probably provide a bean that executes logic using life cycle methods. This is a bit awkward, since the bean would not otherwise be used, or ever called from the application.

┆Issue Type: Story ┆Priority: High ┆Status: Resolved ┆Fix Versions: v0.1.0 ┆Issue Number: MJ-6 ┆Epic: Kernel

stainlessbot commented 4 years ago

➤ Joshua Carter commented:

Unfortunately, installing the kernel requires root privileges. I've decided the best way around this is to install the kernel to a non-Jupyter location and instruct the user of the configuration to configure Jupyter to add that location to it's path (i.e. setting the JUPYTER_PATH environment variable). Alternatively the user would be able to configure a Jupyter path as the location to install to and grant the app permissions to that path.

stainlessbot commented 4 years ago

➤ Joshua Carter commented:

(-) Existing kernel is appended to instead of updated.

stainlessbot commented 4 years ago

➤ Joshua Carter commented:

(-) Multiple issues with curl command

stainlessbot commented 4 years ago

➤ Joshua Carter commented:

(-) The original concept of just telling Jupyter to call an endpoint will not work. Jupyter is expecting to run the kernel as a process, so it isn't as simple as just executing a command. If the process exits, then it is assumed that the kernel has exited, and so Jupyter will try to start the process again (possibly with the same connection file). Jupyter restarts a kernel by killing the existing process and starting a new one.

My current plan is to create a bash script that Jupyter can run as the kernel process. Without making any other changes to the configuration, the bash script can simply just call the start endpoint and then sleep. However, as a future feature, the bash script should be able to exit if the kernel exits, and the kernel should be able to detect if the bash script was killed, this can probably be facilitated through some sort of status/heartbeat kernel endpoint (maybe making use of the same Micronaut @Endpoint).

stainlessbot commented 4 years ago

➤ Joshua Carter commented:

!/bin/bash

curl -X POST http://localhost:8080/jupyterkernel -H 'Content-Type: application/json' -d "{\"file\":\"$1\"}" --trace - RET=$? if [ $RET -ne 0 ]; then exit $RET fi

while true; do sleep 5 done{ "language": "groovy", "argv": [ "/usr/local/share/jupyter/kernels/micronaut/kernel.sh", "{connection_file}" ], "display_name": "Micronaut" }