您当前的位置:首页 > 计算机 > 软件应用 > 其它软件

保持Doprax 容器执行

时间:03-06来源:作者:点击数:

背景

Doprax 提供在国外的免费容器,可以用来运行自己的程序。但使用过程中,不知道什么情况下会终止执行,此事,我们需要一个检查器,如果发现停止执行了,就启动起来。

假设

目前假设Cookie可以长久使用,以后如果不行,在进行改进。

使用方法

1. 把Cookie放到cookie.txt 文件中

2. 在自己的服务器中,或宝塔面板中,定时执行 alive.sh, 我自己放到了 潘多拉的路由器里面。

核心代码如下: alive.sh

#!/bin/bash

cookie=$(cat ./cookie.txt)
# username=''
projekt_code=''
apiNode=''
# queryUsername(){    
#  locationStr=$(curl 'https://www.doprax.com/u/me/' \
#   -H 'authority: www.doprax.com' \
#   -H 'accept: application/json, text/plain, */*' \
#   -H 'accept-language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7' \
#   -H 'cache-control: no-cache' \
#   -H "cookie: $cookie" \
#   -H 'pragma: no-cache' \
#   -H 'referer: https://www.doprax.com/u/me/' \
#   -H 'sec-ch-ua: "Chromium";v="104", " Not A;Brand";v="99", "Microsoft Edge";v="104"' \
#   -H 'sec-ch-ua-mobile: ?0' \
#   -H 'sec-ch-ua-platform: "Windows"' \
#   -H 'sec-fetch-dest: empty' \
#   -H 'sec-fetch-mode: cors' \
#   -H 'sec-fetch-site: same-origin' \
#   -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.81 Safari/537.36 Edg/104.0.1293.47' \
#   -vvv 2>&1 | grep -E "Location: /u/")
#   locationStr=${locationStr#*/u/}
#   locationStr=${locationStr:0:-2}
#   username=$locationStr
#   echo "your name is $username"
# }

queryAppInfo(){
   appInfo=$(curl 'https://www.doprax.com/api/v1/projects/' \
  -H 'authority: www.doprax.com' \
  -H 'accept: application/json, text/plain, */*' \
  -H 'accept-language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7' \
  -H 'cache-control: no-cache' \
  -H "cookie: $cookie" \
  -H 'pragma: no-cache' \
  -H 'referer: https://www.doprax.com/' \
  -H 'sec-ch-ua: "Chromium";v="104", " Not A;Brand";v="99", "Microsoft Edge";v="104"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Windows"' \
  -H 'sec-fetch-dest: empty' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-site: same-origin' \
  -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.81 Safari/537.36 Edg/104.0.1293.47')

   apiNode=$(echo $appInfo | jq -r '.[0].node')
   echo "apiNode is $apiNode"

   projekt_code=$(echo $appInfo | jq -r '.[0].projekt_code')
   echo "projekt_code is $projekt_code"
}

queryStatus(){
 appstatusJson=$(curl "$apiNode/api/v1/projects/$projekt_code/resources/?environment=sandbox" \
  -H 'authority: eu-dyqrfuajkib.doprax.com' \
  -H 'accept: application/json, text/plain, */*' \
  -H 'accept-language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7' \
  -H 'cache-control: no-cache' \
  -H "cookie: $cookie" \
  -H 'pragma: no-cache' \
  -H 'referer: https://eu-dyqrfuajkib.doprax.com/' \
  -H 'sec-ch-ua: "Chromium";v="104", " Not A;Brand";v="99", "Microsoft Edge";v="104"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Windows"' \
  -H 'sec-fetch-dest: empty' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-site: same-origin' \
  -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.81 Safari/537.36 Edg/104.0.1293.47')

   appStatus=$(echo ${appstatusJson} | jq -r '.[0].status')
   echo  $appStatus
}

startApp(){
    curl "$apiNode/api/v1/projects/$projekt_code/dev/" \
    -H 'authority: eu-dyqrfuajkib.doprax.com' \
    -H 'accept: application/json, text/plain, */*' \
    -H 'accept-language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7' \
    -H 'cache-control: no-cache' \
    -H 'content-type: application/x-www-form-urlencoded' \
    -H "cookie: $cookie" \
    -H 'origin: https://eu-dyqrfuajkib.doprax.com' \
    -H 'pragma: no-cache' \
    -H 'referer: https://eu-dyqrfuajkib.doprax.com//' \
    -H 'sec-ch-ua: "Chromium";v="104", " Not A;Brand";v="99", "Microsoft Edge";v="104"' \
    -H 'sec-ch-ua-mobile: ?0' \
    -H 'sec-ch-ua-platform: "Windows"' \
    -H 'sec-fetch-dest: empty' \
    -H 'sec-fetch-mode: cors' \
    -H 'sec-fetch-site: same-origin' \
    -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.81 Safari/537.36 Edg/104.0.1293.47' \
    -d '{"operation":"run_all"}' \
    --compressed
}

queryAppInfo
queryStatus
appstatus=$(queryStatus)

if [ "$appstatus" == "not running" ]; then 
    startApp
else
    echo "running $appstatus"
fi

执行效果如下:

[RT-AC54U /media/upan/doprax]# ./alive.sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   345  100   345    0     0    327      0  0:00:01  0:00:01 --:--:--   417
apiNode is https://eu-dyqrfuajkib.doprax.com
projekt_code is 27f12d80-956e-11ed-8e66-b42e99837a9f
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   219  100   219    0     0    194      0  0:00:01  0:00:01 --:--:--   251
running
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   219  100   219    0     0    238      0 --:--:-- --:--:-- --:--:--   241
running running
[RT-AC54U /media/upan/doprax]# ./alive.sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   345  100   345    0     0    402      0 --:--:-- --:--:-- --:--:--   406
apiNode is https://eu-dyqrfuajkib.doprax.com
projekt_code is 27f12d80-956e-11ed-8e66-b42e99837a9f
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   223  100   223    0     0    241      0 --:--:-- --:--:-- --:--:--   243
not running
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   223  100   223    0     0    253      0 --:--:-- --:--:-- --:--:--   256{"success": true, "msg": "App starting"}[RT-AC54U /media/upan/doprax]#
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门