Skip to content

Commit dd4c2c6

Browse files
Improved logging and errors handling for sm-ssh-ide
1 parent 0e0a2ca commit dd4c2c6

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

SageMaker_SSH_IDE.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"cell_type": "markdown",
6464
"metadata": {},
6565
"source": [
66-
"The next command will install the software for remote access, including SSH daemon and VNC server and XFCE4 desktop. If you don't want to run a VNC server or Jupyter notebook, pass the flag `--ssh-only` (comment the first line and uncomment the second). Also consider adding the same `--ssh-only` flag to the `sm-local-ssh-ide` command."
66+
"The next command will install the software for remote access, including SSH daemon and VNC server and XFCE4 desktop. If you don't want to run a VNC server or Jupyter notebook, pass the flag `--ssh-only` (comment the first line and uncomment the second). Also consider adding the same flag to the `sm-local-ssh-ide` command."
6767
]
6868
},
6969
{

sagemaker_ssh_helper/sm-ssh-ide

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ if [[ "$1" == "get-metadata" ]]; then
1818
echo "Domain: $(_print_sm_domain_id)"
1919
echo ""
2020
echo "Connect from local machine: sm-local-ssh-ide connect $(_print_sm_app_name)"
21+
echo "Connect from local machine (SSH only): sm-local-ssh-ide connect $(_print_sm_app_name) --ssh-only"
2122

2223
elif [[ "$1" == "configure" ]]; then
2324
OPTIONS=$2
25+
echo "$OPTIONS" > ~/.sm-ssh-ide-options
2426

2527
_install_helper_scripts
2628

@@ -64,8 +66,6 @@ EOF
6466
fi
6567

6668
else
67-
echo "$OPTIONS" > ~/.sm-ssh-ide-options
68-
6969
echo "sm-ssh-ide: Skipping VNC and GUI apps install"
7070
fi
7171

@@ -155,7 +155,7 @@ elif [[ "$1" == "init-ssm" ]]; then
155155
sm-init-ssm | tee /proc/1/fd/1
156156

157157
elif [[ "$1" == "start" ]]; then
158-
OPTIONS=$(cat ~/.sm-ssh-ide-options)
158+
OPTIONS=$(cat ~/.sm-ssh-ide-options || echo "")
159159

160160
set -e
161161

@@ -165,10 +165,13 @@ elif [[ "$1" == "start" ]]; then
165165

166166
touch /tmp/.ssh-ide-local-lock
167167

168+
echo "sm-ssh-ide: Starting SSH service"
168169
service ssh start
169170

170171
if [[ "$OPTIONS" != "--ssh-only" ]]; then
171172

173+
echo "sm-ssh-ide: Starting VNC server"
174+
172175
export USER=root
173176
vncserver :1
174177

@@ -177,24 +180,31 @@ elif [[ "$1" == "start" ]]; then
177180

178181
echo "sm-ssh-ide: Using SageMaker Studio Python: $SM_STUDIO_PYTHON"
179182

183+
echo "sm-ssh-ide: Installing Jupyter notebook"
184+
180185
"$SM_STUDIO_PYTHON_PREFIX"/bin/pip install -q notebook
181186

182187
# TODO: remove the below temp fix for "cannot import name 'Callable' from 'traitlets" when starting notebook
183188
"$SM_STUDIO_PYTHON_PREFIX"/bin/pip install --force-reinstall traitlets
184189

190+
echo "sm-ssh-ide: Starting Jupyter notebook server"
191+
185192
"$SM_STUDIO_PYTHON" -m jupyter notebook --no-browser --port=8889 --ip=127.0.0.1 --allow-root \
186193
>/tmp/jupyter-notebook.log 2>&1 &
187194

188195
sleep 2
189196

190-
tail /tmp/jupyter-notebook.log
197+
"$SM_STUDIO_PYTHON" -m jupyter notebook list
191198

192199
else
193200
echo "sm-ssh-ide: Skipping VNC and Jupyter start"
194201
fi
195202

203+
echo "sm-ssh-ide: Started all services"
204+
196205
elif [[ "$1" == "ssm-agent" ]]; then
197206

207+
echo "sm-ssh-ide: Starting SSM agent"
198208
/usr/bin/amazon-ssm-agent
199209

200210
elif [[ "$1" == "status" ]]; then
@@ -227,26 +237,31 @@ elif [[ "$1" == "env-diagnostics" ]]; then
227237
find "$JUPYTER_PATH" -name 'kernel.json' -print0 | xargs -0 cat
228238

229239
elif [[ "$1" == "stop" ]]; then
230-
OPTIONS=$(cat ~/.sm-ssh-ide-options)
240+
OPTIONS=$(cat ~/.sm-ssh-ide-options || echo "")
231241

242+
echo "sm-ssh-ide: Stopping SSM agent"
232243
pkill -ef amazon-ssm-agent || echo "sm-ssh-ide: SSM agent already stopped?"
233244

245+
echo "sm-ssh-ide: Stopping SSH service"
234246
service ssh stop
235247

236248
if [[ "$OPTIONS" != "--ssh-only" ]]; then
237249

238-
vncserver -kill :1
250+
echo "sm-ssh-ide: Stopping VNC server"
251+
vncserver -kill :1 || echo "sm-ssh-ide: VNC server already stopped?"
239252

240253
# Wait dbus to shop
241254
sleep 5
242255

243-
pkill -e Xtigervnc
244-
pkill -e Xtightvnc
256+
pkill -e Xtigervnc || :
257+
pkill -e Xtightvnc || :
245258

246-
pkill -e ssh-agent
247-
pkill -e gpg-agent
259+
echo "sm-ssh-ide: Stopping SSH and GPG agents"
260+
pkill -e ssh-agent || :
261+
pkill -e gpg-agent || :
248262

249-
pkill -fe jupyter-notebook
263+
echo "sm-ssh-ide: Stopping Jupyter notebook server"
264+
pkill -fe jupyter-notebook || echo "sm-ssh-ide: Jupyter notebook already stopped?"
250265

251266
else
252267
echo "sm-ssh-ide: Skipping VNC and Jupyter stop"
@@ -261,6 +276,8 @@ elif [[ "$1" == "stop" ]]; then
261276
echo "sm-ssh-ide: Local lock is missing, was not not running on this instance?"
262277
fi
263278

279+
echo "sm-ssh-ide: Stopped all services"
280+
264281
else
265282

266283
echo "sm-ssh-ide: Unknown command: $1"

0 commit comments

Comments
 (0)