Skip to content

Commit 82a9992

Browse files
committed
use systemd
1 parent fff3df6 commit 82a9992

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

template/code-interpreter.service

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Unit]
2+
Description=Code Interpreter Server
3+
After=jupyter.service
4+
Requires=jupyter.service
5+
6+
[Service]
7+
Type=simple
8+
WorkingDirectory=/root/.server
9+
ExecStartPre=/bin/bash -c 'until curl -sf http://localhost:8888/api/status > /dev/null 2>&1; do sleep 0.1; done'
10+
ExecStart=/root/.server/.venv/bin/uvicorn main:app --host 0.0.0.0 --port 49999 --workers 1 --no-access-log --no-use-colors --timeout-keep-alive 640
11+
Restart=on-failure
12+
13+
[Install]
14+
WantedBy=multi-user.target

template/jupyter.service

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[Unit]
2+
Description=Jupyter Server
3+
4+
[Service]
5+
Type=simple
6+
Environment=MATPLOTLIBRC=/root/.config/matplotlib/.matplotlibrc
7+
ExecStart=/usr/local/bin/jupyter server --IdentityProvider.token=""
8+
Restart=on-failure
9+
StandardOutput=journal
10+
StandardError=journal
11+
12+
[Install]
13+
WantedBy=multi-user.target

template/start-up.sh

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
#!/bin/bash
22

3-
function start_jupyter_server() {
4-
counter=0
5-
response=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:8888/api/status")
6-
while [[ ${response} -ne 200 ]]; do
7-
let counter++
8-
if ((counter % 20 == 0)); then
9-
echo "Waiting for Jupyter Server to start..."
10-
sleep 0.1
11-
fi
12-
13-
response=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:8888/api/status")
14-
done
15-
16-
cd /root/.server/
17-
.venv/bin/uvicorn main:app --host 0.0.0.0 --port 49999 --workers 1 --no-access-log --no-use-colors --timeout-keep-alive 640
18-
}
19-
203
echo "Starting Code Interpreter server..."
21-
start_jupyter_server &
22-
MATPLOTLIBRC=/root/.config/matplotlib/.matplotlibrc jupyter server --IdentityProvider.token="" >/dev/null 2>&1
4+
systemctl daemon-reload
5+
systemctl start jupyter code-interpreter

template/template.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def make_template(
3838
"sudo",
3939
"fonts-noto-cjk",
4040
"ca-certificates",
41+
"systemd",
4142
]
4243
)
4344
.run_cmd("curl -fsSL https://deb.nodesource.com/setup_20.x | bash -")
@@ -126,6 +127,15 @@ def make_template(
126127
.make_dir(".ipython/profile_default/startup")
127128
.copy("ipython_kernel_config.py", ".ipython/profile_default/")
128129
.copy("startup_scripts", ".ipython/profile_default/startup")
130+
# Install systemd service units
131+
.copy("jupyter.service", ".jupyter/jupyter.service")
132+
.copy("code-interpreter.service", ".jupyter/code-interpreter.service")
133+
.run_cmd(
134+
[
135+
"cp /root/.jupyter/jupyter.service /etc/systemd/system/",
136+
"cp /root/.jupyter/code-interpreter.service /etc/systemd/system/",
137+
]
138+
)
129139
)
130140

131141
if is_docker:

0 commit comments

Comments
 (0)