improve dnew
This commit is contained in:
parent
072e00fcb9
commit
ed5b5f1e14
|
@ -1,21 +1,85 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
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)
|
||||||
|
|
||||||
|
base_command="sudo docker run -d --net=host -v /home2:/home2 \\
|
||||||
|
--cap-add=SYS_NICE --cap-add=IPC_LOCK \\
|
||||||
|
--security-opt seccomp=unconfined --ulimit memlock=-1:-1 \\
|
||||||
|
--restart=unless-stopped \\
|
||||||
|
--name $container_name"
|
||||||
|
|
||||||
|
|
||||||
if [[ "$EUID" == "0" ]]; then
|
if [[ "$EUID" == "0" ]]; then
|
||||||
echo "Please run as your own user (i.e., DO NOT sudo)."
|
echo "Please run as your own user (i.e., DO NOT sudo)."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
container_name=$(whoami)_$(date +%y%m%d-%H%M%S)
|
|
||||||
image_name=${1:-"git.nasp.ob.ac.cn/nasp/nasp-ubuntu"}
|
ret=$(ask_for_yN "Use GPU?")
|
||||||
cmd=${2:-"/etc/startup.sh"}
|
if [[ "$ret" == "1" ]]; then
|
||||||
echo "container name: $container_name"
|
base_command="$base_command \\
|
||||||
echo "image: $image_name"
|
--runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all"
|
||||||
sudo docker run -d --net=host -v /home2:/home2 \
|
fi
|
||||||
--cap-add=SYS_NICE --cap-add=IPC_LOCK \
|
ret=$(ask_for_yN "Use RDMA?")
|
||||||
--device=/dev/infiniband/rdma_cm --device=/dev/infiniband/issm0 \
|
if [[ "$ret" == "1" ]]; then
|
||||||
--device=/dev/infiniband/umad0 --device=/dev/infiniband/uverbs0 \
|
base_command="$base_command \\
|
||||||
--runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all \
|
--device=/dev/infiniband/rdma_cm --device=/dev/infiniband/issm0 \\
|
||||||
--security-opt \
|
--device=/dev/infiniband/umad0 --device=/dev/infiniband/uverbs0"
|
||||||
seccomp=unconfined --ulimit memlock=-1:-1 \
|
fi
|
||||||
--restart=always \
|
|
||||||
--name $container_name -it $image_name $cmd
|
read -p "Image name (default: git.nasp.ob.ac.cn/nasp/nasp-ubuntu): "
|
||||||
|
if [[ -z "$REPLY" ]]; then
|
||||||
|
image_name="git.nasp.ob.ac.cn/nasp/nasp-ubuntu"
|
||||||
|
else
|
||||||
|
image_name="$REPLY"
|
||||||
|
fi
|
||||||
|
base_command="$base_command \\
|
||||||
|
-it $image_name"
|
||||||
|
|
||||||
|
read -p "Start up command (default: /etc/startup.sh): "
|
||||||
|
if [[ -z "$REPLY" ]]; then
|
||||||
|
cmd="/etc/startup.sh"
|
||||||
|
else
|
||||||
|
cmd="$REPLY"
|
||||||
|
fi
|
||||||
|
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"
|
||||||
|
else
|
||||||
|
echo "Aborted."
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in New Issue
Block a user