How to run iPython Notebook as a service
In the end I created the following .plist file. It is autoloaded on startup and it will start a jupiter
notebook and keep it alive.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>cern.chernals.ipython</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/jupyter-notebook</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/chernals/Library/LaunchAgents/jupyter-notebook.stderr</string>
<key>StandardOutPath</key>
<string>/Users/chernals/Library/LaunchAgents/jupyter-notebook.stdout</string>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
I'm a macOS newbie, and found the accepted answer very helpful. I modified it to not launch a browser at startup and also start in the directory ~/jupyter where I store most of my notebooks.
For future reference, the way to make this start is to put the xml data in a file in the directory ~/Library/LaunchAgents, e.g. ~/Library/LaunchAgents/org.jupyter.notebook.plist.
The plist I ended up with was the following.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>org.jupyter.notebook</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/jupyter-notebook</string>
<string>--no-browser</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/rickard/Library/LaunchAgents/org.jupyter.notebook.stderr</string>
<key>StandardOutPath</key>
<string>/Users/rickard/Library/LaunchAgents/org.jupyter.notebook.stdout</string>
<key>KeepAlive</key>
<true/>
<key>WorkingDirectory</key>
<string>/Users/rickard/jupyter</string>
</dict>
</plist>
I haven't figured out a way to not have to hard code the user's home directory in there -- the EnableGlobbing option only works in ProgramArgument, and there is no environment variable expansion, so for now it needs to be in there.