diff --git a/conf/jobs.service b/conf/jobs.service index 68b255c..4cfb3c6 100644 --- a/conf/jobs.service +++ b/conf/jobs.service @@ -8,7 +8,7 @@ User=__APP__ Group=__APP__ WorkingDirectory=__INSTALL_DIR__/ EnvironmentFile=__INSTALL_DIR__/.env -Environment="__YNH_RUBY_LOAD_PATH__" +Environment="PATH=__PATH_WITH_RUBY__" ExecStart=/opt/rbenv/versions/__APP__/bin/bundle exec rails runner bin/threaded.rb StandardOutput=append:__INSTALL_DIR__/log/__APP__-jobs.log StandardError=inherit diff --git a/conf/web.service b/conf/web.service index 12a5b4d..dedcb32 100644 --- a/conf/web.service +++ b/conf/web.service @@ -8,7 +8,7 @@ User=__APP__ Group=__APP__ WorkingDirectory=__INSTALL_DIR__/ EnvironmentFile=__INSTALL_DIR__/.env -Environment="__YNH_RUBY_LOAD_PATH__" +Environment="PATH=__PATH_WITH_RUBY__" ExecStart=/opt/rbenv/versions/__APP__/bin/bundle exec unicorn -c config/unicorn.rb StandardOutput=append:__INSTALL_DIR__/log/__APP__-web.log StandardError=inherit diff --git a/manifest.toml b/manifest.toml index eaa2aab..47d15f1 100644 --- a/manifest.toml +++ b/manifest.toml @@ -15,7 +15,8 @@ license = "MIT" code = "https://github.com/huginn/huginn" [integration] -yunohost = ">= 11.2.12" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = "all" multi_instance = true ldap = false @@ -56,6 +57,7 @@ ram.runtime = "50M" [resources.system_user] [resources.install_dir] + group = "www-data:r-x" [resources.permissions] main.url = "/" diff --git a/scripts/_common.sh b/scripts/_common.sh index 6a96b69..465a570 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,19 +1,7 @@ #!/bin/bash #================================================= -# COMMON VARIABLES +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= ruby_version=3.2.4 - -#================================================= -# PERSONAL HELPERS -#================================================= - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - -#================================================= -# FUTURE OFFICIAL HELPERS -#================================================= diff --git a/scripts/backup b/scripts/backup index 715d768..abd60ab 100644 --- a/scripts/backup +++ b/scripts/backup @@ -8,35 +8,32 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# DECLARE DATA AND CONF FILES TO BACKUP -#================================================= -ynh_print_info --message="Declaring files to be backed up..." +ynh_print_info "Declaring files to be backed up..." #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$install_dir" +ynh_backup "$install_dir" #================================================= # SYSTEM CONFIGURATION #================================================= -ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_backup --src_path="/etc/systemd/system/$app-web.service" -ynh_backup --src_path="/etc/systemd/system/$app-jobs.service" +ynh_backup "/etc/systemd/system/$app-web.service" +ynh_backup "/etc/systemd/system/$app-jobs.service" #================================================= # BACKUP THE MYSQL DATABASE #================================================= -ynh_print_info --message="Backing up the MySQL database..." +ynh_print_info "Backing up the MySQL database..." -ynh_mysql_dump_db --database="$db_name" > db.sql +ynh_mysql_dump_db > db.sql #================================================= # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/change_url b/scripts/change_url index de0fe43..8a0f0f2 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -10,41 +10,42 @@ source /usr/share/yunohost/helpers #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping $app's systemd service..." +ynh_script_progression "Stopping $app's systemd service..." -ynh_systemd_action --service_name="$app-web" --action="stop" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name="$app-jobs" --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemctl --service="$app-web" --action="stop" + +ynh_systemctl --service="$app-jobs" --action="stop" #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." +ynh_script_progression "Updating NGINX web server configuration..." -ynh_change_url_nginx_config +ynh_config_change_url_nginx #================================================= # SPECIFIC MODIFICATIONS #================================================= -ynh_script_progression --message="Updating $app's configuration file..." +ynh_script_progression "Updating $app's configuration file..." #domain=$new_domain #path=$new_path -ynh_add_config --template=".env.example" --destination="$install_dir/.env" +ynh_config_add --template=".env.example" --destination="$install_dir/.env" -chmod 400 "$install_dir/.env" -chown "$app:$app" "$install_dir/.env" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/.env" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" "$install_dir/.env" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting $app's systemd service..." +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name="$app-web" --action="start" --log_path="$install_dir/log/unicorn.log" --line_match="listening on addr" -ynh_systemd_action --service_name="$app-jobs" --action="start" --log_path="$install_dir/log/huginn-jobs.log" +ynh_systemctl --service="$app-web" --action="start" --log_path="$install_dir/log/unicorn.log" --wait_until="listening on addr" +ynh_systemctl --service="$app-jobs" --action="start" --log_path="$install_dir/log/huginn-jobs.log" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" +ynh_script_progression "Change of URL completed for $app" diff --git a/scripts/install b/scripts/install index 9c69d43..32ef32a 100755 --- a/scripts/install +++ b/scripts/install @@ -13,58 +13,57 @@ source /usr/share/yunohost/helpers secret=$(ynh_string_random --length=16) -ynh_app_setting_set --app="$app" --key="secret" --value="$secret" +ynh_app_setting_set --key="secret" --value="$secret" #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing Ruby..." +ynh_script_progression "Installing Ruby..." -ynh_install_ruby --ruby_version=$ruby_version +ynh_ruby_install #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." +ynh_script_progression "Setting up source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir" mkdir -p "$install_dir/log" "$install_dir/tmp/pids" "$install_dir/tmp/sockets" -chmod -R o-rwx "$install_dir" -chown -R "$app:www-data" "$install_dir" - +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir" #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding $app's configuration file..." +ynh_script_progression "Adding $app's configuration file..." -ynh_add_config --template=".env.example" --destination="$install_dir/.env" +ynh_config_add --template=".env.example" --destination="$install_dir/.env" -chmod 400 "$install_dir/.env" -chown "$app:$app" "$install_dir/.env" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/.env" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" "$install_dir/.env" #================================================= # BUILD APP #================================================= -ynh_script_progression --message="Building app..." +ynh_script_progression "Building app..." pushd "$install_dir" - ynh_use_ruby + cp config/unicorn.rb.example config/unicorn.rb chown -R "$app:www-data" "$install_dir/config/unicorn.rb" - ynh_gem install rubygems-update -v 3.4 - ynh_gem update --system --no-document - ynh_gem install bundler -v 2.4.22 - ynh_gem install rake foreman --no-document + gem install rubygems-update -v 3.4 + gem update --system --no-document + gem install bundler -v 2.4.22 + gem install rake foreman --no-document bundle config set --local deployment 'true' bundle config set --local without 'development test' bundle install - ynh_exec_warn_less bundle exec rake db:create RAILS_ENV=production - ynh_exec_warn_less bundle exec rake db:migrate RAILS_ENV=production - ynh_exec_warn_less bundle exec rake db:seed RAILS_ENV=production SEED_USERNAME=$admin SEED_PASSWORD=$password - ynh_exec_warn_less bundle exec rake assets:precompile RAILS_ENV=production + ynh_hide_warnings bundle exec rake db:create RAILS_ENV=production + ynh_hide_warnings bundle exec rake db:migrate RAILS_ENV=production + ynh_hide_warnings bundle exec rake db:seed RAILS_ENV=production SEED_USERNAME=$admin SEED_PASSWORD=$password + ynh_hide_warnings bundle exec rake assets:precompile RAILS_ENV=production popd chmod 750 "$install_dir/public" @@ -74,29 +73,29 @@ chown -R "$app:www-data" "$install_dir/public" #================================================= # SYSTEM CONFIGURATION #================================================= -ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 +ynh_script_progression "Adding system configurations related to $app..." # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx # Create a dedicated systemd config -ynh_add_systemd_config --service="$app-web" --template="web.service" +ynh_config_add_systemd --service="$app-web" --template="web.service" yunohost service add "$app-web" --log="$install_dir/log/unicorn.log" -ynh_add_systemd_config --service="$app-jobs" --template="jobs.service" +ynh_config_add_systemd --service="$app-jobs" --template="jobs.service" yunohost service add "$app-jobs" --log="$install_dir/log/production.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting $app's systemd services..." +ynh_script_progression "Starting $app's systemd services..." # Start a systemd service -ynh_systemd_action --service_name="$app-web" --action="start" --log_path="$install_dir/log/unicorn.log" --line_match="listening on addr" -ynh_systemd_action --service_name="$app-jobs" --action="start" --log_path="$install_dir/log/huginn-jobs.log" --line_match="Starting" +ynh_systemctl --service="$app-web" --action="start" --log_path="$install_dir/log/unicorn.log" --wait_until="listening on addr" +ynh_systemctl --service="$app-jobs" --action="start" --log_path="$install_dir/log/huginn-jobs.log" --wait_until="Starting" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" +ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 8318576..ba1249c 100755 --- a/scripts/remove +++ b/scripts/remove @@ -10,29 +10,29 @@ source /usr/share/yunohost/helpers #================================================= # REMOVE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 +ynh_script_progression "Removing system configurations related to $app..." # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status "$app-web" >/dev/null; then +if ynh_hide_warnings yunohost service status "$app-web" >/dev/null; then yunohost service remove "$app-web" fi # Remove the dedicated systemd config -ynh_remove_systemd_config --service="$app-web" +ynh_config_remove_systemd"$app-web" -if ynh_exec_warn_less yunohost service status "$app-jobs" >/dev/null; then +if ynh_hide_warnings yunohost service status "$app-jobs" >/dev/null; then yunohost service remove "$app-jobs" fi # Remove the dedicated systemd config -ynh_remove_systemd_config --service="$app-jobs" +ynh_config_remove_systemd"$app-jobs" # Remove the dedicated NGINX config -ynh_remove_nginx_config +ynh_config_remove_nginx # Remove metapackage and its dependencies -ynh_remove_ruby +ynh_ruby_remove #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" +ynh_script_progression "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 25dd100..748d877 100644 --- a/scripts/restore +++ b/scripts/restore @@ -11,44 +11,43 @@ source /usr/share/yunohost/helpers #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling Ruby..." +ynh_script_progression "Reinstalling Ruby..." -ynh_install_ruby --ruby_version=$ruby_version +ynh_ruby_install #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." +ynh_script_progression "Restoring the app main directory..." -ynh_restore_file --origin_path="$install_dir" +ynh_restore "$install_dir" mkdir -p "$install_dir/log" "$install_dir/tmp/pids" "$install_dir/tmp/sockets" -chmod -R o-rwx "$install_dir" -chown -R "$app:www-data" "$install_dir" - +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir" #================================================= # RESTORE THE MYSQL DATABASE #================================================= -ynh_script_progression --message="Restoring the MySQL database..." --weight=1 +ynh_script_progression "Restoring the MySQL database..." -ynh_mysql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql +ynh_mysql_db_shell < ./db.sql #================================================= # BUILD APP #================================================= -ynh_script_progression --message="Building app..." +ynh_script_progression "Building app..." pushd "$install_dir" - ynh_use_ruby - ynh_gem install rubygems-update -v 3.4 - ynh_gem update --system --no-document - ynh_gem install bundler -v 2.4.22 - ynh_gem install rake foreman --no-document + + gem install rubygems-update -v 3.4 + gem update --system --no-document + gem install bundler -v 2.4.22 + gem install rake foreman --no-document bundle config set --local deployment 'true' - ynh_exec_warn_less bundle config set --local without 'development test' - ynh_exec_warn_less bundle install - ynh_exec_warn_less bundle exec rake assets:clean assets:precompile tmp:cache:clear RAILS_ENV=production + ynh_hide_warnings bundle config set --local without 'development test' + ynh_hide_warnings bundle install + ynh_hide_warnings bundle exec rake assets:clean assets:precompile tmp:cache:clear RAILS_ENV=production popd chmod 750 "$install_dir/public" @@ -58,31 +57,31 @@ chown -R "$app:www-data" "$install_dir/public" #================================================= # RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 +ynh_script_progression "Restoring system configurations related to $app..." -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_restore_file --origin_path="/etc/systemd/system/$app-web.service" +ynh_restore "/etc/systemd/system/$app-web.service" systemctl enable "$app-web.service" --quiet yunohost service add "$app-web" --log="$install_dir/log/unicorn.log" -ynh_restore_file --origin_path="/etc/systemd/system/$app-jobs.service" +ynh_restore "/etc/systemd/system/$app-jobs.service" systemctl enable "$app-jobs.service" --quiet yunohost service add "$app-jobs" --log="$install_dir/log/production.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Reloading NGINX web server and $app's service..." +ynh_script_progression "Reloading NGINX web server and $app's service..." # Start a systemd service -ynh_systemd_action --service_name="$app-web" --action="start" --log_path="$install_dir/log/unicorn.log" --line_match="listening on addr" -ynh_systemd_action --service_name="$app-jobs" --action="start" --log_path="$install_dir/log/huginn-jobs.log" --line_match="Starting" +ynh_systemctl --service="$app-web" --action="start" --log_path="$install_dir/log/unicorn.log" --wait_until="listening on addr" +ynh_systemctl --service="$app-jobs" --action="start" --log_path="$install_dir/log/huginn-jobs.log" --wait_until="Starting" -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemctl --service=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" +ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index 8d6991d..804038e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -10,58 +10,58 @@ source /usr/share/yunohost/helpers #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping $app's systemd services..." +ynh_script_progression "Stopping $app's systemd services..." -ynh_systemd_action --service_name="$app-web" --action="stop" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name="$app-jobs" --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemctl --service="$app-web" --action="stop" + +ynh_systemctl --service="$app-jobs" --action="stop" #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Upgrading Ruby..." --weight=1 +ynh_script_progression "Upgrading Ruby..." -ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version +ynh_ruby_install #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Upgrading source files..." +ynh_script_progression "Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source --dest_dir="$install_dir" --full_replace=1 --keep=".env" +ynh_setup_source --dest_dir="$install_dir" --full_replace --keep=".env" mkdir -p "$install_dir/log" "$install_dir/tmp/pids" "$install_dir/tmp/sockets" -chmod -R o-rwx "$install_dir" -chown -R "$app:www-data" "$install_dir" - +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir" #================================================= # UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating a configuration file..." +ynh_script_progression "Updating configuration..." -ynh_add_config --template="../conf/.env.example" --destination="$install_dir/.env" +ynh_config_add --template=".env.example" --destination="$install_dir/.env" -chmod 400 "$install_dir/.env" -chown "$app:$app" "$install_dir/.env" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/.env" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" "$install_dir/.env" #================================================= # BUILD APP #================================================= -ynh_script_progression --message="Building app..." +ynh_script_progression "Building app..." pushd $install_dir - ynh_use_ruby + cp -f config/unicorn.rb.example config/unicorn.rb chown -R "$app:www-data" "$install_dir/config/unicorn.rb" - ynh_gem install rubygems-update -v 3.4 - ynh_gem update --system --no-document - ynh_gem install bundler -v 2.4.22 - ynh_gem install rake foreman --no-document + gem install rubygems-update -v 3.4 + gem update --system --no-document + gem install bundler -v 2.4.22 + gem install rake foreman --no-document bundle config set --local deployment 'true' bundle config set --local without 'development test' bundle install - ynh_exec_warn_less bundle exec rake db:migrate RAILS_ENV=production - ynh_exec_warn_less bundle exec rake assets:clean assets:precompile tmp:cache:clear RAILS_ENV=production + ynh_hide_warnings bundle exec rake db:migrate RAILS_ENV=production + ynh_hide_warnings bundle exec rake assets:clean assets:precompile tmp:cache:clear RAILS_ENV=production popd chmod 750 "$install_dir/public" @@ -71,29 +71,29 @@ chown -R "$app:www-data" "$install_dir/public" #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 +ynh_script_progression "Upgrading system configurations related to $app..." # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx # Create a dedicated systemd config -ynh_add_systemd_config --service="$app-web" --template="web.service" +ynh_config_add_systemd --service="$app-web" --template="web.service" yunohost service add "$app-web" --log="$install_dir/log/unicorn.log" -ynh_add_systemd_config --service="$app-jobs" --template="jobs.service" +ynh_config_add_systemd --service="$app-jobs" --template="jobs.service" yunohost service add "$app-jobs" --log="$install_dir/log/production.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting $app's systemd service..." +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name="$app-web" --action="start" --log_path="$install_dir/log/unicorn.log" --line_match="listening on addr" -ynh_systemd_action --service_name="$app-jobs" --action="start" --log_path="$install_dir/log/huginn-jobs.log" --line_match="Starting" +ynh_systemctl --service="$app-web" --action="start" --log_path="$install_dir/log/unicorn.log" --wait_until="listening on addr" +ynh_systemctl --service="$app-jobs" --action="start" --log_path="$install_dir/log/huginn-jobs.log" --wait_until="Starting" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" +ynh_script_progression "Upgrade of $app completed"