사전 지식
사용법
./server_learning.sh company_0 feature/discrete-sac
알고리즘
- 서버 컴에 ssh로 접속 후,
- tmux(이름:
server
/ gpu_idx:1 이면 server_1
)가 있으면 거기 들어가고, 없으면 tmux 생성함.
- tmux 창은, window 1개(이름:
server_window
)임.
- tmux 창에서 아래 명령어 실행
- cd ~/PycharmProjects/nl_navigation
- conda activate nl_navigation
- git config --global credential.helper store (비번 한번만 쳐도 되도록)
- git stash
- git fetch
- export BRANCH_NAME=$BRANCH_NAME
- if git show-ref --verify --quiet refs/heads/$BRANCH_NAME; then echo Switching to $BRANCH_NAME && git checkout $BRANCH_NAME && git pull origin $BRANCH_NAME; else echo Creating and switching to $BRANCH_NAME from origin/$BRANCH_NAME && git checkout -b $BRANCH_NAME origin/$BRANCH_NAME; fi
- target_branch가 server local에 이미 있으면, checkout 후 full하고, 없었으면, 서버로부터 가져와서 로컬에 해당 브랜치를 생성한다.
- cd nl_navigation
- python3 launch_sac_training.py
TODO
- ssh로 접근해서 학습돌리면, 학습 진행이 안되는데, 왜 그런지 확인 필요.
- 브랜치명을 WORKSPACE 인자로 넣어주는 코드 작성해야함
- NAMESPACE(note_~~~)를 인자로 넣어주는 코드 작성해야함.
코드
#!/bin/bash
SESSION="server"
WINDOW_NAME="server_window"
TARGET_SERVER=$1
BRANCH_NAME=$2
echo "Target server: $TARGET_SERVER"
echo "Target branch: $BRANCH_NAME"
DESIRED_USER="hsb"
GPU_IDX=0
PORT=3100
if [ $TARGET_SERVER == "company_0" ]; then
DESIRED_IP="10.60.188.51"
elif [ $TARGET_SERVER == "company_1" ]; then
DESIRED_IP="10.60.188.51"
GPU_IDX=1
else
DESIRED_IP="None"
fi
BRANCH_CHECK_COMMAND="
BRANCH_NAME=$BRANCH_NAME
if git show-ref --verify --quiet refs/heads/\$BRANCH_NAME; then
echo 'Switching to \$BRANCH_NAME'
git checkout \$BRANCH_NAME
git pull origin \$BRANCH_NAME
else
echo 'Creating and switching to \$BRANCH_NAME from origin/\$BRANCH_NAME'
git checkout -b \$BRANCH_NAME origin/\$BRANCH_NAME
fi
"
TMUX_COMMAND="
if ! tmux has-session -t $SESSION 2>/dev/null; then
tmux new-session -d -s $SESSION -n $WINDOW_NAME
echo 'Creating new session'
else
echo 'Attaching to existing session'
tmux setw -g mouse on
tmux send-keys -t $SESSION 'cd ~/PycharmProjects/nl_navigation' C-m
tmux send-keys -t $SESSION 'conda activate nl_navigation' C-m
tmux send-keys -t $SESSION 'git config --global credential.helper store' C-m
tmux send-keys -t $SESSION 'git stash' C-m
tmux send-keys -t $SESSION 'git fetch' C-m
tmux send-keys -t $SESSION 'export BRANCH_NAME=$BRANCH_NAME' C-m
tmux send-keys -t $SESSION 'if git show-ref --verify --quiet refs/heads/\$BRANCH_NAME; then echo Switching to \$BRANCH_NAME && git checkout \$BRANCH_NAME && git pull origin \$BRANCH_NAME; else echo Creating and switching to \$BRANCH_NAME from origin/\$BRANCH_NAME && git checkout -b \$BRANCH_NAME origin/\$BRANCH_NAME; fi' C-m
tmux send-keys -t $SESSION 'cd nl_navigation' C-m
tmux send-keys -t $SESSION 'python3 launch_sac_training.py' C-m
tmux attach -t $SESSION
fi
"
ssh -X -t $DESIRED_USER@$DESIRED_IP -p $PORT "$TMUX_COMMAND"