1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/gitlab_ynh.git synced 2024-09-03 18:36:35 +02:00
gitlab_ynh/scripts/install

267 lines
10 KiB
Text
Raw Normal View History

2017-06-10 10:10:31 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
2018-12-19 00:02:20 +01:00
#=================================================
2019-03-16 02:38:12 +01:00
source _common.sh
source /usr/share/yunohost/helpers
2019-03-16 02:38:12 +01:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
2019-05-09 01:13:48 +02:00
ynh_exec_warn_less ynh_secure_remove --file="$tempdir"
2019-03-16 02:38:12 +01:00
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2018-12-19 00:02:20 +01:00
#=================================================
2019-03-16 02:38:12 +01:00
# RETRIEVE ARGUMENTS FROM THE MANIFEST
2018-12-19 00:02:20 +01:00
#=================================================
2017-06-10 10:10:31 +02:00
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC
use_web_account=$YNH_APP_ARG_USE_WEB_ACCOUNT
2017-06-28 15:41:05 +02:00
admin=$YNH_APP_ARG_ADMIN
2017-06-10 10:10:31 +02:00
2019-03-16 02:38:12 +01:00
app=$YNH_APP_INSTANCE_NAME
2018-12-19 00:02:20 +01:00
#=================================================
2019-03-16 02:38:12 +01:00
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
2018-12-19 00:02:20 +01:00
#=================================================
2019-05-09 09:03:19 +02:00
ynh_script_progression --message="Validating installation parameters..." --weight=1
2018-12-19 00:02:20 +01:00
2019-03-16 02:38:12 +01:00
config_path=/etc/$app
final_path=/opt/$app
2019-05-09 01:13:48 +02:00
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
2018-12-19 00:02:20 +01:00
2019-03-16 02:38:12 +01:00
# Detect the system architecture
2021-03-29 11:46:48 +02:00
if [ -n "$(uname -m | grep arm64)" ] || [ -n "$(uname -m | grep aarch64)" ]; then
architecture="arm64"
2020-08-27 12:33:33 +02:00
elif [ -n "$(uname -m | grep x86_64)" ]; then
2019-03-16 02:38:12 +01:00
architecture="x86-64"
elif [ -n "$(uname -m | grep 86)" ]; then
ynh_die "Gitlab is not compatible with x86 architecture"
elif [ -n "$(uname -m | grep arm)" ]; then
architecture="arm"
else
2019-05-09 01:13:48 +02:00
ynh_die --message="Unable to detect your achitecture, please open a bug describing \
2019-03-16 02:38:12 +01:00
your hardware and the result of the command \"uname -m\"." 1
fi
2017-06-10 10:10:31 +02:00
2019-03-29 22:18:08 +01:00
# Could be an option?
client_max_body_size="250m"
2019-03-16 02:38:12 +01:00
# Register (book) web path
2019-05-09 01:13:48 +02:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2017-06-10 10:10:31 +02:00
2018-12-19 00:02:20 +01:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2019-05-09 09:03:19 +02:00
ynh_script_progression --message="Storing installation settings..." --weight=2
2017-06-28 15:41:05 +02:00
2019-05-09 01:13:48 +02:00
ynh_app_setting_set --app=$app --key=admin --value=$admin
2019-05-13 15:54:26 +02:00
ynh_app_setting_set --app=$app --key=path --value=$path_url
2019-05-09 01:13:48 +02:00
ynh_app_setting_set --app=$app --key=use_web_account --value=$use_web_account
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
ynh_app_setting_set --app=$app --key=config_path --value=$config_path
ynh_app_setting_set --app=$app --key=architecture --value=$architecture
ynh_app_setting_set --app=$app --key=client_max_body_size --value=$client_max_body_size
2018-12-19 00:02:20 +01:00
2019-05-09 01:13:48 +02:00
ynh_app_setting_set --app=$app --key=overwrite_nginx --value="1"
2019-04-11 01:11:54 +02:00
2018-12-19 00:02:20 +01:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
2019-04-04 12:37:49 +02:00
# FIND A PORT
2018-12-19 00:02:20 +01:00
#=================================================
2019-05-09 09:03:19 +02:00
ynh_script_progression --message="Find internal port..." --weight=1
2019-01-26 14:30:58 +01:00
2018-12-19 00:02:20 +01:00
# Find free ports
2019-05-09 01:13:48 +02:00
port=$(ynh_find_port --port=8080)
2021-05-28 16:13:02 +02:00
puma_port=$(ynh_find_port --port=$(($port + 1)))
2021-05-30 16:45:36 +02:00
sidekiq_port=$(ynh_find_port --port=$(($puma_port + 1)))
2018-12-19 00:02:20 +01:00
2019-05-09 01:13:48 +02:00
ynh_app_setting_set --app=$app --key=web_port --value=$port
2021-05-28 16:13:02 +02:00
ynh_app_setting_set --app=$app --key=puma_port --value=$puma_port
ynh_app_setting_set --app=$app --key=sidekiq_port --value=$sidekiq_port
2017-06-10 10:10:31 +02:00
#=================================================
2019-03-16 02:38:12 +01:00
# INSTALL DEPENDENCIES
#=================================================
2019-05-09 09:03:19 +02:00
ynh_script_progression --message="Installing dependencies..." --weight=5
2017-06-10 10:10:31 +02:00
2019-03-16 02:38:12 +01:00
ynh_install_app_dependencies $pkg_dependencies
2017-06-10 10:35:32 +02:00
2019-09-03 21:18:42 +02:00
#=================================================
# DEFINE THE NUMBER OF WORKERS USED
#=================================================
2021-02-23 13:52:33 +01:00
total_memory=$(ynh_get_ram --total)
if [ $total_memory -lt 4096 ]; then
#https://docs.gitlab.com/omnibus/settings/puma.html#running-in-memory-constrained-environments
puma_worker_processes=0
else
#https://docs.gitlab.com/ce/install/requirements.html#puma-workers
puma_worker_processes=$(( $(nproc) > 2 ? $(($(nproc) - 1)) : 2 ))
fi
2019-09-03 21:18:42 +02:00
2020-06-23 12:34:19 +02:00
# If the server has less than 2GB of RAM
2021-02-23 13:52:33 +01:00
if [ $(ynh_get_ram --total --ignore_swap) -lt 2048 ]; then
2020-05-23 01:04:34 +02:00
puma_min_threads=1
puma_max_threads=1
2019-09-03 21:18:42 +02:00
else
2020-05-23 01:04:34 +02:00
puma_min_threads=2
puma_max_threads=4
2019-09-03 21:18:42 +02:00
fi
2020-05-23 01:04:34 +02:00
ynh_app_setting_set --app=$app --key=puma_workers --value=$puma_worker_processes
ynh_app_setting_set --app=$app --key=puma_max_threads --value=$puma_max_threads
ynh_app_setting_set --app=$app --key=puma_min_threads --value=$puma_min_threads
2019-09-03 21:18:42 +02:00
2019-05-06 21:17:27 +02:00
#=================================================
# ADD SWAP IF NEEDED
#=================================================
2020-05-02 14:16:08 +02:00
total_swap=$(ynh_get_ram --total --only_swap)
2019-05-06 21:17:27 +02:00
swap_needed=0
2019-08-23 21:44:38 +02:00
# https://docs.gitlab.com/ce/install/requirements.html#memory
2019-05-07 00:37:07 +02:00
# Need at least 2Go of swap
2021-02-23 13:52:33 +01:00
if [ $total_swap -lt 2048 ]; then
swap_needed=$((2048 - total_swap))
2019-05-06 21:17:27 +02:00
fi
2020-05-23 01:04:34 +02:00
if [ $swap_needed -gt 0 ]; then
ynh_script_progression --message="Adding $swap_needed Mo to swap..."
2021-05-15 15:33:14 +02:00
if ! ynh_add_swap --size=$swap_needed; then
ynh_print_warn --message="Please add $swap_needed Mo to swap to make Gitlab work properly"
fi
2020-05-23 01:04:34 +02:00
fi
2019-05-06 21:17:27 +02:00
#=================================================
# CHECK IF KERNEL IS READ-ONLY
#=================================================
modify_kernel_parameters="true"
for value_to_check in "kernel.shmall" "kernel.shmmax" "kernel.sem" "net.core.somaxconn"
do
if ! ynh_exec_fully_quiet sysctl --write $value_to_check="$(sysctl --value $value_to_check)"; then
modify_kernel_parameters="false"
break
fi
done
2018-12-19 00:02:20 +01:00
#=================================================
2019-03-16 02:38:12 +01:00
# PRECONFIGURE GITLAB
2018-12-19 00:02:20 +01:00
#=================================================
2020-12-23 17:08:21 +01:00
ynh_script_progression --message="Preconfigure GitLab..." --weight=1
2019-03-16 02:38:12 +01:00
mkdir -p $config_path
2019-04-16 00:01:12 +02:00
touch "$config_path/gitlab-persistent.rb"
2021-05-31 16:00:54 +02:00
chown root:root "$config_path/gitlab-persistent.rb"
chmod 640 "$config_path/gitlab-persistent.rb"
2019-04-16 00:01:12 +02:00
2019-04-04 10:37:10 +02:00
ssh_port=$(grep -P "Port\s+\d+" /etc/ssh/sshd_config | grep -P -o "\d+")
2017-06-10 10:10:31 +02:00
2021-05-28 16:13:02 +02:00
generated_external_url="https://$domain${path_url%/}"
ynh_add_config --template="$YNH_APP_BASEDIR/conf/gitlab.rb" --destination="$config_path/gitlab.rb"
2017-06-28 15:41:05 +02:00
2018-12-19 00:02:20 +01:00
#=================================================
2019-03-16 02:38:12 +01:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2018-12-19 00:02:20 +01:00
#=================================================
2020-12-23 17:08:21 +01:00
ynh_script_progression --message="Setting up source files..." --weight=50
2019-03-16 02:38:12 +01:00
2021-05-15 17:05:49 +02:00
source $YNH_APP_BASEDIR/scripts/upgrade.d/upgrade.last.sh
2021-05-28 16:13:02 +02:00
ynh_add_config --template="$YNH_APP_BASEDIR/conf/$architecture.src.default" --destination="$YNH_APP_BASEDIR/conf/$architecture.src"
2019-03-16 02:38:12 +01:00
tempdir="$(mktemp -d)"
2017-06-28 15:41:05 +02:00
2019-05-09 01:13:48 +02:00
ynh_setup_source --dest_dir=$tempdir --source_id=$architecture
2019-03-16 02:38:12 +01:00
ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename
2019-03-16 02:38:12 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-12-23 17:08:21 +01:00
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
2019-03-16 02:38:12 +01:00
2020-12-23 17:08:21 +01:00
# Create a dedicated NGINX config
2019-04-01 20:59:30 +02:00
ynh_add_nginx_config client_max_body_size
2017-06-28 15:41:05 +02:00
2018-12-19 00:02:20 +01:00
#=================================================
# SPECIFIC SETUP
#=================================================
2019-03-16 02:38:12 +01:00
# ADD USER AND CONFIGURE SIGN IN SYSTEM
2018-12-19 00:02:20 +01:00
#=================================================
2019-05-09 09:03:19 +02:00
ynh_script_progression --message="Creating an administrator user..." --weight=13
2019-01-26 14:30:58 +01:00
2019-05-09 01:13:48 +02:00
mailadmin=$(ynh_user_get_info --username=$admin --key=mail)
rdmPass=$(ynh_string_random --length=30)
2018-12-19 00:02:20 +01:00
2017-06-28 16:28:20 +02:00
echo "newuser = User.new({ \"email\"=>'$mailadmin', \"username\"=>'$admin', \"name\"=>'$admin', \"password\"=>'$rdmPass'})
2017-06-28 15:41:05 +02:00
newuser.admin = true
newuser.confirmed_at = Time.now
newuser.confirmation_token = nil
newuser.save
2021-09-15 16:35:23 +02:00
ApplicationSetting.last.update(password_authentication_enabled_for_web: $use_web_account, signup_enabled: $use_web_account)" | gitlab-rails console
2017-06-28 15:41:05 +02:00
2018-12-19 00:02:20 +01:00
#=================================================
2019-03-16 02:38:12 +01:00
# RECONFIGURE TO TAKE INTO ACCOUNT CHANGES
2018-12-19 00:02:20 +01:00
#=================================================
2020-12-23 17:08:21 +01:00
ynh_script_progression --message="Reconfigure GitLab..." --weight=13
2018-12-19 00:02:20 +01:00
2023-05-24 17:54:17 +02:00
ynh_exec_warn_less gitlab-ctl reconfigure
2017-06-10 10:10:31 +02:00
2021-05-15 11:00:03 +02:00
# Allow ssh for git
usermod -a -G "ssh.app" "git"
2019-03-16 02:38:12 +01:00
#=================================================
# GENERIC FINALIZATION
2019-03-24 21:36:20 +01:00
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
2020-05-23 01:04:34 +02:00
yunohost service add "gitlab-runsvdir" --log "/var/log/$app/gitlab-rails/application.log" "/var/log/$app/gitlab-rails/api_json.log" "/var/log/$app/gitlab-rails/production.log" "/var/log/$app/gitlab-rails/production_json.log" "/var/log/$app/gitlab-rails/sidekiq.log" "/var/log/$app/puma/puma_stderr.log" "/var/log/$app/puma/current" "/var/log/$app/alertmanager/current" "/var/log/$app/gitaly/current" "/var/log/$app/gitlab-monitor/current" "/var/log/$app/gitlab-shell/gitlab-shell.log" "/var/log/$app/gitlab-workhorse/current" "/var/log/$app/logrotate/current" "/var/log/$app/nginx/current" "/var/log/$app/nginx/access.log" "/var/log/$app/nginx/error.log" "/var/log/$app/nginx/gitlab_access.log" "/var/log/$app/nginx/gitlab_error.log" "/var/log/$app/node-exporter/current" "/var/log/$app/postgres-exporter/current" "/var/log/$app/postgresql/current" "/var/log/$app/prometheus/current" "/var/log/$app/redis/current" "/var/log/$app/redis-exporter/current"
2019-03-24 21:36:20 +01:00
2018-12-19 00:02:20 +01:00
#=================================================
# SETUP SSOWAT
#=================================================
2019-05-09 09:03:19 +02:00
ynh_script_progression --message="Configuring SSOwat..." --weight=1
2018-12-19 00:02:20 +01:00
2019-03-16 02:38:12 +01:00
# Make app public if necessary
if [ $is_public -eq 1 ]; then
2021-01-28 01:07:33 +01:00
ynh_permission_update --permission="main" --add="visitors"
2017-06-10 10:10:31 +02:00
fi
2018-12-19 00:02:20 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2020-12-23 17:08:21 +01:00
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
2018-12-19 00:02:20 +01:00
2019-03-16 02:38:12 +01:00
ynh_systemd_action --action=reload --service_name=nginx
2018-12-19 00:02:20 +01:00
#=================================================
# RESTART GITLAB
#=================================================
2020-12-23 17:08:21 +01:00
ynh_script_progression --message="Restarting GitLab..." --weight=15
2021-05-28 16:13:02 +02:00
ynh_systemd_action --action=restart --service_name="gitlab-runsvdir" --log_path="/var/log/$app/puma/current" --line_match="Listening on http://127.0.0.1:$puma_port" --timeout=300
2018-12-19 00:02:20 +01:00
#=================================================
2019-03-16 02:38:12 +01:00
# END OF SCRIPT
2018-12-19 00:02:20 +01:00
#=================================================
2020-12-23 17:18:58 +01:00
ynh_script_progression --message="Installation of GitLab completed" --last