From eece458af25f072cdaa9cfa3636d9481cc570089 Mon Sep 17 00:00:00 2001 From: Selamanse Date: Wed, 19 Jul 2017 11:13:17 +0200 Subject: [PATCH] Improves installation and removal --- conf/nginx.conf | 11 ++++++----- conf/nginx.conf-nosub | 6 ------ manifest.json | 7 ++++--- scripts/install | 31 +++++++++++++++++++++++-------- scripts/remove | 9 +++++---- 5 files changed, 38 insertions(+), 26 deletions(-) delete mode 100644 conf/nginx.conf-nosub diff --git a/conf/nginx.conf b/conf/nginx.conf index 3770f2a..9bb6b40 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,6 +1,7 @@ -location /PATHTOCHANGE { - rewrite ^PATHTOCHANGE$ PATHTOCHANGE/ permanent; - proxy_pass http://localhost:3000/; - proxy_set_header Host $host; - proxy_buffering off; +location ^~ #LOCATION# { + alias #DESTDIR#/; + rewrite ^#PATH#$ #PATH#/ permanent; + proxy_pass http://localhost:3000/; + proxy_set_header Host $host; + proxy_buffering off; } diff --git a/conf/nginx.conf-nosub b/conf/nginx.conf-nosub deleted file mode 100644 index 09825b1..0000000 --- a/conf/nginx.conf-nosub +++ /dev/null @@ -1,6 +0,0 @@ -location / { - proxy_pass http://localhost:3000/; - proxy_set_header Host $host; - # be careful, this line doesn't override any proxy_buffering on set in a conf.d/file.conf - proxy_buffering off; -} diff --git a/manifest.json b/manifest.json index edfb236..a15b382 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,8 @@ "en": "the ultimate chat platform" }, "url": "https://github.com/selamanse/rocketchat_ynh", - "license": "free", + "license": "MIT", + "version": "0.57.2-rc.0", "maintainer": { "name": "selamanse", "email": "selamanse@scheinfrei.info", @@ -35,8 +36,8 @@ "ask": { "en": "Choose a path for RocketChat" }, - "example": "/chat", - "default": "/chat" + "example": "/rocketchat", + "default": "/rocketchat" }, { "name": "is_public", diff --git a/scripts/install b/scripts/install index 98cc3e7..ae78661 100644 --- a/scripts/install +++ b/scripts/install @@ -21,7 +21,7 @@ ynh_abort_if_errors #================================================= domain=$YNH_APP_ARG_DOMAIN -path_url=$YNH_APP_ARG_PATH +path=$YNH_APP_ARG_PATH is_public=$YNH_APP_ARG_IS_PUBLIC language=$YNH_APP_ARG_LANG @@ -30,6 +30,8 @@ app=$YNH_APP_INSTANCE_NAME ROCKETCHAT_VERSION=0.57.2 NODE_VERSION=4.7.1 +workdir=$(pwd) + # Check domain/path availability sudo yunohost app checkurl $domain -a rocketchat if [[ ! $? -eq 0 ]]; then @@ -50,17 +52,26 @@ sudo npm install -g n sudo n $NODE_VERSION # Create destination -final_path=/var/www/rocketchat +final_path="/var/www/$app" +[[ -d $final_path ]] && ynh_die \ +"The destination directory '$DESTDIR' already exists.\ + You should safely delete it before installing this app." + ynh_app_setting_set $app final_path $final_path sudo mkdir -p $final_path -sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf* +# Copy and set systemd configuration sed -i "s@CHANGEMETOROOTURL@$domain/@g" ../conf/Rocketchat.service - -sudo cp ../conf/nginx.conf-nosub /etc/nginx/conf.d/$domain.d/rocketchat.conf sudo cp ../conf/Rocketchat.service /etc/systemd/system/ -pkgdir=$(pwd) +# Copy and set nginx configuration +nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" +sed -i "s@#APP#@${app}@g" ../conf/nginx.conf +sed -i "s@#PATH#@${path}@g" ../conf/nginx.conf +sed -i "s@#LOCATION#@${path:-/}@g" ../conf/nginx.conf +sed -i "s@#DESTDIR#@${final_path}@g" ../conf/nginx.conf + +sudo cp ../conf/nginx.conf "$nginx_conf" # download and extract rocketchat sudo curl -L -o $final_path/rocket.chat-$ROCKETCHAT_VERSION.gtar "https://rocket.chat/releases/${ROCKETCHAT_VERSION}/download" @@ -86,9 +97,13 @@ fi sudo systemctl start Rocketchat.service sudo systemctl enable Rocketchat.service -sleep 25s +# wait for rocketchat to populate db and start (oneliner has to be improved) +isup=false; x=5; while [ $x -gt 0 ];do echo "Waiting approx. $x seconds..."; \ +x=$(( $x - 1 )); sleep 1; if $(curl -m 1 -s localhost:3000/api/v1/info | \ +grep -e "success.*true" >/dev/null 2>%1); then isup=true; break; fi; done && if $isup; \ +then echo "service is up"; else echo "service not reachable"; ynh_die; fi -cd $pkgdir +cd $workdir sudo mongo < ../conf/rocketchat_ldap.js diff --git a/scripts/remove b/scripts/remove index 87f91cf..663b9dd 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,10 +12,11 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) -sudo rm -rf /var/www/rocketchat - -sudo rm -f /etc/nginx/conf.d/$domain.d/rocketchat.conf -sudo rm -Rf /var/log/rocketchat/ sudo systemctl stop Rocketchat.service + +sudo rm -rf /var/www/rocketchat +sudo rm -f /etc/nginx/conf.d/$domain.d/rocketchat.conf +sudo rm -rf /var/log/rocketchat/ sudo rm -f /etc/systemd/system/Rocketchat.service + sudo systemctl restart nginx