From 5d2d50aa78bf55b3c7ba6e8a3f936b2d458cb823 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Thu, 14 Sep 2017 17:40:26 +0200 Subject: [PATCH 01/10] run source in subshell and move pip installation after defining settings --- scripts/install | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/scripts/install b/scripts/install index 967fec4..00d83b9 100755 --- a/scripts/install +++ b/scripts/install @@ -107,14 +107,6 @@ ynh_add_nginx_config # Create a system user ynh_system_user_create $app -#================================================= -# PIP INSTALLATION -#================================================= -virtualenv ${final_path}/venv -source ${final_path}/venv/bin/activate -${final_path}/venv/bin/pip install Weblate==2.16 -${final_path}/venv/bin/pip install pytz python-bidi PyYaML Babel pyuca pylibravatar pydns - #================================================= # SPECIFIC SETUP #================================================= @@ -160,6 +152,16 @@ ynh_replace_string "__ADMINMAIL__" "$admin_mail" $final_path/weblate/settings.py ynh_replace_string "__DOMAIN__" "$domain" $final_path/weblate/settings.py ynh_replace_string "__KEY__" "$key" $final_path/weblate/settings.py +#================================================= +# PIP INSTALLATION +#================================================= +virtualenv ${final_path}/venv +#run source in a 'sub shell' +( + source ${final_path}/venv/bin/activate + ${final_path}/venv/bin/pip install Weblate==2.16 + ${final_path}/venv/bin/pip install pytz python-bidi PyYaML Babel pyuca pylibravatar pydns +) #================================================= # SPECIFIC SETUP Filling up the database @@ -167,9 +169,12 @@ ynh_replace_string "__KEY__" "$key" $final_path/weblate/settings.py #========================================== echo "SPECIFIC SETUP Filling up the database" # set up database -source ${final_path}/venv/bin/activate && weblate migrate --noinput --settings weblate.settings -# generate static files -source ${final_path}/venv/bin/activate && weblate collectstatic --noinput --settings weblate.settings +( + source ${final_path}/venv/bin/activate + weblate migrate --noinput --settings weblate.settings + # generate static files + weblate collectstatic --noinput --settings weblate.settings +) #================================================= # SETUP CRON From 49bfb081a614e3e4f60d6c5bf4ec3c8833bca4e4 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Thu, 14 Sep 2017 17:45:02 +0200 Subject: [PATCH 02/10] add set +eu in subshell --- scripts/install | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/install b/scripts/install index 00d83b9..922f2ed 100755 --- a/scripts/install +++ b/scripts/install @@ -158,6 +158,7 @@ ynh_replace_string "__KEY__" "$key" $final_path/weblate/settings.py virtualenv ${final_path}/venv #run source in a 'sub shell' ( + set +eu source ${final_path}/venv/bin/activate ${final_path}/venv/bin/pip install Weblate==2.16 ${final_path}/venv/bin/pip install pytz python-bidi PyYaML Babel pyuca pylibravatar pydns @@ -170,6 +171,7 @@ virtualenv ${final_path}/venv echo "SPECIFIC SETUP Filling up the database" # set up database ( + set +eu source ${final_path}/venv/bin/activate weblate migrate --noinput --settings weblate.settings # generate static files From 110d0c94a433e4ad7b477ca8caee81ccbcfa0055 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Thu, 14 Sep 2017 17:46:20 +0200 Subject: [PATCH 03/10] Correct service removal --- scripts/remove | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/remove b/scripts/remove index c5e1000..4b3b4c4 100755 --- a/scripts/remove +++ b/scripts/remove @@ -26,7 +26,7 @@ db_name=$(ynh_app_setting_get $app db_name) if yunohost service status | grep -q $app then echo "Remove $app service" - yunohost service remove $app + yunohost service remove $app.uwsgi.service fi #================================================= From fc4fab842d5b2c71ed96eb7a1287a959fe6c9305 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Fri, 15 Sep 2017 10:44:45 +0200 Subject: [PATCH 04/10] add DJANGO_SETTINGS_MODULE --- conf/cron_weblate | 6 +++--- scripts/install | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/conf/cron_weblate b/conf/cron_weblate index b0627ab..0e43728 100644 --- a/conf/cron_weblate +++ b/conf/cron_weblate @@ -1,9 +1,9 @@ # https://docs.weblate.org/en/latest/admin/install.html#production-cron # Fulltext index updates -10 * * * * www-data cd "__FINALPATH__" && source __FINALPATH__/venv/bin/activate && weblate update_index --settings weblate.settings +10 * * * * www-data cd "__FINALPATH__" && source __FINALPATH__/venv/bin/activate && DJANGO_SETTINGS_MODULE="weblate.settings" weblate update_index # Cleanup stale objects -@daily cd "__FINALPATH__" && source __FINALPATH__/venv/bin/activate && weblate cleanuptrans --settings weblate.settings +@daily cd "__FINALPATH__" && source __FINALPATH__/venv/bin/activate && DJANGO_SETTINGS_MODULE="weblate.settings" weblate cleanuptrans # Commit pending changes after 96 hours -@hourly cd "__FINALPATH__" && source __FINALPATH__/venv/bin/activate && weblate commit_pending --all --age=96 --verbosity=0 --settings weblate.settings +@hourly cd "__FINALPATH__" && source __FINALPATH__/venv/bin/activate && DJANGO_SETTINGS_MODULE="weblate.settings" weblate commit_pending --all --age=96 --verbosity=0 diff --git a/scripts/install b/scripts/install index 922f2ed..c83918c 100755 --- a/scripts/install +++ b/scripts/install @@ -173,9 +173,10 @@ echo "SPECIFIC SETUP Filling up the database" ( set +eu source ${final_path}/venv/bin/activate - weblate migrate --noinput --settings weblate.settings + export DJANGO_SETTINGS_MODULE="weblate.settings" + weblate migrate --noinput # generate static files - weblate collectstatic --noinput --settings weblate.settings + weblate collectstatic --noinput ) #================================================= From 933076f8bea7d8ccb3f24a9e44f925179f50ce6c Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Fri, 15 Sep 2017 10:58:04 +0200 Subject: [PATCH 05/10] added pathurl in settings, and corrected DATA_DIR in nginx --- conf/nginx.conf | 8 ++++---- conf/settings.py | 3 +-- scripts/install | 1 + 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 1aa4bed..c3c4a1c 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -16,24 +16,24 @@ location __PATH__ { location __PATH__/favicon.ico { # DATA_DIR/static/favicon.ico - alias __FINALPATH__/static/favicon.ico; + alias __FINALPATH__/data/static/favicon.ico; expires 30d; } location __PATH__/robots.txt { # DATA_DIR/static/robots.txt - alias __FINALPATH__/static/robots.txt; + alias __FINALPATH__/data/static/robots.txt; expires 30d; } location __PATH__/static { # DATA_DIR/static/ - alias __FINALPATH__/static/; + alias __FINALPATH__/data/static/; expires 30d; } location __PATH__/media { # DATA_DIR/media/ - alias __FINALPATH__/media/; + alias __FINALPATH__/data/media/; expires 30d; } diff --git a/conf/settings.py b/conf/settings.py index 4640a9b..d53c5c4 100644 --- a/conf/settings.py +++ b/conf/settings.py @@ -56,7 +56,6 @@ DATABASES = { # If your server supports it, see Unicode issues above 'charset': 'utf8mb4', } - } } @@ -133,7 +132,7 @@ USE_L10N = True USE_TZ = True # URL prefix to use, please see documentation for more details -URL_PREFIX = '' +URL_PREFIX = '__PATHURL__/' # Absolute filesystem path to the directory that will hold user-uploaded files. # Example: "/home/media/media.lawrence.com/media/" diff --git a/scripts/install b/scripts/install index c83918c..c96fd4e 100755 --- a/scripts/install +++ b/scripts/install @@ -151,6 +151,7 @@ ynh_replace_string "__ADMIN__" "$admin" $final_path/weblate/settings.py ynh_replace_string "__ADMINMAIL__" "$admin_mail" $final_path/weblate/settings.py ynh_replace_string "__DOMAIN__" "$domain" $final_path/weblate/settings.py ynh_replace_string "__KEY__" "$key" $final_path/weblate/settings.py +ynh_replace_string "__PATHURL__" "$pathurl" $final_path/weblate/settings.py #================================================= # PIP INSTALLATION From 0d83cec63b43e7754a5a4be314efc92eb401015f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Fri, 15 Sep 2017 12:23:33 +0200 Subject: [PATCH 06/10] typo path_url --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index c96fd4e..f69adb5 100755 --- a/scripts/install +++ b/scripts/install @@ -151,7 +151,7 @@ ynh_replace_string "__ADMIN__" "$admin" $final_path/weblate/settings.py ynh_replace_string "__ADMINMAIL__" "$admin_mail" $final_path/weblate/settings.py ynh_replace_string "__DOMAIN__" "$domain" $final_path/weblate/settings.py ynh_replace_string "__KEY__" "$key" $final_path/weblate/settings.py -ynh_replace_string "__PATHURL__" "$pathurl" $final_path/weblate/settings.py +ynh_replace_string "__PATHURL__" "$path_url" $final_path/weblate/settings.py #================================================= # PIP INSTALLATION From 754031c17e88cd32a70853a9f5589497158f1e19 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Fri, 15 Sep 2017 13:13:37 +0200 Subject: [PATCH 07/10] Go to the right directory --- scripts/install | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/install b/scripts/install index f69adb5..06061ec 100755 --- a/scripts/install +++ b/scripts/install @@ -175,6 +175,7 @@ echo "SPECIFIC SETUP Filling up the database" set +eu source ${final_path}/venv/bin/activate export DJANGO_SETTINGS_MODULE="weblate.settings" + cd ${final_path} weblate migrate --noinput # generate static files weblate collectstatic --noinput From 5adeb77268511789dc1e141e27d5fc8a4a078304 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Fri, 15 Sep 2017 16:59:22 +0200 Subject: [PATCH 08/10] Remove install from source and copy settings at the right place --- conf/app.src | 6 ------ conf/settings.py | 2 +- scripts/install | 48 +++++++++++++++++++++--------------------------- 3 files changed, 22 insertions(+), 34 deletions(-) delete mode 100644 conf/app.src diff --git a/conf/app.src b/conf/app.src deleted file mode 100644 index 729f27c..0000000 --- a/conf/app.src +++ /dev/null @@ -1,6 +0,0 @@ -SOURCE_URL=https://dl.cihar.com/weblate/Weblate-2.16.tar.xz -SOURCE_SUM=0cd67d3eef8fb414c55d9447a361feb9718e39460c85de51fc0c636838625c70 -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.xz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME=Weblate-2.16.tar.xz diff --git a/conf/settings.py b/conf/settings.py index d53c5c4..8df879a 100644 --- a/conf/settings.py +++ b/conf/settings.py @@ -59,7 +59,7 @@ DATABASES = { } } -BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +BASE_DIR = '__FINALPATH__' # Data directory DATA_DIR = os.path.join(BASE_DIR, '..', 'data') diff --git a/scripts/install b/scripts/install index 06061ec..f5442dc 100755 --- a/scripts/install +++ b/scripts/install @@ -85,14 +85,6 @@ ynh_mysql_setup_db $db_name $db_name # https://docs.weblate.org/en/latest/admin/install.html#unicode-issues-in-mysql ynh_mysql_execute_as_root "ALTER DATABASE $db_name CHARACTER SET utf8mb4;" -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE -#================================================= - -ynh_app_setting_set $app final_path $final_path -# Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source "$final_path" - #================================================= # NGINX CONFIGURATION #================================================= @@ -134,25 +126,6 @@ systemctl restart $app.uwsgi.service # Add weblate.uwsgi as a service yunohost service add $app.uwsgi.service -#================================================= -# SPECIFIC SETUP settings.py -# https://docs.weblate.org/en/latest/admin/install.html#installation -#================================================= -echo "SPECIFIC SETUP settings.py" -db_pwd=$(ynh_app_setting_get $app mysqlpwd) -admin_mail="$(ynh_user_get_info $admin mail)" -key=$(ynh_string_random 64) - -cp ../conf/settings.py $final_path/weblate/settings.py - -ynh_replace_string "__NAME__" "$app" $final_path/weblate/settings.py -ynh_replace_string "__DB_PWD__" "$db_pwd" $final_path/weblate/settings.py -ynh_replace_string "__ADMIN__" "$admin" $final_path/weblate/settings.py -ynh_replace_string "__ADMINMAIL__" "$admin_mail" $final_path/weblate/settings.py -ynh_replace_string "__DOMAIN__" "$domain" $final_path/weblate/settings.py -ynh_replace_string "__KEY__" "$key" $final_path/weblate/settings.py -ynh_replace_string "__PATHURL__" "$path_url" $final_path/weblate/settings.py - #================================================= # PIP INSTALLATION #================================================= @@ -165,6 +138,27 @@ virtualenv ${final_path}/venv ${final_path}/venv/bin/pip install pytz python-bidi PyYaML Babel pyuca pylibravatar pydns ) +#================================================= +# SPECIFIC SETUP settings.py +# https://docs.weblate.org/en/latest/admin/install.html#installation +#================================================= +echo "SPECIFIC SETUP settings.py" +db_pwd=$(ynh_app_setting_get $app mysqlpwd) +admin_mail="$(ynh_user_get_info $admin mail)" +key=$(ynh_string_random 64) + +cp ../conf/settings.py $final_path/venv/lib/python2.7/site-packages/weblate/settings.py + +ynh_replace_string "__NAME__" "$app" $final_path/venv/lib/python2.7/site-packages/weblate/settings.py +ynh_replace_string "__DB_PWD__" "$db_pwd" $final_path/venv/lib/python2.7/site-packages/weblate/settings.py +ynh_replace_string "__ADMIN__" "$admin" $final_path/venv/lib/python2.7/site-packages/weblate/settings.py +ynh_replace_string "__ADMINMAIL__" "$admin_mail" $final_path/venv/lib/python2.7/site-packages/weblate/settings.py +ynh_replace_string "__DOMAIN__" "$domain" $final_path/venv/lib/python2.7/site-packages/weblate/settings.py +ynh_replace_string "__KEY__" "$key" $final_path/venv/lib/python2.7/site-packages/weblate/settings.py +ynh_replace_string "__PATHURL__" "$path_url" $final_path/venv/lib/python2.7/site-packages/weblate/settings.py +ynh_replace_string "__FINALPATH__" "$final_path" $final_path/venv/lib/python2.7/site-packages/weblate/settings.py + + #================================================= # SPECIFIC SETUP Filling up the database # https://docs.weblate.org/en/latest/admin/install.html#filling-up-the-database From 68f5d0502e2e25464577e3213a98f80394dba1f7 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Fri, 15 Sep 2017 17:25:04 +0200 Subject: [PATCH 09/10] make sure wsgi use the virtualenv file --- conf/uwsgi.ini | 2 +- scripts/install | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/conf/uwsgi.ini b/conf/uwsgi.ini index ab39ec6..e293d58 100644 --- a/conf/uwsgi.ini +++ b/conf/uwsgi.ini @@ -6,7 +6,7 @@ gid = users home = __FINALPATH__/venv protocol = uwsgi -wsgi-file = __FINALPATH__/weblate/wsgi.py +wsgi-file = __FINALPATH__/venv/lib/python2.7/site-packages/weblate/wsgi.py python-path = __FINALPATH__ # Needed for OAuth/OpenID buffer-size = 8192 diff --git a/scripts/install b/scripts/install index f5442dc..6230c96 100755 --- a/scripts/install +++ b/scripts/install @@ -141,6 +141,7 @@ virtualenv ${final_path}/venv #================================================= # SPECIFIC SETUP settings.py # https://docs.weblate.org/en/latest/admin/install.html#installation +# TODO: use --extra-search-dir=/path/to/dists #================================================= echo "SPECIFIC SETUP settings.py" db_pwd=$(ynh_app_setting_get $app mysqlpwd) From d7551b07e5d4ebefeb9da3ab91834af80cd01430 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Fri, 15 Sep 2017 17:29:32 +0200 Subject: [PATCH 10/10] Create final_path as it's not created anymore by the help --- scripts/install | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/install b/scripts/install index 6230c96..e359cef 100755 --- a/scripts/install +++ b/scripts/install @@ -52,6 +52,8 @@ ynh_webpath_register $app $domain $path_url final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" +mkdir -p $final_path + #================================================= # STORE SETTINGS FROM MANIFEST #=================================================