1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/grafana_ynh.git synced 2024-09-03 20:36:29 +02:00
# Conflicts:
#	scripts/upgrade
This commit is contained in:
Jimmy Monin 2017-08-03 07:42:46 +02:00
commit 0efe448bdc
7 changed files with 50 additions and 8 deletions

View file

@ -5,6 +5,7 @@
path="/path" (PATH)
admin="john" (USER)
is_public=1 (PUBLIC|public=1|private=0)
port="3000" (PORT)
; Checks
pkg_linter=1
setup_sub_dir=1
@ -19,9 +20,9 @@
wrong_path=1
incorrect_path=1
corrupt_source=0
fail_download_source=0
port_already_use=0
final_path_already_use=0
fail_download_source=0
port_already_use=1
final_path_already_use=0
;;; Levels
Level 1=auto
Level 2=auto

View file

@ -3,7 +3,7 @@ location / {
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-WEBAUTH-USER $remote_user;
proxy_pass http://127.0.0.1:3000;
proxy_pass http://127.0.0.1:YNH_WWW_PORT;
proxy_http_version 1.1;
proxy_pass_request_headers on;
proxy_set_header Connection "keep-alive";

View file

@ -14,7 +14,7 @@ location ~ YNH_WWW_PATH/(?<ndpath>.*) {
proxy_pass_request_headers on;
proxy_set_header Connection "keep-alive";
proxy_store off;
proxy_pass http://127.0.0.1:3000/$ndpath$is_args$args;
proxy_pass http://127.0.0.1:YNH_WWW_PORT/$ndpath$is_args$args;
gzip on;
gzip_proxied any;

View file

@ -43,6 +43,15 @@
"example": "/grafana",
"default": "/grafana"
},
{
"name": "port",
"ask": {
"en": "Choose a port for your server. Let as default if you don't want to change it",
"fr": "Entrez un port pour votre serveur. Laissez par défaut si vous ne voulez pas en changer"
},
"example": "3000",
"default": "3000"
},
{
"name": "admin",
"type": "user",

View file

@ -103,3 +103,19 @@ ynh_remove_app_dependencies () {
dep_app=${app//_/-} # Replace all '_' by '-'
ynh_package_autoremove ${dep_app}-ynh-deps # Remove the fake package and its dependencies if they not still used.
}
# Find a free port and return it
#
# example: port=$(ynh_find_port 8080)
#
# usage: ynh_find_port begin_port
# | arg: begin_port - port to start to search
ynh_find_port () {
port=$1
test -n "$port" || ynh_die "The argument of ynh_find_port must be a valid port."
while netcat -z 127.0.0.1 $port # Check if the port is free
do
port=$((port+1)) # Else, pass to next port
done
echo $port
}

View file

@ -13,6 +13,7 @@ source ./_common.sh
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
port=$(ynh_find_port $YNH_APP_ARG_PORT)
admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
@ -29,6 +30,7 @@ sudo yunohost app checkurl "${domain}${path}" -a "$app" \
# Save app settings
ynh_app_setting_set "$app" admin "$admin"
ynh_app_setting_set "$app" is_public "$is_public"
ynh_app_setting_set "$app" port "$port"
# Install dependencies
install_dependencies
@ -83,6 +85,8 @@ sudo systemctl start influxdb
sudo cp ../conf/ldap.toml /etc/grafana
grafana_conf="/etc/grafana/grafana.ini"
# Set final port
sudo sed -i "/^\[server\]$/,/^\[/ s@;http_port = .*@http_port = $port@" $grafana_conf
# Set final URL
sudo sed -i "/^\[server\]$/,/^\[/ s@;root_url = .*@root_url = https://$domain$path@" $grafana_conf
# Disable check for updates
@ -142,6 +146,7 @@ else
fi
sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf
sed -i "s@YNH_WWW_PORT@$port@g" $nginx_conf
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
# If app is public, add url to SSOWat conf as skipped_uris

View file

@ -18,6 +18,13 @@ source /usr/share/yunohost/helpers
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
is_public=$(ynh_app_setting_get "$app" is_public)
port=$(ynh_app_setting_get "$app" port)
# test port settings
if [[ -z "$port" ]]; then
port=3000
ynh_app_setting_set $app port $port
fi
# Fix path if needed
path=$(fix_path $path)
@ -25,6 +32,9 @@ path=$(fix_path $path)
# There's currently nothing else to upgrade than packaging files
# as InfluxDB/Grafana updates are managed through APT
# Restart service
sudo systemctl restart grafana-server
# Declare services for YunoHost monitoring
sudo yunohost service add influxdb
sudo yunohost service add grafana-server --log "/var/log/grafana/grafana.log"
@ -37,6 +47,7 @@ else
fi
sed -i "s@YNH_WWW_PATH@${path}@g" $nginx_conf
sed -i "s@YNH_WWW_PORT@$port@g" $nginx_conf
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
# If app is public, add url to SSOWat conf as skipped_uris