2024-05-29 15:36:56 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
trap 'echo "An error occurred. Please contact the manager." >&2' ERR
|
|
|
|
|
|
|
|
echo "================== dnew ==================="
|
|
|
|
echo "=== contact: xd21@mails.tsinghua.edu.cn ==="
|
|
|
|
|
|
|
|
test_not_empty()
|
|
|
|
{
|
|
|
|
if [[ -z "$1" ]]; then
|
|
|
|
echo $2 >&2
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
ask_for_yN()
|
|
|
|
{
|
|
|
|
if [[ "$DFS_QUIET" == "1" ]]; then
|
|
|
|
echo 0
|
|
|
|
else
|
|
|
|
read -p "$1 [yN]: " yn
|
|
|
|
case $yn in
|
|
|
|
[Yy]* ) echo 1;;
|
|
|
|
* ) echo 0;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
container_name=$(whoami)_$(date +%y%m%d-%H%M%S)
|
|
|
|
|
2024-06-16 12:48:35 +08:00
|
|
|
base_command="sudo docker run -d --net=host \\
|
2024-06-26 13:38:29 +08:00
|
|
|
-v /home2:/home2 -v /gshare:/gshare \\
|
2024-11-15 10:19:43 +08:00
|
|
|
--privileged \\
|
2024-05-29 15:36:56 +08:00
|
|
|
--security-opt seccomp=unconfined --ulimit memlock=-1:-1 \\
|
|
|
|
--restart=unless-stopped \\
|
|
|
|
--name $container_name"
|
|
|
|
|
|
|
|
|
|
|
|
if [[ "$EUID" == "0" ]]; then
|
|
|
|
echo "Please run as your own user (i.e., DO NOT sudo)."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
ret=$(ask_for_yN "Use GPU?")
|
|
|
|
if [[ "$ret" == "1" ]]; then
|
|
|
|
base_command="$base_command \\
|
2024-06-12 11:03:28 +08:00
|
|
|
--device nvidia.com/gpu=all"
|
2024-05-29 15:36:56 +08:00
|
|
|
fi
|
|
|
|
ret=$(ask_for_yN "Use RDMA?")
|
|
|
|
if [[ "$ret" == "1" ]]; then
|
|
|
|
base_command="$base_command \\
|
|
|
|
--device=/dev/infiniband/uverbs0"
|
|
|
|
fi
|
|
|
|
|
2024-06-12 11:03:28 +08:00
|
|
|
image_name="git.nasp.fit/nasp/nasp-ubuntu"
|
2024-05-29 15:36:56 +08:00
|
|
|
base_command="$base_command \\
|
|
|
|
-it $image_name"
|
|
|
|
|
2024-06-12 11:03:28 +08:00
|
|
|
cmd="/etc/startup.sh"
|
2024-05-29 15:36:56 +08:00
|
|
|
base_command="$base_command $cmd"
|
|
|
|
|
|
|
|
echo "Will run:"
|
|
|
|
echo "====="
|
|
|
|
echo "$base_command"
|
|
|
|
echo "====="
|
|
|
|
ret=$(ask_for_yN "Start the container?")
|
|
|
|
|
|
|
|
if [[ "$ret" == "1" ]]; then
|
|
|
|
eval "$base_command"
|
|
|
|
echo "Container $container_name started. You can use the following command to get in:"
|
|
|
|
echo "sudo docker exec -it $container_name bash"
|
2024-05-30 15:13:19 +08:00
|
|
|
if [[ "$image_name" == "git.nasp.fit/nasp/nasp-ubuntu" ]]; then
|
2024-06-19 16:52:09 +08:00
|
|
|
sleep 1s
|
2024-05-30 15:13:19 +08:00
|
|
|
sudo docker exec -it $container_name code.sh
|
|
|
|
fi
|
2024-05-29 15:36:56 +08:00
|
|
|
else
|
|
|
|
echo "Aborted."
|
|
|
|
fi
|