diff --git a/conf/cron b/conf/cron index a435084..e242fb6 100644 --- a/conf/cron +++ b/conf/cron @@ -1,2 +1,2 @@ RAILS_ENV=production -@daily cd __FINAL__PATH__/live && /opt/rbenv/versions/2.6.6/bin/bundle exec rake __USER__:media:remove_remote +@daily cd __FINAL__PATH__/live && __RBENVROOT__/bin/bundle exec rake __USER__:media:remove_remote diff --git a/conf/mastodon-sidekiq.service b/conf/mastodon-sidekiq.service index 1085e1f..73f29e5 100644 --- a/conf/mastodon-sidekiq.service +++ b/conf/mastodon-sidekiq.service @@ -9,7 +9,7 @@ Environment="RAILS_ENV=production" Environment="DB_POOL=25" Environment="MALLOC_ARENA_MAX=2" - ExecStart=/opt/rbenv/versions/2.6.6/bin/bundle exec sidekiq -c 25 + ExecStart=__RBENVROOT__/shims/bundle exec sidekiq -c 25 TimeoutSec=15 Restart=always StandardError=syslog diff --git a/conf/mastodon-web.service b/conf/mastodon-web.service index 234320f..14d1260 100644 --- a/conf/mastodon-web.service +++ b/conf/mastodon-web.service @@ -8,7 +8,7 @@ WorkingDirectory=__FINALPATH__/live Environment="RAILS_ENV=production" Environment="PORT=__PORT_WEB__" - ExecStart=/opt/rbenv/versions/2.6.6/bin/bundle exec puma -C config/puma.rb + ExecStart=__RBENVROOT__/shims/bundle exec puma -C config/puma.rb ExecReload=/bin/kill -SIGUSR1 $MAINPID TimeoutSec=15 Restart=always diff --git a/scripts/_common.sh b/scripts/_common.sh index 015c1e9..acb1435 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -6,6 +6,7 @@ # dependencies used by the app pkg_dependencies="imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git-core g++ libprotobuf-dev protobuf-compiler pkg-config gcc autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3|libgdbm6 libgdbm-dev redis-server redis-tools postgresql postgresql-contrib libidn11-dev libicu-dev libjemalloc-dev curl apt-transport-https" +RUBY_VERSION="2.6.6" #================================================= # PERSONAL HELPERS diff --git a/scripts/install b/scripts/install index 5fca585..dff019a 100644 --- a/scripts/install +++ b/scripts/install @@ -146,13 +146,11 @@ ynh_script_progression --message="Adding $swap_needed Mo to swap..." --weight=1 ynh_add_swap --size=$swap_needed #================================================= -# INSTALLING RUBY AND BUNDLER +# INSTALLING RUBY #================================================= ynh_script_progression --message="Installing Ruby..." --weight=424 -ynh_install_ruby --ruby_version=2.6.6 -/opt/rbenv/versions/2.6.6/bin/gem update --system -/opt/rbenv/versions/2.6.6/bin/gem install bundler:1.17.3 --no-document +ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= # MODIFY A CONFIG FILE @@ -190,12 +188,17 @@ chown -R "$app": "$final_path" pushd "$final_path/live" ynh_use_nodejs - sudo -u "$app" env PATH=$PATH /opt/rbenv/versions/2.6.6/bin/bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test + gem update --system + gem install bundler --no-document + + sudo -u "$app" env PATH=$PATH bundle config set deployment 'true' + sudo -u "$app" env PATH=$PATH bundle config set without 'development test' + sudo -u "$app" env PATH=$PATH bundle install -j$(getconf _NPROCESSORS_ONLN) sudo -u "$app" env PATH=$PATH yarn install --pure-lockfile sudo -u "$app" echo "SAFETY_ASSURED=1">> .env.production - sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.6/bin/bundle exec rails db:setup --quiet - sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.6/bin/bundle exec rails assets:precompile --quiet - sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.6/bin/bundle exec rake mastodon:webpush:generate_vapid_key > key.txt + sudo -u "$app" env PATH=$PATH RAILS_ENV=production bundle exec rails db:setup --quiet + sudo -u "$app" env PATH=$PATH RAILS_ENV=production bundle exec rails assets:precompile --quiet + sudo -u "$app" env PATH=$PATH RAILS_ENV=production bundle exec rake mastodon:webpush:generate_vapid_key > key.txt sudo -u "$app" env PATH=$PATH RAILS_ENV=production bin/tootctl accounts create "$admin" --email="$admin_mail" --confirmed --role=admin > acc.txt popd @@ -219,6 +222,7 @@ ynh_secure_remove --file="$final_path/live/key.txt" ynh_script_progression --message="Setuping a cron job for removing cache..." --weight=1 ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="../conf/cron" +ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/cron" ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/cron" sudo cp -f ../conf/cron /etc/cron.d/$app @@ -229,6 +233,8 @@ ynh_script_progression --message="Configuring a systemd service..." --weight=5 # Create a dedicated systemd config ynh_replace_string --match_string="__PORT_WEB__" --replace_string="$port_web" --target_file="../conf/mastodon-web.service" +ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/mastodon-web.service" +ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/mastodon-sidekiq.service" ynh_replace_string --match_string="__PORT_STREAM__" --replace_string="$port_stream" --target_file="../conf/mastodon-streaming.service" ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="../conf/mastodon-streaming.service" ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" diff --git a/scripts/restore b/scripts/restore index 81c242e..201af24 100644 --- a/scripts/restore +++ b/scripts/restore @@ -110,13 +110,11 @@ ynh_install_app_dependencies $pkg_dependencies ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" #================================================= -# INSTALLING RUBY AND BUNDLER +# INSTALLING RUBY #================================================= ynh_script_progression --message="Installing Ruby..." --weight=393 -ynh_install_ruby --ruby_version=2.6.6 -/opt/rbenv/versions/2.6.6/bin/gem update --system -/opt/rbenv/versions/2.6.6/bin/gem install bundler:1.17.3 --no-document +ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= # RESTORE THE POSTGRESQL DATABASE diff --git a/scripts/upgrade b/scripts/upgrade index e24b610..a26133f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -240,13 +240,11 @@ ynh_script_progression --message="Adding $swap_needed Mo to swap..." --weight=1 ynh_add_swap --size=$swap_needed #================================================= -# INSTALLING RUBY AND BUNDLER +# INSTALLING RUBY #================================================= ynh_script_progression --message="Installing Ruby..." --weight=424 -ynh_install_ruby --ruby_version=2.6.6 -/opt/rbenv/versions/2.6.6/bin/gem update --system -/opt/rbenv/versions/2.6.6/bin/gem install bundler:1.17.3 --no-document +ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= # MODIFY A CONFIG FILE @@ -282,11 +280,15 @@ chown -R "$app": "$final_path" pushd "$final_path/live" ynh_use_nodejs - sudo -u "$app" env PATH=$PATH /opt/rbenv/versions/2.6.6/bin/bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test + gem update --system + gem install bundler --no-document + sudo -u "$app" env PATH=$PATH bundle config set deployment 'true' + sudo -u "$app" env PATH=$PATH bundle config set without 'development test' + sudo -u "$app" env PATH=$PATH bundle install -j$(getconf _NPROCESSORS_ONLN) sudo -u "$app" env PATH=$PATH yarn install --pure-lockfile - sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.6/bin/bundle exec rails assets:clean - sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.6/bin/bundle exec rails assets:precompile - sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.6/bin/bundle exec rails db:migrate + sudo -u "$app" env PATH=$PATH RAILS_ENV=production bundle exec rails assets:clean + sudo -u "$app" env PATH=$PATH RAILS_ENV=production bundle exec rails assets:precompile + sudo -u "$app" env PATH=$PATH RAILS_ENV=production bundle exec rails db:migrate sudo -u "$app" env PATH=$PATH RAILS_ENV=production bin/tootctl cache clear popd @@ -311,6 +313,7 @@ ynh_store_file_checksum --file="${final_path}/live/.env.production" ynh_script_progression --message="Setuping a cron job for removing cache..." --weight=1 ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="../conf/cron" +ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/cron" ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/cron" sudo cp -f ../conf/cron /etc/cron.d/$app @@ -321,6 +324,8 @@ ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 # Create a dedicated systemd config ynh_replace_string --match_string="__PORT_WEB__" --replace_string="$port_web" --target_file="../conf/mastodon-web.service" +ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/mastodon-web.service" +ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/mastodon-sidekiq.service" ynh_replace_string --match_string="__PORT_STREAM__" --replace_string="$port_stream" --target_file="../conf/mastodon-streaming.service" ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="../conf/mastodon-streaming.service" ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index b1e2efc..6df5fc4 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -94,7 +94,7 @@ ynh_install_ruby () { test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby # Install the requested version of ruby - CONFIGURE_OPTS="--disable-install-doc" MAKE_OPTS="-j2" rbenv install --skip-existing $ruby_version + CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $ruby_version # Store the ID of this app and the version of ruby requested for it echo "$YNH_APP_ID:$ruby_version" | tee --append "$rbenv_install_dir/ynh_app_version"