Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[autopatch] Automatic patch attempt for helpers 2.1 #132

Open
wants to merge 1 commit into
base: testing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conf/fab-manager-app.service
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Type=simple
User=__APP__
WorkingDirectory=__INSTALL_DIR__
Environment="__LD_PRELOAD__"
Environment="__YNH_RUBY_LOAD_PATH__"
Environment="PATH=__PATH_WITH_RUBY__"
Environment="RAILS_ENV=production"
ExecStartPre=-rm -f __INSTALL_DIR__/tmp/pids/server.pid
ExecStart=__INSTALL_DIR__/bin/bundle exec rails s puma -p __PORT__ -b 127.0.0.1
Expand Down
2 changes: 1 addition & 1 deletion conf/fab-manager-worker.service
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Type=simple
User=__APP__
WorkingDirectory=__INSTALL_DIR__
Environment="__LD_PRELOAD__"
Environment="__YNH_RUBY_LOAD_PATH__"
Environment="PATH=__PATH_WITH_RUBY__"
Environment="RAILS_ENV=production"
ExecStart=__INSTALL_DIR__/bin/bundle exec sidekiq -C __INSTALL_DIR__/config/sidekiq.yml
TimeoutSec=15
Expand Down
4 changes: 3 additions & 1 deletion manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ admindoc = "http://doc.fab.mn"
code = "https://github.com/sleede/fab-manager"

[integration]
yunohost = ">= 11.2.12"
yunohost = ">= 11.2.18"
helpers_version = "2.1"
architectures = "all"
multi_instance = false
ldap = false
Expand Down Expand Up @@ -55,6 +56,7 @@ ram.runtime = "50M"
allow_email = true

[resources.install_dir]
group = "www-data:r-x"

[resources.data_dir]

Expand Down
49 changes: 18 additions & 31 deletions scripts/_common.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

#=================================================
# COMMON VARIABLES
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================

ruby_version="2.6.10"
Expand All @@ -23,53 +23,40 @@ else
ld_preload=""
fi

#=================================================
# PERSONAL HELPERS
#=================================================

fabmanager_build_ruby() {
pushd "$install_dir"
ynh_use_ruby
ynh_exec_warn_less $ynh_gem install "bundler:$bundler_version"
ynh_exec_warn_less bin/bundle config --global frozen 1
ynh_exec_warn_less bin/bundle config set --local without 'development test doc'
ynh_exec_warn_less bin/bundle install
ynh_exec_warn_less bin/bundle binstubs --all

ynh_hide_warnings gem install "bundler:$bundler_version"
ynh_hide_warnings bin/bundle config --global frozen 1
ynh_hide_warnings bin/bundle config set --local without 'development test doc'
ynh_hide_warnings bin/bundle install
ynh_hide_warnings bin/bundle binstubs --all
popd
}

fabmanager_seed_db() {
pushd "$install_dir"
ynh_replace_string --match_string="DateTime.current" --replace_string="DateTime.current - 1.days" --target_file="$install_dir/db/seeds.rb"
ynh_exec_warn_less ynh_exec_as "$app" env RAILS_ENV=production "$ynh_ruby_load_path" $ld_preload \
ynh_replace --match="DateTime.current" --replace="DateTime.current - 1.days" --file="$install_dir/db/seeds.rb"
ynh_hide_warnings ynh_exec_as_app RAILS_ENV=production ruby_load_path" $ld_preload \
bin/bundle exec rake db:seed ADMIN_EMAIL="$admin_mail" ADMIN_PASSWORD="$password"
popd
}

fabmanager_migrate_db() {
pushd "$install_dir"
ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH SUPERUSER;"
ynh_exec_warn_less ynh_exec_as "$app" env RAILS_ENV=production "$ynh_ruby_load_path" $ld_preload bin/bundle exec rake db:migrate
ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH NOSUPERUSER;"
ynh_psql_db_shell <<< "ALTER USER $db_user WITH SUPERUSER;"
ynh_hide_warnings ynh_exec_as_app RAILS_ENV=production ruby_load_path" $ld_preload bin/bundle exec rake db:migrate
ynh_psql_db_shell <<< "ALTER USER $db_user WITH NOSUPERUSER;"
popd
}

fabmanager_build_ui() {
pushd "$install_dir"
ynh_use_nodejs
ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" yarn install
#ynh_exec_warn_less ynh_exec_as "$app" env RAILS_ENV=production "$ynh_ruby_load_path" $ld_preload yarn install
#ynh_exec_warn_less ynh_exec_as "$app" env RAILS_ENV=production "$ynh_ruby_load_path" $ld_preload bin/webpack
ynh_exec_warn_less ynh_exec_as "$app" env RAILS_ENV=production "$ynh_ruby_load_path" $ld_preload bin/bundle exec rake assets:precompile
ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" yarn cache clean --all

ynh_hide_warnings ynh_exec_as_app node_load_PATH" yarn install
#ynh_hide_warnings ynh_exec_as_app RAILS_ENV=production ruby_load_path" $ld_preload yarn install
#ynh_hide_warnings ynh_exec_as_app RAILS_ENV=production ruby_load_path" $ld_preload bin/webpack
ynh_hide_warnings ynh_exec_as_app RAILS_ENV=production ruby_load_path" $ld_preload bin/bundle exec rake assets:precompile
ynh_hide_warnings ynh_exec_as_app node_load_PATH" yarn cache clean --all
popd
}


#=================================================
# EXPERIMENTAL HELPERS
#=================================================

#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================
21 changes: 9 additions & 12 deletions scripts/backup
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,38 @@
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"

#=================================================
# BACKUP THE DATA DIR
#=================================================

ynh_backup --src_path="$data_dir" --is_big
ynh_backup "$data_dir"

#=================================================
# BACKUP THE 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-app.service"
ynh_backup --src_path="/etc/systemd/system/$app-worker.service"
ynh_backup "/etc/systemd/system/$app-app.service"
ynh_backup "/etc/systemd/system/$app-worker.service"

#=================================================
# BACKUP THE POSTGRESQL DATABASE
#=================================================
ynh_print_info --message="Backing up the PostgreSQL database..."
ynh_print_info "Backing up the PostgreSQL database..."

ynh_psql_dump_db --database="$db_name" > db.sql
ynh_psql_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)."
28 changes: 13 additions & 15 deletions scripts/change_url
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,38 @@ admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_script_progression "Stopping $app's systemd service..."

ynh_systemd_action --service_name="${app}-app" --action="stop" --log_path=systemd
ynh_systemd_action --service_name="${app}-worker" --action="stop" --log_path=systemd
ynh_systemctl --service="${app}-app" --action="stop" --log_path=systemd
ynh_systemctl --service="${app}-worker" --action="stop" --log_path=systemd

#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1
ynh_script_progression "Updating NGINX web server configuration..."

ynh_change_url_nginx_config
ynh_config_change_url_nginx

#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1
ynh_script_progression "Updating configuration..."

ynh_add_config --template="secrets.yml" --destination="$install_dir/config/secrets.yml"
chmod 400 "$install_dir/config/secrets.yml"
chown "$app:$app" "$install_dir/config/secrets.yml"
ynh_config_add --template="secrets.yml" --destination="$install_dir/config/secrets.yml"
#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/config/secrets.yml"
#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/config/secrets.yml"

#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_script_progression "Starting $app's systemd service..."

# Start a systemd service
ynh_systemd_action --service_name="${app}-app" --action="start" --log_path=systemd
ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path=systemd --line_match="Schedules Loaded"
ynh_systemctl --service="${app}-app" --action="start" --log_path=systemd
ynh_systemctl --service="${app}-worker" --action="start" --log_path=systemd --wait_until="Schedules Loaded"

#=================================================
# END OF SCRIPT
#=================================================

ynh_script_progression --message="Change of URL completed for $app" --last
ynh_script_progression "Change of URL completed for $app"
63 changes: 31 additions & 32 deletions scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +14,58 @@ source /usr/share/yunohost/helpers
admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)

secret_key_base=$(ynh_string_random --length=30)
ynh_app_setting_set --app="$app" --key="secret_key_base" --value="$secret_key_base"
ynh_app_setting_set --key="secret_key_base" --value="$secret_key_base"

#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing NodeJS..." --weight=1
ynh_exec_warn_less ynh_install_nodejs --nodejs_version="$nodejs_version"
ynh_script_progression "Installing NodeJS..."
ynh_nodejs_install

ynh_script_progression --message="Installing Ruby..." --weight=4
ynh_exec_warn_less ynh_install_ruby --ruby_version="$ruby_version"
ynh_script_progression "Installing Ruby..."
ynh_ruby_install

#=================================================
# CREATE A POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Configuring $app's PostgreSQL database..." --weight=1
ynh_script_progression "Configuring $app's PostgreSQL database..."

ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH SUPERUSER;"
ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS unaccent;"
ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;"
ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;"
ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH NOSUPERUSER;"
ynh_psql_db_shell <<< "ALTER USER $db_user WITH SUPERUSER;"
ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS unaccent;"
ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;"
ynh_psql_db_shell <<< "ALTER USER $db_user WITH NOSUPERUSER;"

#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
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"

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"
chmod -R o-rwx "$data_dir"
chown -R "$app:www-data" "$data_dir"

#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1
ynh_script_progression "Adding $app's configuration..."

ynh_add_config --template="secrets.yml" --destination="$install_dir/config/secrets.yml"
chmod 400 "$install_dir/config/secrets.yml"
chown "$app:$app" "$install_dir/config/secrets.yml"
ynh_config_add --template="secrets.yml" --destination="$install_dir/config/secrets.yml"
#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/config/secrets.yml"
#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/config/secrets.yml"

ynh_add_config --template="database.yml" --destination="$install_dir/config/database.yml"
chmod 400 "$install_dir/config/database.yml"
chown "$app:$app" "$install_dir/config/database.yml"
ynh_config_add --template="database.yml" --destination="$install_dir/config/database.yml"
#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/config/database.yml"
#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/config/database.yml"

#=================================================
# BUILD APP
#=================================================
ynh_script_progression --message="Building app..." --weight=7
ynh_script_progression "Building app..."

fabmanager_build_ruby

Expand All @@ -75,32 +74,32 @@ fabmanager_seed_db

fabmanager_build_ui

ynh_secure_remove --file="$install_dir/.cache"
ynh_safe_rm "$install_dir/.cache"

#=================================================
# 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-app" --template="fab-manager-app.service"
ynh_config_add_systemd --service="$app-app" --template="fab-manager-app.service"
yunohost service add "$app-app" --description="$app app service"
ynh_add_systemd_config --service="$app-worker" --template="fab-manager-worker.service"
ynh_config_add_systemd --service="$app-worker" --template="fab-manager-worker.service"
yunohost service add "$app-worker" --description="$app worker service"

#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
ynh_script_progression "Starting $app's systemd service..."

ynh_systemd_action --service_name="${app}-app" --action="start" --log_path=systemd
ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path=systemd --line_match="Schedules Loaded"
ynh_systemctl --service="${app}-app" --action="start" --log_path=systemd
ynh_systemctl --service="${app}-worker" --action="start" --log_path=systemd --wait_until="Schedules Loaded"

#=================================================
# END OF SCRIPT
#=================================================

ynh_script_progression --message="Installation of $app completed" --last
ynh_script_progression "Installation of $app completed"
18 changes: 9 additions & 9 deletions scripts/remove
Original file line number Diff line number Diff line change
Expand Up @@ -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-app" >/dev/null; then
if ynh_hide_warnings yunohost service status "$app-app" >/dev/null; then
yunohost service remove "$app-app"
fi
if ynh_exec_warn_less yunohost service status "$app-worker" >/dev/null; then
if ynh_hide_warnings yunohost service status "$app-worker" >/dev/null; then
yunohost service remove "$app-worker"
fi

# Remove the dedicated systemd config
ynh_remove_systemd_config --service="$app-app"
ynh_remove_systemd_config --service="$app-worker"
ynh_config_remove_systemd"$app-app"
ynh_config_remove_systemd"$app-worker"

# Remove the dedicated NGINX config
ynh_remove_nginx_config
ynh_config_remove_nginx

ynh_remove_ruby
ynh_ruby_remove

ynh_remove_nodejs
ynh_nodejs_remove

#=================================================
# END OF SCRIPT
#=================================================

ynh_script_progression --message="Removal of $app completed" --last
ynh_script_progression "Removal of $app completed"
Loading