diff --git a/scripts/_common.sh b/scripts/_common.sh index d400d3d..e9c7bde 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -122,3 +122,48 @@ ynh_system_user_del_group() { gpasswd -d "$username" "$group" done } + + +ynh_setup_my_nodeapp() { + # Declare an array to define the options of this helper. + local legacy_args=ai + local -A args_array=([a]=app= [i]=install_dir=) + local app + local install_dir + + ynh_handle_getopts_args "$@" + + ynh_add_systemd_config --service="${app}-nodejs" --template="nodejs.service" + ynh_add_systemd_config --service="${app}-nodejs-watcher" --template="nodejs-watcher.service" + ynh_add_config --template="nodejs-watcher.path" --destination="/etc/systemd/system/${app}-nodejs-watcher.path" + + systemctl enable "${app}-nodejs-watcher.path" --quiet + systemctl daemon-reload + + yunohost service add "${app}-nodejs" --description="$app NodeJS Server" --log="/var/log/$app-nodejs.log" + ynh_systemd_action --service_name="${app}-nodejs" + ynh_systemd_action --service_name="${app}-nodejs-watcher" + ynh_systemd_action --service_name="${app}-nodejs-watcher.path" + + # Add the config manually because yunohost does not support custom nginx confs + ynh_add_config --template="nginx-nodejs.conf" --destination="/etc/nginx/conf.d/$domain.d/$app.conf" + ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" + ynh_systemd_action --service_name=nginx --action=reload +} + +ynh_remove_my_nodeapp() { + # Declare an array to define the options of this helper. + local legacy_args=a + local -A args_array=([a]=app=) + local app + + ynh_handle_getopts_args "$@" + + yunohost service remove "${app}-nodejs" + + ynh_remove_systemd_config --service="${app}-nodejs" + ynh_remove_systemd_config --service="${app}-nodejs-watcher" + ynh_secure_remove --file="/etc/systemd/system/${app}-nodejs-watcher.path" + + ynh_remove_nodejs +} diff --git a/scripts/install b/scripts/install index c7d692b..78ef054 100644 --- a/scripts/install +++ b/scripts/install @@ -69,17 +69,8 @@ then fi # Create a dedicated NGINX config -# Use a custom nginx config when using nodejs as it is incompatible with the html/php one -if [ $nodeversion == "none" ] -then - ynh_add_nginx_config - ynh_add_config --template="example-custom-nginx-config.conf" --destination="$nginx_extra_conf_dir/sample.conf" -else - # Add the config manually because yunohost does not support custom nginx confs - ynh_add_config --template="nginx-nodejs.conf" --destination="/etc/nginx/conf.d/$domain.d/$app.conf" - ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" - ynh_systemd_action --service_name=nginx --action=reload -fi +ynh_add_nginx_config +ynh_add_config --template="example-custom-nginx-config.conf" --destination="$nginx_extra_conf_dir/sample.conf" #================================================= # CREATE DEDICATED USER @@ -157,19 +148,7 @@ then ynh_add_config --template="../sources/www/package.json" --destination="$install_dir/www/package.json" ynh_add_config --template="../sources/www/index.js" --destination="$install_dir/www/index.js" - - ynh_add_systemd_config --service="${app}-nodejs" --template="nodejs.service" - ynh_add_systemd_config --service="${app}-nodejs-watcher" --template="nodejs-watcher.service" - ynh_add_config --template="nodejs-watcher.path" --destination="/etc/systemd/system/${app}-nodejs-watcher.path" - - systemctl enable "${app}-nodejs-watcher.path" --quiet - systemctl daemon-reload - - yunohost service add "${app}-nodejs" --description="$app NodeJS Server" --log="/var/log/$app-nodejs.log" - ynh_add_config --template="nginx-nodejs.conf" --destination="$nginx_extra_conf_dir/nodejs.conf" - ynh_systemd_action --service_name="${app}-nodejs" - ynh_systemd_action --service_name="${app}-nodejs-watcher" - ynh_systemd_action --service_name="${app}-nodejs-watcher.path" + ynh_setup_my_nodeapp --app=$app --install_dir=$install_dir fi #================================================= diff --git a/scripts/remove b/scripts/remove index 03ed198..3a5bf61 100644 --- a/scripts/remove +++ b/scripts/remove @@ -51,11 +51,10 @@ ynh_remove_fpm_config #================================================= ynh_script_progression --message="Removing NodeJS configuration..." -yunohost service remove "${app}-nodejs" - -ynh_remove_systemd_config --service="${app}-nodejs" -ynh_remove_systemd_config --service="${app}-nodejs-watcher" -ynh_secure_remove --file="/etc/systemd/system/${app}-nodejs-watcher.path" +if [ $nodeversion != "none" ] +then + ynh_remove_my_nodeapp --app=$app +fi #================================================= # END OF SCRIPT diff --git a/scripts/upgrade b/scripts/upgrade index 43d0855..b81cd30 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -157,34 +157,6 @@ then ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint --phpversion=$phpversion fi -#================================================= -# NodeJS CONFIGURATION -#================================================= - -if [ $nodeversion != "none" ] -then - ynh_script_progression --message="Updating NodeJS..." --weight=3 - - ynh_install_nodejs --nodejs_version=$nodeversion - ynh_use_nodejs - - ynh_add_config --template="../sources/www/package.json" --destination="$install_dir/www/package.json" - ynh_add_config --template="../sources/www/index.js" --destination="$install_dir/www/index.js" - - ynh_add_systemd_config --service="${app}-nodejs" --template="nodejs.service" - ynh_add_systemd_config --service="${app}-nodejs-watcher" --template="nodejs-watcher.service" - ynh_add_config --template="nodejs-watcher.path" --destination="/etc/systemd/system/${app}-nodejs-watcher.path" - - systemctl enable "${app}-nodejs-watcher.path" --quiet - systemctl daemon-reload - - yunohost service add "${app}-nodejs" --description="$app NodeJS Server" --log="/var/log/$app-nodejs.log" - ynh_add_config --template="nginx-nodejs.conf" --destination="$nginx_extra_conf_dir/nodejs.conf" - ynh_systemd_action --service_name="${app}-nodejs" - ynh_systemd_action --service_name="${app}-nodejs-watcher" - ynh_systemd_action --service_name="${app}-nodejs-watcher.path" -fi - #================================================= # GENERIC FINALIZATION #================================================= @@ -199,6 +171,22 @@ setfacl -m g:$app:r-x "$install_dir" setfacl -m g:www-data:r-x "$install_dir" chmod 750 "$install_dir" +#================================================= +# NodeJS CONFIGURATION +#================================================= + +if [ $nodeversion != "none" ] +then + ynh_script_progression --message="Updating NodeJS..." --weight=3 + + ynh_install_nodejs --nodejs_version=$nodeversion + ynh_use_nodejs + + ynh_add_config --template="../sources/www/package.json" --destination="$install_dir/www/package.json" + ynh_add_config --template="../sources/www/index.js" --destination="$install_dir/www/index.js" + ynh_setup_my_nodeapp --app=$app --install_dir=$install_dir +fi + #================================================= # DEACTIVE MAINTENANCE MODE #=================================================