mirror of
https://github.com/YunoHost-Apps/gitlab_ynh.git
synced 2024-09-03 18:36:35 +02:00
203 lines
7.8 KiB
Bash
203 lines
7.8 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
#=================================================
|
|
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
|
|
|
config_path=/etc/$app
|
|
|
|
# Detect the system architecture
|
|
if [ -n "$(uname -m | grep arm64)" ] || [ -n "$(uname -m | grep aarch64)" ]; then
|
|
architecture="arm64"
|
|
elif [ -n "$(uname -m | grep x86_64)" ]; then
|
|
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
|
|
ynh_die --message="Unable to detect your achitecture, please open a bug describing \
|
|
your hardware and the result of the command \"uname -m\"." 1
|
|
fi
|
|
|
|
# Could be an option?
|
|
client_max_body_size="250m"
|
|
|
|
#=================================================
|
|
# STORE SETTINGS FROM MANIFEST
|
|
#=================================================
|
|
ynh_script_progression --message="Storing installation settings..." --weight=2
|
|
|
|
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
|
|
ynh_app_setting_set --app=$app --key=overwrite_nginx --value="1"
|
|
|
|
#=================================================
|
|
# STANDARD MODIFICATIONS
|
|
#=================================================
|
|
# DEFINE THE NUMBER OF WORKERS USED
|
|
#=================================================
|
|
|
|
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
|
|
|
|
# If the server has less than 2GB of RAM
|
|
if [ $(ynh_get_ram --total --ignore_swap) -lt 2048 ]; then
|
|
puma_min_threads=1
|
|
puma_max_threads=1
|
|
else
|
|
puma_min_threads=2
|
|
puma_max_threads=4
|
|
fi
|
|
|
|
ynh_app_setting_set --app=$app --key=puma_worker_processes --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
|
|
|
|
#=================================================
|
|
# ADD SWAP IF NEEDED
|
|
#=================================================
|
|
|
|
total_swap=$(ynh_get_ram --total --only_swap)
|
|
swap_needed=0
|
|
|
|
# https://docs.gitlab.com/ce/install/requirements.html#memory
|
|
# Need at least 2Go of swap
|
|
if [ $total_swap -lt 2048 ]; then
|
|
swap_needed=$((2048 - total_swap))
|
|
fi
|
|
|
|
if [ $swap_needed -gt 0 ]; then
|
|
ynh_script_progression --message="Adding $swap_needed Mo to swap..."
|
|
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
|
|
fi
|
|
|
|
#=================================================
|
|
# 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
|
|
|
|
#=================================================
|
|
# PRECONFIGURE GITLAB
|
|
#=================================================
|
|
ynh_script_progression --message="Preconfigure GitLab..." --weight=1
|
|
|
|
mkdir -p $config_path
|
|
|
|
touch "$config_path/gitlab-persistent.rb"
|
|
chown root:root "$config_path/gitlab-persistent.rb"
|
|
chmod 640 "$config_path/gitlab-persistent.rb"
|
|
|
|
ssh_port=$(grep -P "Port\s+\d+" /etc/ssh/sshd_config | grep -P -o "\d+")
|
|
|
|
generated_external_url="https://$domain${path%/}"
|
|
|
|
ynh_add_config --template="$YNH_APP_BASEDIR/conf/gitlab.rb" --destination="$config_path/gitlab.rb"
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up source files..." --weight=50
|
|
|
|
source $YNH_APP_BASEDIR/scripts/upgrade.d/upgrade.last.sh
|
|
ynh_add_config --template="$YNH_APP_BASEDIR/conf/$architecture.src.default" --destination="$YNH_APP_BASEDIR/conf/$architecture.src"
|
|
|
|
tempdir="$(mktemp -d)"
|
|
|
|
ynh_setup_source --dest_dir=$tempdir --source_id=$architecture
|
|
|
|
chmod 755 $install_dir
|
|
|
|
ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename
|
|
|
|
ynh_secure_remove --file="$tempdir"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config client_max_body_size
|
|
|
|
#=================================================
|
|
# SPECIFIC SETUP
|
|
#=================================================
|
|
# ADD USER AND CONFIGURE SIGN IN SYSTEM
|
|
#=================================================
|
|
ynh_script_progression --message="Creating an administrator user..." --weight=13
|
|
|
|
mailadmin=$(ynh_user_get_info --username=$admin --key=mail)
|
|
rdmPass=$(ynh_string_random --length=30)
|
|
|
|
echo "newuser = User.new({ \"email\"=>'$mailadmin', \"username\"=>'$admin', \"name\"=>'$admin', \"password\"=>'$rdmPass'})
|
|
newuser.admin = true
|
|
newuser.confirmed_at = Time.now
|
|
newuser.confirmation_token = nil
|
|
newuser.save
|
|
ApplicationSetting.last.update(password_authentication_enabled_for_web: $use_web_account, signup_enabled: $use_web_account)" | gitlab-rails console
|
|
|
|
#=================================================
|
|
# RECONFIGURE TO TAKE INTO ACCOUNT CHANGES
|
|
#=================================================
|
|
ynh_script_progression --message="Reconfigure GitLab..." --weight=13
|
|
|
|
ynh_exec_warn_less gitlab-ctl reconfigure
|
|
|
|
# Allow ssh for git
|
|
usermod -a -G "ssh.app" "git"
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
#=================================================
|
|
|
|
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"
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
|
|
ynh_systemd_action --action=reload --service_name=nginx
|
|
|
|
#=================================================
|
|
# RESTART GITLAB
|
|
#=================================================
|
|
ynh_script_progression --message="Restarting GitLab..." --weight=15
|
|
|
|
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:$port_puma" --timeout=300
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installation of GitLab completed" --last
|