diff --git a/scripts/_common.sh b/scripts/_common.sh index a2f8cdc..81fa75d 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -24,16 +24,22 @@ ynh_check_global_uwsgi_config () { # __PATH__ by $path_url # __FINALPATH__ by $final_path # +# And dynamic variables (from the last example) : +# __PATH_2__ by $path_2 +# __PORT_2__ by $port_2 +# # usage: ynh_add_uwsgi_service # # to interact with your service: `systemctl uwsgi-app@app` ynh_add_uwsgi_service () { ynh_check_global_uwsgi_config + local others_var=${1:-} + local finaluwsgiini="/etc/uwsgi/apps-available/$app.ini" + # www-data group is needed since it is this nginx who will start the service usermod --append --groups www-data "$app" || ynh_die "It wasn't possible to add user $app to group www-data" - finaluwsgiini="/etc/uwsgi/apps-available/$app.ini" ynh_backup_if_checksum_is_different "$finaluwsgiini" cp ../conf/uwsgi.ini "$finaluwsgiini" @@ -48,6 +54,15 @@ ynh_add_uwsgi_service () { if test -n "${app:-}"; then ynh_replace_string "__APP__" "$app" "$finaluwsgiini" fi + + # Replace all other variable given as arguments + for var_to_replace in $others_var + do + # ${var_to_replace^^} make the content of the variable on upper-cases + # ${!var_to_replace} get the content of the variable named $var_to_replace + ynh_replace_string "__${var_to_replace^^}__" "${!var_to_replace}" "$finaluwsgiini" + done + ynh_store_file_checksum "$finaluwsgiini" chown $app:root "$finaluwsgiini" @@ -58,8 +73,11 @@ ynh_add_uwsgi_service () { chmod -R u=rwX,g=rX,o= /var/log/uwsgi/$app systemctl daemon-reload + systemctl stop "uwsgi-app@$app.service" systemctl enable "uwsgi-app@$app.socket" systemctl start "uwsgi-app@$app.socket" + systemctl enable "uwsgi-app@$app.service" + systemctl start "uwsgi-app@$app.service" # Add as a service yunohost service add "uwsgi-app@$app" --log "/var/log/uwsgi/$app/$app.log" @@ -69,10 +87,12 @@ ynh_add_uwsgi_service () { # # usage: ynh_remove_uwsgi_service ynh_remove_uwsgi_service () { - finaluwsgiini="/etc/uwsgi/apps-available/$app.ini" + local finaluwsgiini="/etc/uwsgi/apps-available/$app.ini" if [ -e "$finaluwsgiini" ]; then systemctl stop "uwsgi-app@$app.socket" systemctl disable "uwsgi-app@$app.socket" + systemctl stop "uwsgi-app@$app.service" + systemctl disable "uwsgi-app@$app.service" yunohost service remove "uwsgi-app@$app" ynh_secure_remove "$finaluwsgiini" diff --git a/scripts/install b/scripts/install index 208e2a6..fe798b1 100644 --- a/scripts/install +++ b/scripts/install @@ -113,37 +113,6 @@ ynh_system_user_create "$app" "$final_path" #================================================= # SPECIFIC SETUP -#================================================= -# create config file syncserver.ini -#================================================= - -# Generate random password and save -secret=$(ynh_string_random) -ynh_app_setting_set "$app" secret "$secret" - -# Copy Files -ynh_replace_string "__APP__" "$app" "$finaluwsgiini" -ynh_replace_string "__DOMAIN__" "$domain" "$finaluwsgiini" -ynh_replace_string "__PATH__" "$path_url" "$finaluwsgiini" -ynh_replace_string "__NAME__" "$app" "$finaluwsgiini" -ynh_replace_string "__FINALPATH__" "$final_path" "$finaluwsgiini" -ynh_replace_string "__SECRET__" "$secret" "$finaluwsgiini" - -ynh_replace_string "__DB_USER__" "$db_user" "$finaluwsgiini" -ynh_replace_string "__DB_PWD__" "$db_pwd" "$finaluwsgiini" -ynh_replace_string "__DB_NAME__" "$db_name" "$finaluwsgiini" - -rm "$final_path/syncserver.ini" -ln -s "$finaluwsgiini" "$final_path/syncserver.ini" - -#================================================= -# MODIFY A CONFIG FILE -#================================================= - -# TODO: fix this css patch -# ynh_replace_string "media\/img@$path_url\/media\/img@g" $final_path/syncserver/page/sync_files/firefox_sync-bundle.css -# ynh_replace_string "media\/img@$path_url\/media\/img@g" $final_path/syncserver/page/sync_files/responsive-bundle.css - #================================================= # pip installation #================================================= @@ -170,14 +139,6 @@ virtualenv "$final_path/local" cp -r ../sources/page $final_path/syncserver/ (cd "$final_path/syncserver" && patch -p1 < $YNH_CWD/../sources/homepage.patch) || echo "Unable to apply patches" -#================================================= -# SETUP UWSGI -#================================================= - -ynh_add_uwsgi_service - -#================================================= -# GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= @@ -185,6 +146,32 @@ ynh_add_uwsgi_service chown $app -R $final_path chmod u=rwX,g=rX,o= -R $final_path + +#================================================= +# SETUP UWSGI +#================================================= + +# Generate random password and save +secret=$(ynh_string_random) +ynh_app_setting_set "$app" secret "$secret" + +# create config file syncserver.ini +rm "$final_path/syncserver.ini" +ln -s "/etc/uwsgi/apps-available/$app.ini" "$final_path/syncserver.ini" + +# configure uwsgi +ynh_add_uwsgi_service 'domain secret db_user db_pwd db_name' + +#================================================= +# MODIFY A CONFIG FILE +#================================================= + +# TODO: fix this css patch +# ynh_replace_string "media\/img@$path_url\/media\/img@g" $final_path/syncserver/page/sync_files/firefox_sync-bundle.css +# ynh_replace_string "media\/img@$path_url\/media\/img@g" $final_path/syncserver/page/sync_files/responsive-bundle.css + +#================================================= +# GENERIC FINALIZATION #================================================= # SETUP LOGROTATE #================================================= @@ -197,10 +184,3 @@ ynh_use_logrotate /var/log/uwsgi/$app # accessible by everyone (authentification is done by firefox accounts) ynh_app_setting_set "$app" skipped_uris "/" - -#================================================= -# RELOAD NGINX -#================================================= - -systemctl start "uwsgi-app@$app.service" -systemctl reload nginx diff --git a/scripts/upgrade b/scripts/upgrade index a37a945..ead10a4 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -98,12 +98,6 @@ ynh_install_app_dependencies python-dev python-virtualenv \ `# ARM support: ` \ build-essential libssl-dev libffi-dev -#================================================= -# SPECIFIC SETUP UWSGI -#================================================= - -ynh_add_uwsgi_service - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -139,25 +133,6 @@ fi # Create a system user ynh_system_user_create "$app" -#================================================= -# SPECIFIC UPGRADE -#================================================= - -# Copy Files -ynh_replace_string "__APP__" "$app" "$finaluwsgiini" -ynh_replace_string "__DOMAIN__" "$domain" "$finaluwsgiini" -ynh_replace_string "__PATH__" "$path_url" "$finaluwsgiini" -ynh_replace_string "__NAME__" "$app" "$finaluwsgiini" -ynh_replace_string "__FINALPATH__" "$final_path" "$finaluwsgiini" -ynh_replace_string "__SECRET__" "$secret" "$finaluwsgiini" - -ynh_replace_string "__DB_USER__" "$db_user" "$finaluwsgiini" -ynh_replace_string "__DB_PWD__" "$db_pwd" "$finaluwsgiini" -ynh_replace_string "__DB_NAME__" "$db_name" "$finaluwsgiini" - -rm "$final_path/syncserver.ini" -ln -s "$finaluwsgiini" "$final_path/syncserver.ini" - #================================================= # pip installation #================================================= @@ -184,8 +159,6 @@ virtualenv "$final_path/local" cp -r ../sources/page $final_path/syncserver/ (cd "$final_path/syncserver" && patch -p1 < $YNH_CWD/../sources/homepage.patch) || echo "Unable to apply patches" -#================================================= -# GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= @@ -193,6 +166,19 @@ cp -r ../sources/page $final_path/syncserver/ chown $app -R $final_path chmod u=rwX,g=rX,o= -R $final_path +#================================================= +# SETUP UWSGI +#================================================= + +# create config file syncserver.ini +rm "$final_path/syncserver.ini" +ln -s "/etc/uwsgi/apps-available/$app.ini" "$final_path/syncserver.ini" + +# configure uwsgi +ynh_add_uwsgi_service 'domain secret db_user db_pwd db_name' + +#================================================= +# GENERIC FINALIZATION #================================================= # SETUP LOGROTATE #=================================================