-
Notifications
You must be signed in to change notification settings - Fork 2
/
load_launch_agent.sh
executable file
·70 lines (54 loc) · 1.65 KB
/
load_launch_agent.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
# Run Jupyter Notebook as a service on macOS
# Based on https://gist.github.com/nathanielobrown/1614c1011d8eb5aad291fda7c60c5563
COMMAND=${1:-notebook}
PORT=${2:-8888}
JUPYTER=$(which jupyter)
# shellcheck disable=SC2016
[[ -s "$JUPYTER" ]] || (echo 'The "jupyter" command is not in your $PATH'; exit 1)
LABEL=org.jupyter.$COMMAND
PLIST="$HOME/Library/LaunchAgents/$LABEL.plist"
LOG="$HOME/Library/Logs/$LABEL.log"
echo "Writing $PLIST to run $JUPYTER"
# TODO: Password? Might be better to set independently
# See https://jupyter-notebook.readthedocs.io/en/stable/public_server.html
cat > "$PLIST" <<EOF
<?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>Label</key>
<string>$LABEL</string>
<key>ProgramArguments</key>
<array>
<string>$JUPYTER</string>
<string>$COMMAND</string>
<string>--no-browser</string>
<string>--port</string>
<string>$PORT</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>WorkingDirectory</key>
<string>$HOME</string>
<key>StandardOutPath</key>
<string>$LOG</string>
<key>StandardErrorPath</key>
<string>$LOG</string>
</dict>
</plist>
EOF
if launchctl list | grep -q "$LABEL"; then
echo Unloading "$LABEL"
launchctl unload "$PLIST"
fi
echo Loading "$LABEL"
launchctl load "$PLIST"
echo Logging to "$LOG"
while ! [ -f "$LOG" ]; do
sleep 1
done
echo
tail -n 20 -f "$LOG"