CC-5708: proftpd hook for new File API
added handling for if the web server is down
This commit is contained in:
parent
eb72f25151
commit
2bc37b9fea
1 changed files with 37 additions and 22 deletions
|
@ -1,26 +1,41 @@
|
|||
#! /bin/bash
|
||||
|
||||
file_path=$1
|
||||
filename="${file_path##*/}"
|
||||
post_file() {
|
||||
#kill process after 30 minutes (360*5=30 minutes)
|
||||
max_retry=360
|
||||
retry_count=0
|
||||
|
||||
#base_instance_path and airtime_conf_path are common to all saas instances
|
||||
base_instance_path=/mnt/airtimepro/instances/
|
||||
airtime_conf_path=/etc/airtime/airtime.conf
|
||||
file_path=$1
|
||||
filename="${file_path##*/}"
|
||||
|
||||
#maps the instance_path to the url
|
||||
vhost_file=/mnt/airtimepro/system/vhost.map
|
||||
#base_instance_path and airtime_conf_path are common to all saas instances
|
||||
base_instance_path=/mnt/airtimepro/instances/
|
||||
airtime_conf_path=/etc/airtime/airtime.conf
|
||||
|
||||
#instance_path will look like 1/1384, for example
|
||||
instance_path=$(echo $file_path | grep -Po "(?<=($base_instance_path)).*?(?=/srv)")
|
||||
#maps the instance_path to the url
|
||||
vhost_file=/mnt/airtimepro/system/vhost.map
|
||||
|
||||
#post request url - http://bananas.airtime.pro/rest/media, for example
|
||||
url=http://
|
||||
url+=$(grep -E $instance_path $vhost_file | awk '{print $1;}')
|
||||
url+=/rest/media
|
||||
#instance_path will look like 1/1384, for example
|
||||
instance_path=$(echo $file_path | grep -Po "(?<=($base_instance_path)).*?(?=/srv)")
|
||||
|
||||
#path to specific instance's airtime.conf
|
||||
instance_conf_path=$base_instance_path$instance_path$airtime_conf_path
|
||||
#post request url - http://bananas.airtime.pro/rest/media, for example
|
||||
url=http://
|
||||
url+=$(grep -E $instance_path $vhost_file | awk '{print $1;}')
|
||||
url+=/rest/media
|
||||
|
||||
api_key=$(sudo awk -F "=" '/api_key/ {print $2}' $instance_conf_path)
|
||||
#path to specific instance's airtime.conf
|
||||
instance_conf_path=$base_instance_path$instance_path$airtime_conf_path
|
||||
|
||||
curl $url -u $api_key":" -X POST -F "file=@$file_path" -F "name=$filename"
|
||||
api_key=$(sudo awk -F "=" '/api_key/ {print $2}' $instance_conf_path)
|
||||
|
||||
until curl --max-time 30 $url -u $api_key":" -X POST -F "file=@$file_path" -F "name=$filename"
|
||||
do
|
||||
retry_count=$[$retry_count+1]
|
||||
if [ $retry_count -ge $max_retry ]; then
|
||||
break
|
||||
fi
|
||||
sleep 5
|
||||
done
|
||||
}
|
||||
|
||||
post_file "$1" &
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue