?
前面總結了aws webrtc sdk-c項目中多進程啟動master的shell腳本,具體參考:https://blog.csdn.net/zhang_jiamin/article/details/148616899
這次總結一下多進程啟動viewer的shell腳本,以及過程中遇到的問題和解決方法。
實現說明:
1、獲取 sid 和 uid(用于認證)
2、獲取 ak/sk/token(多個 SN 共用一組密鑰)
3、為每個 channel 啟動 5 個 viewer,啟動命令包含日志文件
4、使用 GNU parallel 控制并發(替代 wait + 手動計數)
5、所有錯誤集中到 error.log
首先,需要安裝parallel,請參考:https://blog.csdn.net/zhang_jiamin/article/details/148815820
主要模塊代碼實現:
#!/bin/bashset -euo pipefail# ==== 登錄獲取 sid uid ====
login_response=$(curl -ks "$LOGIN_URL" \-H "Content-Type: application/x-www-form-urlencoded" \-H "GG-Pid: xxxxxxx" \-H "GG-Sign: xxxxxxxxxxxxxx" \-H "GG-Imei: xxxxxxxxxxxxxxx" \--data-urlencode "countryAbbr=CN" \--data-urlencode "countryCode=86" \--data-urlencode "email=${EMAIL}" \--data-urlencode "password=${PASSWORD}" \--data-urlencode "region=${REGION}" \--data-urlencode "type=1"
)sid=$(echo "$login_response" | jq -r '.data.sid')
uid=$(echo "$login_response" | jq -r '.data.uid')# ==== 獲取 STS 密鑰 ====
sts_curl_args=(-k -s "$STS_URL"-H "Content-Type: application/x-www-form-urlencoded"-H "GG-Sid: $sid"-H "GG-Uid: $uid"-H "GG-Pid: xxxxxxx"-H "GG-Sign: xxxxxxxxx"-H "GG-Imei: xxxxxxxxxxxx"--data-urlencode "refresh=true"
)for sn in "${SNS[@]}"; dosts_curl_args+=( --data-urlencode "sn[]=$sn" )
donests_response=$(curl "${sts_curl_args[@]}")ak=$(echo "$sts_response" | jq -r '.data.ak')
sk=$(echo "$sts_response" | jq -r '.data.sk')
token=$(echo "$sts_response" | jq -r '.data.token')# ==== 構造任務列表 ====
TASK_FILE="${BASE_DIR}/viewer_tasks.txt"
: > "$TASK_FILE"for channel in "${CHANNELS[@]}"; dofor i in $(seq 1 "$VIEWERS_PER_CHANNEL"); doecho "$channel $i" >> "$TASK_FILE"done
done# ==== 啟動 viewer 的函數 ====