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

Merge pull request #51 from YunoHost-Apps/testing

Testing
This commit is contained in:
Kayou 2019-05-12 13:52:18 +02:00 committed by GitHub
commit c54370932e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 462 additions and 380 deletions

View file

@ -46,6 +46,7 @@ Yes with LDAP support.
* Report a bug: https://github.com/YunoHost-Apps/gitlab_ynh/issues
* App website: https://gitlab.com
* Upstream app repository: https://gitlab.com/gitlab-org/omnibus-gitlab - https://gitlab.com/gitlab-org/gitlab-ce
* YunoHost website: https://yunohost.org/
---

View file

@ -21,16 +21,7 @@
port_already_use=1 (8080)
change_url=1
;;; Levels
Level 1=auto
Level 2=auto
Level 3=auto
Level 4=auto
Level 5=auto
Level 6=auto
Level 7=auto
Level 8=auto
Level 9=0
Level 10=0
;;; Options
Email=
Notification=none

View file

@ -28,13 +28,6 @@
"id": "overwrite_nginx",
"type": "bool",
"default": true
},
{
"name": "Overwrite the gitlab.rb config file ?",
"help": "If the file is overwritten, a backup will be created.",
"id": "overwrite_gitlab_config",
"type": "bool",
"default": true
}
]
},

View file

@ -2,7 +2,7 @@
"name": "Gitlab",
"id": "gitlab",
"packaging_format": 1,
"version": "11.10.4~ynh1",
"version": "11.10.4~ynh2",
"description": {
"en": "GitLab is a Git-repository manager.",
"fr": "GitLab est un gestionnaire de dépôts Git."
@ -14,7 +14,7 @@
"email": "pierre@kayou.io"
},
"requirements": {
"yunohost": ">> 3.3.0"
"yunohost": ">= 3.5.0"
},
"multi_instance": false,
"services": [

View file

@ -6,14 +6,6 @@
pkg_dependencies="openssh-server"
#=================================================
# PACKAGE CHECK BYPASSING...
#=================================================
IS_PACKAGE_CHECK () {
return $(env | grep -c container=lxc)
}
#=================================================
# BOOLEAN CONVERTER
#=================================================
@ -33,110 +25,165 @@ bool_to_true_false () {
}
#=================================================
# WAIT
# EXPERIMENTAL HELPERS
#=================================================
# Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started
#
# usage: ynh_systemd_action [-n service_name] [-a action] [ [-l "line to match"] [-p log_path] [-t timeout] [-e length] ]
# | arg: -n, --service_name= - Name of the service to start. Default : $app
# | arg: -a, --action= - Action to perform with systemctl. Default: start
# | arg: -l, --line_match= - Line to match - The line to find in the log to attest the service have finished to boot.
# If not defined it don't wait until the service is completely started.
# WARNING: When using --line_match, you should always add `ynh_clean_check_starting` into your
# `ynh_clean_setup` at the beginning of the script. Otherwise, tail will not stop in case of failure
# of the script. The script will then hang forever.
# | arg: -p, --log_path= - Log file - Path to the log file. Default : /var/log/$app/$app.log
# | arg: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Default : 300 seconds.
# | arg: -e, --length= - Length of the error log : Default : 20
ynh_systemd_action() {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [n]=service_name= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length= )
local service_name
local action
local line_match
local length
local log_path
local timeout
# Add swap
#
# usage: ynh_add_swap --size=SWAP in Mb
# | arg: -s, --size= - Amount of SWAP to add in Mb.
ynh_add_swap () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [s]=size= )
local size
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
local service_name="${service_name:-$app}"
local action=${action:-start}
local log_path="${log_path:-/var/log/$service_name/$service_name.log}"
local length=${length:-20}
local timeout=${timeout:-300}
local swap_max_size=$(( $size * 1024 ))
# Start to read the log
if [[ -n "${line_match:-}" ]]
local free_space=$(df --output=avail / | sed 1d)
# Because we don't want to fill the disk with a swap file, divide by 2 the available space.
local usable_space=$(( $free_space / 2 ))
SD_CARD_CAN_SWAP=${SD_CARD_CAN_SWAP:-0}
# Swap on SD card only if it's is specified
if ynh_is_main_device_a_sd_card && [ "$SD_CARD_CAN_SWAP" == "0" ]
then
local templog="$(mktemp)"
# Following the starting of the app in its log
if [ "$log_path" == "systemd" ] ; then
# Read the systemd journal
journalctl --unit=$service_name --follow --since=-0 --quiet > "$templog" &
# Get the PID of the journalctl command
local pid_tail=$!
ynh_print_warn --message="The main mountpoint of your system '/' is on an SD card, swap will not be added to prevent some damage of this one, but that can cause troubles for the app $app. If you still want activate the swap, you can relaunch the command preceded by 'SD_CARD_CAN_SWAP=1'"
return
fi
# Compare the available space with the size of the swap.
# And set a acceptable size from the request
if [ $usable_space -ge $swap_max_size ]
then
local swap_size=$swap_max_size
elif [ $usable_space -ge $(( $swap_max_size / 2 )) ]
then
local swap_size=$(( $swap_max_size / 2 ))
elif [ $usable_space -ge $(( $swap_max_size / 3 )) ]
then
local swap_size=$(( $swap_max_size / 3 ))
elif [ $usable_space -ge $(( $swap_max_size / 4 )) ]
then
local swap_size=$(( $swap_max_size / 4 ))
else
# Read the specified log file
tail -F -n0 "$log_path" > "$templog" 2>&1 &
# Get the PID of the tail command
local pid_tail=$!
fi
echo "Not enough space left for a swap file" >&2
local swap_size=0
fi
ynh_print_info --message="${action^} the service $service_name"
# Use reload-or-restart instead of reload. So it wouldn't fail if the service isn't running.
if [ "$action" == "reload" ]; then
action="reload-or-restart"
fi
systemctl $action $service_name \
|| ( journalctl --no-pager --lines=$length -u $service_name >&2 \
; test -e "$log_path" && echo "--" >&2 && tail --lines=$length "$log_path" >&2 \
; false )
# Start the timeout and try to find line_match
if [[ -n "${line_match:-}" ]]
# If there's enough space for a swap, and no existing swap here
if [ $swap_size -ne 0 ] && [ ! -e /swap_$app ]
then
local i=0
for i in $(seq 1 $timeout)
do
# Read the log until the sentence is found, that means the app finished to start. Or run until the timeout
if grep --quiet "$line_match" "$templog"
then
ynh_print_info --message="The service $service_name has correctly started."
break
fi
if [ $i -eq 3 ]; then
echo -n "Please wait, the service $service_name is ${action}ing" >&2
fi
if [ $i -ge 3 ]; then
echo -n "." >&2
fi
sleep 1
done
if [ $i -ge 3 ]; then
echo "" >&2
fi
if [ $i -eq $timeout ]
then
ynh_print_warn --message="The service $service_name didn't fully started before the timeout."
ynh_print_warn --message="Please find here an extract of the end of the log of the service $service_name:"
journalctl --no-pager --lines=$length -u $service_name >&2
test -e "$log_path" && echo "--" >&2 && tail --lines=$length "$log_path" >&2
fi
ynh_clean_check_starting
# Preallocate space for the swap file
fallocate -l ${swap_size}K /swap_$app
chmod 0600 /swap_$app
# Create the swap
mkswap /swap_$app
# And activate it
swapon /swap_$app
# Then add an entry in fstab to load this swap at each boot.
echo -e "/swap_$app swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab
fi
}
# Clean temporary process and file used by ynh_check_starting
# (usually used in ynh_clean_setup scripts)
ynh_del_swap () {
# If there a swap at this place
if [ -e /swap_$app ]
then
# Clean the fstab
sed -i "/#Swap added by $app/d" /etc/fstab
# Desactive the swap file
swapoff /swap_$app
# And remove it
rm /swap_$app
fi
}
# Check if the device of the main mountpoint "/" is an SD card
#
# usage: ynh_clean_check_starting
ynh_clean_check_starting () {
# Stop the execution of tail.
kill -s 15 $pid_tail 2>&1
ynh_secure_remove "$templog" 2>&1
# [internal]
#
# return 0 if it's an SD card, else 1
ynh_is_main_device_a_sd_card () {
local main_device=$(lsblk --output PKNAME --noheadings $(findmnt / --nofsroot --uniq --output source --noheadings --first-only))
if echo $main_device | grep --quiet "mmc" && [ $(tail -n1 /sys/block/$main_device/queue/rotational) == "0" ]
then
return 0
else
return 1
fi
}
# Check the amount of available RAM
#
# usage: ynh_check_ram [--required=RAM required in Mb] [--no_swap|--only_swap] [--free_ram]
# | arg: -r, --required= - Amount of RAM required in Mb. The helper will return 0 is there's enough RAM, or 1 otherwise.
# If --required isn't set, the helper will print the amount of RAM, in Mb.
# | arg: -s, --no_swap - Ignore swap
# | arg: -o, --only_swap - Ignore real RAM, consider only swap.
# | arg: -f, --free_ram - Count only free RAM, not the total amount of RAM available.
ynh_check_ram () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [r]=required= [s]=no_swap [o]=only_swap [f]=free_ram )
local required
local no_swap
local only_swap
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
required=${required:-}
no_swap=${no_swap:-0}
only_swap=${only_swap:-0}
local total_ram=$(vmstat --stats --unit M | grep "total memory" | awk '{print $1}')
local total_swap=$(vmstat --stats --unit M | grep "total swap" | awk '{print $1}')
local total_ram_swap=$(( total_ram + total_swap ))
local free_ram=$(vmstat --stats --unit M | grep "free memory" | awk '{print $1}')
local free_swap=$(vmstat --stats --unit M | grep "free swap" | awk '{print $1}')
local free_ram_swap=$(( free_ram + free_swap ))
# Use the total amount of ram
local ram=$total_ram_swap
if [ $free_ram -eq 1 ]
then
# Use the total amount of free ram
ram=$free_ram_swap
if [ $no_swap -eq 1 ]
then
# Use only the amount of free ram
ram=$free_ram
elif [ $only_swap -eq 1 ]
then
# Use only the amount of free swap
ram=$free_swap
fi
else
if [ $no_swap -eq 1 ]
then
# Use only the amount of free ram
ram=$total_ram
elif [ $only_swap -eq 1 ]
then
# Use only the amount of free swap
ram=$total_swap
fi
fi
if [ -n "$required" ]
then
# Return 1 if the amount of ram isn't enough.
if [ $ram -lt $required ]
then
return 1
else
return 0
fi
# If no RAM is required, return the amount of available ram.
else
echo $ram
fi
}

View file

@ -26,7 +26,7 @@ app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
# CHECK IF AN ACTION HAS TO BE DONE
#=================================================
is_public_old=$(ynh_app_setting_get $app is_public)
is_public_old=$(ynh_app_setting_get --app=$app --key=is_public)
if [ $is_public -eq $is_public_old ]
then
@ -43,27 +43,27 @@ if [ $is_public -eq 0 ]; then
else
public_private="public"
fi
ynh_print_info --message="Moving the application to $public_private..."
ynh_script_progression --message=--message="Moving the application to $public_private..." --weight=1
# Make app public if necessary
if [ $is_public -eq 0 ]; then
ynh_app_setting_delete $app unprotected_uris
else
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set $app unprotected_uris "/"
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
fi
ynh_print_info --message="Reconfiguring SSOwat..."
ynh_script_progression --message=--message="Reconfiguring SSOwat..." --weight=1
# Regen ssowat configuration
yunohost app ssowatconf
# Update the config of the app
ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
#=================================================
# RELOAD NGINX
#=================================================
ynh_print_info --message="Reloading nginx web server..."
ynh_script_progression --message=--message="Reloading nginx web server..." --weight=1
ynh_systemd_action --action=reload --service_name=nginx
@ -71,4 +71,4 @@ ynh_systemd_action --action=reload --service_name=nginx
# END OF SCRIPT
#=================================================
ynh_print_info --message="Execution completed"
ynh_script_progression --message="Execution completed" --last

View file

@ -26,7 +26,7 @@ app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
# CHECK IF AN ACTION HAS TO BE DONE
#=================================================
use_web_account_old=$(ynh_app_setting_get $app use_web_account)
use_web_account_old=$(ynh_app_setting_get --app=$app --key=use_web_account)
if [ $use_web_account -eq $use_web_account_old ]
then
@ -43,15 +43,15 @@ if [ $use_web_account -eq 0 ]; then
else
web_account="Disable"
fi
ynh_print_info --message="$web_account web user creation..."
ynh_script_progression --message=--message="$web_account web user creation..." --weight=13
echo "ApplicationSetting.last.update_attributes(password_authentication_enabled_for_web: $use_web_account, signup_enabled: $use_web_account)" | gitlab-rails console
# Update the config of the app
ynh_app_setting_set $app use_web_account $use_web_account
ynh_app_setting_set --app=$app --key=use_web_account --value=$use_web_account
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Execution completed"
ynh_script_progression --message="Execution completed" --last

View file

@ -24,48 +24,48 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading installation settings..."
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
config_path=$(ynh_app_setting_get $app config_path)
domain=$(ynh_app_setting_get $app domain)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
config_path=$(ynh_app_setting_get --app=$app --key=config_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_print_info "Backing up nginx web server configuration..."
ynh_script_progression --message="Backing up nginx web server configuration..." --weight=1
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP GITLAB DATABASE
#=================================================
ynh_print_info "Backuping of Gitlab..."
ynh_script_progression --message="Backuping of Gitlab..." --weight=9
# Use gitlab-rake to backup
gitlab-rake gitlab:backup:create > backup.log
# Searching in backup logs the
# Searching in backup logs the name of the backup archive created
last_backup=$(grep _gitlab_backup.tar backup.log | cut -d' ' -f4)
mv "/var/opt/$app/backups/$last_backup" "/var/opt/$app/backups/last_gitlab_backup.tar"
ynh_backup "/var/opt/$app/backups/last_gitlab_backup.tar"
ynh_backup --src_path="/var/opt/$app/backups/last_gitlab_backup.tar"
#=================================================
# BACKUP CONF FILES
#=================================================
ynh_print_info "Backuping configuration files of Gitlab..."
ynh_script_progression --message="Backuping configuration files of Gitlab..." --weight=1
ynh_backup "$config_path/gitlab-secrets.json"
ynh_backup "$config_path/gitlab.rb"
ynh_backup "$config_path/gitlab-persistent.rb"
ynh_backup --src_path="$config_path/gitlab-secrets.json"
ynh_backup --src_path="$config_path/gitlab.rb"
ynh_backup --src_path="$config_path/gitlab-persistent.rb"
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last

View file

@ -24,25 +24,16 @@ app=$YNH_APP_INSTANCE_NAME
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading installation settings..."
ynh_script_progression --message="Loading installation settings..." --weight=1
# Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get $app final_path)
config_path=$(ynh_app_setting_get $app config_path)
port=$(ynh_app_setting_get "$app" web_port)
portUnicorn=$(ynh_app_setting_get "$app" unicorn_port)
portSidekiq=$(ynh_app_setting_get "$app" sidekiq_port)
unicorn_worker_processes=$(ynh_app_setting_get "$app" unicorn_worker_processes)
client_max_body_size=$(ynh_app_setting_get "$app" client_max_body_size)
#=================================================
# CHECK THE SYNTAX OF THE PATHS
#=================================================
test -n "$old_path" || old_path="/"
test -n "$new_path" || new_path="/"
new_path=$(ynh_normalize_url_path $new_path)
old_path=$(ynh_normalize_url_path $old_path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
config_path=$(ynh_app_setting_get --app=$app --key=config_path)
port=$(ynh_app_setting_get --app="$app" --key=web_port)
portUnicorn=$(ynh_app_setting_get --app="$app" --key=unicorn_port)
portSidekiq=$(ynh_app_setting_get --app="$app" --key=sidekiq_port)
unicorn_worker_processes=$(ynh_app_setting_get --app="$app" --key=unicorn_worker_processes)
client_max_body_size=$(ynh_app_setting_get --app="$app" --key=client_max_body_size)
#=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED
@ -63,12 +54,12 @@ fi
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_print_info "Updating nginx web server configuration..."
ynh_script_progression --message="Updating nginx web server configuration..." --weight=1
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
if [ $change_path -eq 1 ]; then
ynh_print_info "Changing path..."
ynh_script_progression --message="Changing path..." --weight=4
#doc in: https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
@ -76,7 +67,7 @@ if [ $change_path -eq 1 ]; then
gitlab-ctl stop sidekiq
# Make a backup of the original nginx config file if modified
ynh_backup_if_checksum_is_different "$nginx_conf_path"
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for nginx helper
domain="$old_domain"
path_url="$new_path"
@ -86,13 +77,13 @@ fi
# Change the domain for nginx
if [ $change_domain -eq 1 ]; then
ynh_print_info "Changing domain..."
ynh_script_progression --message="Changing domain..." --weight=4
# Delete file checksum for the old conf file location
ynh_delete_file_checksum "$nginx_conf_path"
ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
#=================================================
@ -100,9 +91,9 @@ fi
#=================================================
# CONFIGURE GITLAB
#=================================================
ynh_print_info "Configure gitlab..."
ynh_script_progression --message="Configure gitlab..." --weight=28
ynh_backup_if_checksum_is_different "$config_path/gitlab.rb"
ynh_backup_if_checksum_is_different --file="$config_path/gitlab.rb"
mkdir -p $config_path
@ -112,15 +103,15 @@ ssh_port=$(grep -P "Port\s+\d+" /etc/ssh/sshd_config | grep -P -o "\d+")
domain="$new_domain"
path_url="$new_path"
ynh_replace_string "__GENERATED_EXTERNAL_URL__" "https://$domain${path_url%/}" "$config_path/gitlab.rb"
ynh_replace_string "__PORT__" "$port" "$config_path/gitlab.rb"
ynh_replace_string "__UNICORN_PORT__" "$portUnicorn" "$config_path/gitlab.rb"
ynh_replace_string "__UNICORN_WORKER_PROCESSES__" "$unicorn_worker_processes" "$config_path/gitlab.rb"
ynh_replace_string "__CLIENT_MAX_BODY_SIZE__" "$client_max_body_size" "$config_path/gitlab.rb"
ynh_replace_string "__SSH_PORT__" "$ssh_port" "$config_path/gitlab.rb"
ynh_replace_string "__SIDEKIQ_PORT__" "$portSidekiq" "$config_path/gitlab.rb"
ynh_replace_string --match_string="__GENERATED_EXTERNAL_URL__" --replace_string="https://$domain${path_url%/}" --target_file="$config_path/gitlab.rb"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_path/gitlab.rb"
ynh_replace_string --match_string="__UNICORN_PORT__" --replace_string="$portUnicorn" --target_file="$config_path/gitlab.rb"
ynh_replace_string --match_string="__UNICORN_WORKER_PROCESSES__" --replace_string="$unicorn_worker_processes" --target_file="$config_path/gitlab.rb"
ynh_replace_string --match_string="__CLIENT_MAX_BODY_SIZE__" --replace_string="$client_max_body_size" --target_file="$config_path/gitlab.rb"
ynh_replace_string --match_string="__SSH_PORT__" --replace_string="$ssh_port" --target_file="$config_path/gitlab.rb"
ynh_replace_string --match_string="__SIDEKIQ_PORT__" --replace_string="$portSidekiq" --target_file="$config_path/gitlab.rb"
ynh_store_file_checksum "$config_path/gitlab.rb"
ynh_store_file_checksum --file="$config_path/gitlab.rb"
#=================================================
# RECONFIGURE GITLAB
@ -136,7 +127,7 @@ fi
#=================================================
# WAITING GITLAB
#=================================================
ynh_print_info "Waiting for gitlab..."
ynh_script_progression --message="Waiting for gitlab..." --weight=15
# Action status to just wait the service
ynh_systemd_action --action=status --service_name="gitlab-runsvdir" --log_path="/var/log/$app/unicorn/current" --line_match="adopted" --timeout=3600
@ -146,7 +137,7 @@ ynh_systemd_action --action=status --service_name="gitlab-runsvdir" --log_path="
#=================================================
# RELOAD NGINX
#=================================================
ynh_print_info "Reloading nginx web server..."
ynh_script_progression --message="Reloading nginx web server..." --weight=1
ynh_systemd_action --action=reload --service_name=nginx
@ -154,4 +145,4 @@ ynh_systemd_action --action=reload --service_name=nginx
# END OF SCRIPT
#=================================================
ynh_print_info "Change of URL completed for $app"
ynh_script_progression --message="Change of URL completed for $app" --last

View file

@ -26,22 +26,17 @@ app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
# Otherwise, keep the value from the app config.
# is_public
old_is_public="$(ynh_app_setting_get $app is_public)"
old_is_public="$(ynh_app_setting_get --app=$app --key=is_public)"
old_is_public=$(bool_to_true_false $old_is_public)
is_public="${YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC:-$old_is_public}"
# Overwrite nginx configuration
old_overwrite_nginx="$(ynh_app_setting_get $app overwrite_nginx)"
old_overwrite_nginx="$(ynh_app_setting_get --app=$app --key=overwrite_nginx)"
old_overwrite_nginx=$(bool_to_true_false $old_overwrite_nginx)
overwrite_nginx="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX:-$old_overwrite_nginx}"
# Overwrite gitlab.rb configuration
old_overwrite_gitlab_config="$(ynh_app_setting_get $app overwrite_gitlab_config)"
old_overwrite_gitlab_config=$(bool_to_true_false $old_overwrite_gitlab_config)
overwrite_gitlab_config="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_GITLAB_CONFIG:-$old_overwrite_gitlab_config}"
# use_web_account
old_use_web_account="$(ynh_app_setting_get $app use_web_account)"
old_use_web_account="$(ynh_app_setting_get --app=$app --key=use_web_account)"
old_use_web_account=$(bool_to_true_false $old_use_web_account)
use_web_account="${YNH_CONFIG_MAIN_USERS_USE_WEB_ACCOUNT:-$old_use_web_account}"
@ -56,7 +51,6 @@ show_config() {
echo "YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC=$is_public"
echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx"
echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_GITLAB_CONFIG=$overwrite_gitlab_config"
echo "YNH_CONFIG_MAIN_USERS_USE_WEB_ACCOUNT=$use_web_account"
}
@ -83,9 +77,7 @@ apply_config() {
fi
# Set overwrite_nginx
ynh_app_setting_set $app overwrite_nginx "$overwrite_nginx"
# Set overwrite_gitlab_config
ynh_app_setting_set $app overwrite_gitlab_config "$overwrite_gitlab_config"
ynh_app_setting_set --app=$app --key=overwrite_nginx --value="$overwrite_nginx"
}
#=================================================

View file

@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers
#=================================================
ynh_clean_setup () {
ynh_secure_remove "$tempdir" 2>&1
ynh_exec_warn_less ynh_secure_remove --file="$tempdir"
ynh_clean_check_starting
}
@ -36,11 +36,11 @@ app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_print_info "Validating installation parameters..."
ynh_script_progression --message="Validating installation parameters..." --weight=1
config_path=/etc/$app
final_path=/opt/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Detect the system architecture
if [ -n "$(uname -m | grep 64)" ]; then
@ -50,7 +50,7 @@ elif [ -n "$(uname -m | grep 86)" ]; then
elif [ -n "$(uname -m | grep arm)" ]; then
architecture="arm"
else
ynh_die "Unable to detect your achitecture, please open a bug describing \
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
@ -58,7 +58,7 @@ fi
unicorn_worker_processes=$(($(nproc) + 1 ))
# If the server has at least 2GB of RAM
if [ $(free -g --si | grep Mem: | awk '{print $2}') -ge 2 ]; then
if [ $(ynh_check_ram --no_swap) -ge 2000 ]; then
# Min 3 worker processes
unicorn_worker_processes=$(($unicorn_worker_processes>3?$unicorn_worker_processes:3))
else
@ -69,56 +69,75 @@ fi
# Could be an option?
client_max_body_size="250m"
path_url=$(ynh_normalize_url_path $path_url)
# Register (book) web path
ynh_webpath_register $app $domain $path_url
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_print_info "Storing installation settings..."
ynh_script_progression --message="Storing installation settings..." --weight=2
ynh_app_setting_set $app admin $admin
ynh_app_setting_set $app path_url $path_url
ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set $app use_web_account $use_web_account
ynh_app_setting_set $app final_path $final_path
ynh_app_setting_set $app config_path $config_path
ynh_app_setting_set $app architecture $architecture
ynh_app_setting_set $app unicorn_worker_processes $unicorn_worker_processes
ynh_app_setting_set $app client_max_body_size $client_max_body_size
ynh_app_setting_set --app=$app --key=admin --value=$admin
ynh_app_setting_set --app=$app --key=path_url --value=$path_url
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
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=unicorn_worker_processes --value=$unicorn_worker_processes
ynh_app_setting_set --app=$app --key=client_max_body_size --value=$client_max_body_size
ynh_app_setting_set $app overwrite_nginx "1"
ynh_app_setting_set $app overwrite_gitlab_config "1"
ynh_app_setting_set --app=$app --key=overwrite_nginx --value="1"
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND A PORT
#=================================================
ynh_print_info "Find internal port..."
ynh_script_progression --message="Find internal port..." --weight=1
# Find free ports
port=$(ynh_find_port 8080)
portUnicorn=$(ynh_find_port $(($port + 1)))
portSidekiq=$(ynh_find_port $(($portUnicorn + 1)))
port=$(ynh_find_port --port=8080)
portUnicorn=$(ynh_find_port --port=$(($port + 1)))
portSidekiq=$(ynh_find_port --port=$(($portUnicorn + 1)))
ynh_app_setting_set $app web_port $port
ynh_app_setting_set $app unicorn_port $portUnicorn
ynh_app_setting_set $app sidekiq_port $portSidekiq
ynh_app_setting_set --app=$app --key=web_port --value=$port
ynh_app_setting_set --app=$app --key=unicorn_port --value=$portUnicorn
ynh_app_setting_set --app=$app --key=sidekiq_port --value=$portSidekiq
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_print_info "Installing dependencies..."
ynh_script_progression --message="Installing dependencies..." --weight=5
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# ADD SWAP IF NEEDED
#=================================================
total_memory=$(ynh_check_ram)
total_swap=$(ynh_check_ram --only_swap)
swap_needed=0
# https://docs.gitlab.com/ee/install/requirements.html#memory
if [ $total_memory -lt 8192 ]; then
# Need a minimum of 8Go of memory
swap_needed=$((8192 - $total_memory))
fi
# Need at least 2Go of swap
if [ $(($total_swap + $swap_needed)) -lt 2048 ]; then
swap_needed=$((2048 - $total_swap))
fi
ynh_script_progression --message="Adding $swap_needed Mo to swap..." --weight=1
ynh_add_swap --size=$swap_needed
#=================================================
# PRECONFIGURE GITLAB
#=================================================
ynh_print_info "Preconfigure gitlab..."
ynh_script_progression --message="Preconfigure gitlab..." --weight=1
mkdir -p $config_path
@ -128,35 +147,35 @@ chown admin: "$config_path/gitlab-persistent.rb"
cp -f ../conf/gitlab.rb "$config_path/gitlab.rb"
ssh_port=$(grep -P "Port\s+\d+" /etc/ssh/sshd_config | grep -P -o "\d+")
ynh_replace_string "__GENERATED_EXTERNAL_URL__" "https://$domain${path_url%/}" "$config_path/gitlab.rb"
ynh_replace_string "__PORT__" "$port" "$config_path/gitlab.rb"
ynh_replace_string "__UNICORN_PORT__" "$portUnicorn" "$config_path/gitlab.rb"
ynh_replace_string "__UNICORN_WORKER_PROCESSES__" "$unicorn_worker_processes" "$config_path/gitlab.rb"
ynh_replace_string "__CLIENT_MAX_BODY_SIZE__" "$client_max_body_size" "$config_path/gitlab.rb"
ynh_replace_string "__SSH_PORT__" "$ssh_port" "$config_path/gitlab.rb"
ynh_replace_string "__SIDEKIQ_PORT__" "$portSidekiq" "$config_path/gitlab.rb"
ynh_replace_string --match_string="__GENERATED_EXTERNAL_URL__" --replace_string="https://$domain${path_url%/}" --target_file="$config_path/gitlab.rb"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_path/gitlab.rb"
ynh_replace_string --match_string="__UNICORN_PORT__" --replace_string="$portUnicorn" --target_file="$config_path/gitlab.rb"
ynh_replace_string --match_string="__UNICORN_WORKER_PROCESSES__" --replace_string="$unicorn_worker_processes" --target_file="$config_path/gitlab.rb"
ynh_replace_string --match_string="__CLIENT_MAX_BODY_SIZE__" --replace_string="$client_max_body_size" --target_file="$config_path/gitlab.rb"
ynh_replace_string --match_string="__SSH_PORT__" --replace_string="$ssh_port" --target_file="$config_path/gitlab.rb"
ynh_replace_string --match_string="__SIDEKIQ_PORT__" --replace_string="$portSidekiq" --target_file="$config_path/gitlab.rb"
#=================================================
# STORE THE CONFIG FILE CHECKSUM
#=================================================
ynh_store_file_checksum "$config_path/gitlab.rb"
ynh_store_file_checksum --file="$config_path/gitlab.rb"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_print_info "Setting up source files..."
ynh_script_progression --message="Setting up source files..." --weight=200
update_src_version() {
source ./upgrade.d/upgrade.last.sh
cp ../conf/$architecture.src.default ../conf/$architecture.src
ynh_replace_string "__VERSION__" "$gitlab_version" "../conf/$architecture.src"
ynh_replace_string "__SOURCE_FILENAME__" "$gitlab_filename" "../conf/$architecture.src"
ynh_replace_string --match_string="__VERSION__" --replace_string="$gitlab_version" --target_file="../conf/$architecture.src"
ynh_replace_string --match_string="__SOURCE_FILENAME__" --replace_string="$gitlab_filename" --target_file="../conf/$architecture.src"
if [ $architecture = "x86-64" ]; then
ynh_replace_string "__SHA256_SUM__" "$gitlab_x86_64_source_sha256" "../conf/$architecture.src"
ynh_replace_string --match_string="__SHA256_SUM__" --replace_string="$gitlab_x86_64_source_sha256" --target_file="../conf/$architecture.src"
elif [ $architecture = "arm" ]; then
ynh_replace_string "__SHA256_SUM__" "$gitlab_arm_source_sha256" "../conf/$architecture.src"
ynh_replace_string --match_string="__SHA256_SUM__" --replace_string="$gitlab_arm_source_sha256" --target_file="../conf/$architecture.src"
fi
}
@ -164,21 +183,21 @@ update_src_version
tempdir="$(mktemp -d)"
ynh_setup_source $tempdir $architecture
ynh_setup_source --dest_dir=$tempdir --source_id=$architecture
if IS_PACKAGE_CHECK; then
if ! dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env
ynh_replace_string "command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"" "command \"cat \/etc\/sysctl.conf\"" "$final_path/embedded/cookbooks/package/resources/sysctl.rb"
dpkg --configure gitlab-ce
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then
if ! ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env
ynh_replace_string --match_string="command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"" --replace_string="command \"cat \/etc\/sysctl.conf\"" --target_file="$final_path/embedded/cookbooks/package/resources/sysctl.rb"
ynh_exec_warn_less dpkg --configure gitlab-ce
fi
else
dpkg -i $tempdir/$gitlab_filename
ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename
fi
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_print_info "Configuring nginx web server..."
ynh_script_progression --message="Configuring nginx web server..." --weight=2
# Create a dedicated nginx config
ynh_add_nginx_config client_max_body_size
@ -188,10 +207,10 @@ ynh_add_nginx_config client_max_body_size
#=================================================
# ADD USER AND CONFIGURE SIGN IN SYSTEM
#=================================================
ynh_print_info "Creating an administrator user..."
ynh_script_progression --message="Creating an administrator user..." --weight=13
mailadmin=$(ynh_user_get_info $admin mail)
rdmPass=$(ynh_string_random 30)
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
@ -203,7 +222,7 @@ ApplicationSetting.last.update_attributes(password_authentication_enabled_for_we
#=================================================
# RECONFIGURE TO TAKE INTO ACCOUNT CHANGES
#=================================================
ynh_print_info "Reconfigure gitlab..."
ynh_script_progression --message="Reconfigure gitlab..." --weight=13
gitlab-ctl reconfigure
@ -218,18 +237,18 @@ yunohost service add "gitlab-runsvdir" --log "/var/log/$app/gitlab-rails/applica
#=================================================
# SETUP SSOWAT
#=================================================
ynh_print_info "Configuring SSOwat..."
ynh_script_progression --message="Configuring SSOwat..." --weight=1
# Make app public if necessary
if [ $is_public -eq 1 ]; then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set $app unprotected_uris "/"
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
fi
#=================================================
# RELOAD NGINX
#=================================================
ynh_print_info "Reloading nginx web server..."
ynh_script_progression --message="Reloading nginx web server..." --weight=1
ynh_systemd_action --action=reload --service_name=nginx
@ -237,4 +256,4 @@ ynh_systemd_action --action=reload --service_name=nginx
# END OF SCRIPT
#=================================================
ynh_print_info "Installation of $app completed"
ynh_script_progression --message="Installation of $app completed" --last

View file

@ -12,15 +12,15 @@ source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading installation settings..."
ynh_script_progression --message="Loading installation settings..." --weight=2
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain)
port=$(ynh_app_setting_get "$app" web_port)
portUnicorn=$(ynh_app_setting_get "$app" unicorn_port)
final_path=$(ynh_app_setting_get $app final_path)
config_path=$(ynh_app_setting_get $app config_path)
domain=$(ynh_app_setting_get --app="$app" --key=domain)
port=$(ynh_app_setting_get --app="$app" --key=web_port)
portUnicorn=$(ynh_app_setting_get --app="$app" --key=unicorn_port)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
config_path=$(ynh_app_setting_get --app=$app --key=config_path)
#=================================================
# STANDARD REMOVE
@ -30,28 +30,28 @@ config_path=$(ynh_app_setting_get $app config_path)
if yunohost service status "gitlab-runsvdir" >/dev/null 2>&1
then
ynh_print_info "Removing $app service"
ynh_script_progression --message="Removing $app service" --weight=1
yunohost service remove "gitlab-runsvdir"
fi
#=================================================
# STOP GITLAB
#=================================================
ynh_print_info "Stopping gitlab"
ynh_script_progression --message="Stopping gitlab" --weight=8
gitlab-ctl stop
#=================================================
# REMOVE GITLAB
#=================================================
ynh_print_info "Removing Gitlab"
ynh_script_progression --message="Removing Gitlab" --weight=4
dpkg --remove gitlab-ce
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_print_info "Removing dependencies"
ynh_script_progression --message="Removing dependencies" --weight=3
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
@ -59,16 +59,16 @@ ynh_remove_app_dependencies
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_print_info "Removing app main directory"
ynh_script_progression --message="Removing app main directory" --weight=1
# Remove the app directory securely
ynh_secure_remove "$final_path"
ynh_secure_remove "$config_path"
ynh_secure_remove --file="$final_path"
ynh_secure_remove --file="$config_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_print_info "Removing nginx web server configuration"
ynh_script_progression --message="Removing nginx web server configuration" --weight=1
# Remove the dedicated nginx config
ynh_remove_nginx_config
@ -79,12 +79,12 @@ ynh_remove_nginx_config
# These ports are no longer open but were in previous versions
if yunohost firewall list | grep -q "\- $port$"; then
ynh_print_info "Closing port $port"
ynh_script_progression --message="Closing port $port" --weight=1
ynh_exec_warn_less yunohost firewall disallow TCP $port
fi
if yunohost firewall list | grep -q "\- $portUnicorn$"; then
ynh_print_info "Closing port $portUnicorn"
ynh_script_progression --message="Closing port $portUnicorn" --weight=1
ynh_exec_warn_less yunohost firewall disallow TCP $portUnicorn
fi
@ -94,13 +94,17 @@ fi
# REMOVE GITLAB FILES
#=================================================
ynh_secure_remove "/var/opt/$app"
ynh_secure_remove --file="/var/opt/$app"
# Remove the log files
ynh_secure_remove "/var/log/$app"
ynh_secure_remove --file="/var/log/$app"
# Remove swap
ynh_del_swap
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Removal of $app completed"
ynh_script_progression --message="Removal of $app completed" --last

View file

@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers
#=================================================
ynh_clean_setup () {
ynh_secure_remove "$tempdir" 2>&1
ynh_exec_warn_less ynh_secure_remove --file="$tempdir"
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -23,27 +23,27 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading settings..."
ynh_script_progression --message="Loading settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
config_path=$(ynh_app_setting_get $app config_path)
port=$(ynh_app_setting_get "$app" web_port)
portUnicorn=$(ynh_app_setting_get "$app" unicorn_port)
architecture=$(ynh_app_setting_get "$app" architecture)
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
config_path=$(ynh_app_setting_get --app=$app --key=config_path)
port=$(ynh_app_setting_get --app="$app" --key=web_port)
portUnicorn=$(ynh_app_setting_get --app="$app" --key=unicorn_port)
architecture=$(ynh_app_setting_get --app="$app" --key=architecture)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_print_info "Validating restoration parameters..."
ynh_script_progression --message="Validating restoration parameters..." --weight=1
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
@ -51,41 +51,63 @@ test ! -d $final_path \
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_print_info "Reinstalling dependencies..."
ynh_script_progression --message="Reinstalling dependencies..." --weight=5
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# ADD SWAP IF NEEDED
#=================================================
total_memory=$(ynh_check_ram)
total_swap=$(ynh_check_ram --only_swap)
swap_needed=0
# https://docs.gitlab.com/ee/install/requirements.html#memory
if [ $total_memory -lt 8192 ]; then
# Need a minimum of 8Go of memory
swap_needed=$((8192 - $total_memory))
fi
# Need at least 2Go of swap
if [ $(($total_swap + $swap_needed)) -lt 2048 ]; then
swap_needed=$((2048 - $total_swap))
fi
ynh_script_progression --message="Adding $swap_needed Mo to swap..." --weight=1
ynh_add_swap --size=$swap_needed
#=================================================
# RESTORE CONF FILES
#=================================================
ynh_print_info "Restoring configuration files of Gitlab..."
ynh_script_progression --message="Restoring configuration files of Gitlab..." --weight=1
ynh_restore_file "$config_path/gitlab-secrets.json"
ynh_restore_file "$config_path/gitlab.rb"
ynh_restore_file "$config_path/gitlab-persistent.rb"
ynh_restore_file --origin_path="$config_path/gitlab-secrets.json"
ynh_restore_file --origin_path="$config_path/gitlab.rb"
ynh_restore_file --origin_path="$config_path/gitlab-persistent.rb"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_print_info "Reinstalling gitlab..."
ynh_script_progression --message="Reinstalling gitlab..." --weight=200
update_src_version() {
source ../settings/scripts/upgrade.d/upgrade.last.sh
mkdir -p ../conf/
cp ../settings/conf/$architecture.src.default ../conf/$architecture.src
ynh_replace_string "__VERSION__" "$gitlab_version" "../conf/$architecture.src"
ynh_replace_string "__SOURCE_FILENAME__" "$gitlab_filename" "../conf/$architecture.src"
ynh_replace_string --match_string="__VERSION__" --replace_string="$gitlab_version" --target_file="../conf/$architecture.src"
ynh_replace_string --match_string="__SOURCE_FILENAME__" --replace_string="$gitlab_filename" --target_file="../conf/$architecture.src"
if [ $architecture = "x86-64" ]; then
ynh_replace_string "__SHA256_SUM__" "$gitlab_x86_64_source_sha256" "../conf/$architecture.src"
ynh_replace_string --match_string="__SHA256_SUM__" --replace_string="$gitlab_x86_64_source_sha256" --target_file="../conf/$architecture.src"
elif [ $architecture = "arm" ]; then
ynh_replace_string "__SHA256_SUM__" "$gitlab_arm_source_sha256" "../conf/$architecture.src"
ynh_replace_string --match_string="__SHA256_SUM__" --replace_string="$gitlab_arm_source_sha256" --target_file="../conf/$architecture.src"
fi
}
@ -93,15 +115,15 @@ update_src_version
tempdir="$(mktemp -d)"
ynh_setup_source $tempdir $architecture
ynh_setup_source --dest_dir=$tempdir --source_id=$architecture
if IS_PACKAGE_CHECK; then
if ! dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env
ynh_replace_string "command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"" "command \"cat \/etc\/sysctl.conf\"" "$final_path/embedded/cookbooks/package/resources/sysctl.rb"
dpkg --configure gitlab-ce
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then
if ! ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env
ynh_replace_string --match_string="command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"" --replace_string="command \"cat \/etc\/sysctl.conf\"" --target_file="$final_path/embedded/cookbooks/package/resources/sysctl.rb"
ynh_exec_warn_less dpkg --configure gitlab-ce
fi
else
dpkg -i $tempdir/$gitlab_filename
ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename
fi
#=================================================
@ -109,9 +131,9 @@ fi
#=================================================
# RESTORE GITLAB DATABASE
#=================================================
ynh_print_info "Restoring Gitlab..."
ynh_script_progression --message="Restoring Gitlab..." --weight=55
ynh_restore_file "/var/opt/$app/backups/last_gitlab_backup.tar"
ynh_restore_file --origin_path="/var/opt/$app/backups/last_gitlab_backup.tar"
last_backup="last"
@ -134,14 +156,14 @@ yunohost service add "gitlab-runsvdir" --log "/var/log/$app/gitlab-rails/applica
#=================================================
# WAITING GITLAB
#=================================================
ynh_print_info "Waiting for gitlab..."
ynh_script_progression --message="Waiting for gitlab..." --weight=14
ynh_systemd_action --action=restart --service_name="gitlab-runsvdir" --log_path="/var/log/$app/unicorn/current" --line_match="adopted" --timeout=3600
#=================================================
# RELOAD NGINX
#=================================================
ynh_print_info "Reloading nginx web server..."
ynh_script_progression --message="Reloading nginx web server..." --weight=1
ynh_systemd_action --action=reload --service_name=nginx
@ -149,4 +171,4 @@ ynh_systemd_action --action=reload --service_name=nginx
# END OF SCRIPT
#=================================================
ynh_print_info "Restoration completed for $app"
ynh_script_progression --message="Restoration completed for $app" --last

View file

@ -19,20 +19,25 @@ source ./_common.sh
app=$YNH_APP_INSTANCE_NAME
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
path_url=$(ynh_app_setting_get "$app" path_url)
admin=$(ynh_app_setting_get "$app" admin)
is_public=$(ynh_app_setting_get "$app" is_public)
final_path=$(ynh_app_setting_get $app final_path)
config_path=$(ynh_app_setting_get $app config_path)
port=$(ynh_app_setting_get "$app" web_port)
portUnicorn=$(ynh_app_setting_get "$app" unicorn_port)
portSidekiq=$(ynh_app_setting_get "$app" sidekiq_port)
architecture=$(ynh_app_setting_get "$app" architecture)
unicorn_worker_processes=$(ynh_app_setting_get "$app" unicorn_worker_processes)
client_max_body_size=$(ynh_app_setting_get "$app" client_max_body_size)
overwrite_nginx=$(ynh_app_setting_get "$app" overwrite_nginx)
overwrite_gitlab_config=$(ynh_app_setting_get "$app" overwrite_gitlab_config)
domain=$(ynh_app_setting_get --app="$app" --key=domain)
path_url=$(ynh_app_setting_get --app="$app" --key=path_url)
admin=$(ynh_app_setting_get --app="$app" --key=admin)
is_public=$(ynh_app_setting_get --app="$app" --key=is_public)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
config_path=$(ynh_app_setting_get --app=$app --key=config_path)
port=$(ynh_app_setting_get --app="$app" --key=web_port)
portUnicorn=$(ynh_app_setting_get --app="$app" --key=unicorn_port)
portSidekiq=$(ynh_app_setting_get --app="$app" --key=sidekiq_port)
architecture=$(ynh_app_setting_get --app="$app" --key=architecture)
unicorn_worker_processes=$(ynh_app_setting_get --app="$app" --key=unicorn_worker_processes)
client_max_body_size=$(ynh_app_setting_get --app="$app" --key=client_max_body_size)
overwrite_nginx=$(ynh_app_setting_get --app="$app" --key=overwrite_nginx)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
@ -40,23 +45,23 @@ overwrite_gitlab_config=$(ynh_app_setting_get "$app" overwrite_gitlab_config)
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1
ynh_app_setting_set --app=$app --key=is_public --value=1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set $app is_public 0
ynh_app_setting_set --app=$app --key=is_public --value=0
is_public=0
fi
# If final_path doesn't exist, create it
if [ -z "$final_path" ]; then
final_path=/opt/$app
ynh_app_setting_set $app final_path $final_path
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi
# If config_path doesn't exist, create it
if [ -z "$config_path" ]; then
config_path=/etc/$app
ynh_app_setting_set $app config_path $config_path
ynh_app_setting_set --app=$app --key=config_path --value=$config_path
fi
if [ -z "$unicorn_worker_processes" ]; then
@ -71,13 +76,13 @@ if [ -z "$unicorn_worker_processes" ]; then
# 2 worker processes
unicorn_worker_processes=2
fi
ynh_app_setting_set $app unicorn_worker_processes $unicorn_worker_processes
ynh_app_setting_set --app=$app --key=unicorn_worker_processes --value=$unicorn_worker_processes
fi
if [ -z "$portSidekiq" ]; then
portSidekiq=$(ynh_find_port $(($portUnicorn + 1)))
ynh_app_setting_set $app sidekiq_port $portSidekiq
ynh_app_setting_set --app=$app --key=sidekiq_port --value=$portSidekiq
fi
# If architecture doesn't exist, create it
@ -90,10 +95,10 @@ if [ -z "$architecture" ]; then
elif [ -n "$(uname -m | grep arm)" ]; then
architecture="arm"
else
ynh_die "Unable to detect your achitecture, please open a bug describing \
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
ynh_app_setting_set $app architecture $architecture
ynh_app_setting_set --app=$app --key=architecture --value=$architecture
fi
# If client_max_body_size doesn't exist, create it
@ -104,13 +109,7 @@ fi
# If overwrite_nginx doesn't exist, create it
if [ -z "$overwrite_nginx" ]; then
overwrite_nginx=1
ynh_app_setting_set $app overwrite_nginx $overwrite_nginx
fi
# If overwrite_gitlab_config doesn't exist, create it
if [ -z "$overwrite_gitlab_config" ]; then
overwrite_gitlab_config=1
ynh_app_setting_set $app overwrite_gitlab_config $overwrite_gitlab_config
ynh_app_setting_set --app=$app --key=overwrite_nginx --value=$overwrite_nginx
fi
# If domain doesn't exist, retrieve it
@ -119,42 +118,42 @@ if [ -z "$domain" ]; then
if [ ${domain: -1} == "'" ]; then # if the last char of $domain is ' remove it
domain=${domain:0:-1}
fi
ynh_app_setting_set $app domain $domain
ynh_app_setting_set --app=$app --key=domain --value=$domain
fi
# If path_url doesn't exist, retrieve it
if [ -z "$path_url" ]; then
path_url=$(grep "location" "/etc/nginx/conf.d/${domain}.d/gitlab.conf" | cut -d' ' -f2)
path_url=$(ynh_normalize_url_path $path_url)
ynh_app_setting_set $app path_url path_url
ynh_app_setting_set --app=$app --key=path_url --value=path_url
fi
# If port doesn't exist, retrieve it
if [ -z "$port" ]; then
port=$(grep -F "nginx['listen_port']" "/etc/gitlab/gitlab.rb" | cut -d' ' -f3)
ynh_app_setting_set $app web_port $port
ynh_app_setting_set --app=$app --key=web_port --value=$port
fi
# If port doesn't exist, retrieve it
if [ -z "$portUnicorn" ]; then
portUnicorn=$(grep -F "unicorn['port']" "/etc/gitlab/gitlab.rb" | cut -d' ' -f3)
ynh_app_setting_set $app unicorn_port $portUnicorn
ynh_app_setting_set --app=$app --key=unicorn_port --value=$portUnicorn
fi
# if this source file exist, remove it
if [ -e "/etc/apt/sources.list.d/gitlab-ce.list" ]; then
ynh_secure_remove "/etc/apt/sources.list.d/gitlab-ce.list"
ynh_secure_remove --file="/etc/apt/sources.list.d/gitlab-ce.list"
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_print_info "Backing up the app before upgrading (may take a while)..."
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=10
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_secure_remove "$tempdir" 2>&1
ynh_exec_warn_less ynh_secure_remove --file="$tempdir"
ynh_clean_check_starting
@ -176,36 +175,54 @@ path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_print_info "Installing dependencies..."
ynh_script_progression --message="Installing dependencies..." --weight=5
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# ADD SWAP IF NEEDED
#=================================================
total_memory=$(ynh_check_ram)
total_swap=$(ynh_check_ram --only_swap)
swap_needed=0
# https://docs.gitlab.com/ee/install/requirements.html#memory
if [ $total_memory -lt 8192 ]; then
# Need a minimum of 8Go of memory
swap_needed=$((8192 - $total_memory))
fi
# Need at least 2Go of swap
if [ $(($total_swap + $swap_needed)) -lt 2048 ]; then
swap_needed=$((2048 - $total_swap))
fi
ynh_script_progression --message="Adding $swap_needed Mo to swap..." --weight=1
ynh_add_swap --size=$swap_needed
#=================================================
# PRECONFIGURE GITLAB
#=================================================
# Overwrite the gitlab.rb configuration only if it's allowed
if [ $overwrite_gitlab_config -eq 1 ]
then
ynh_print_info "Preconfigure gitlab..."
ynh_script_progression --message="Preconfigure gitlab..." --weight=1
ynh_backup_if_checksum_is_different "$config_path/gitlab.rb"
ynh_backup_if_checksum_is_different --file="$config_path/gitlab.rb"
mkdir -p $config_path
mkdir -p $config_path
cp -f ../conf/gitlab.rb "$config_path/gitlab.rb"
ssh_port=$(grep -P "Port\s+\d+" /etc/ssh/sshd_config | grep -P -o "\d+")
cp -f ../conf/gitlab.rb "$config_path/gitlab.rb"
ssh_port=$(grep -P "Port\s+\d+" /etc/ssh/sshd_config | grep -P -o "\d+")
ynh_replace_string "__GENERATED_EXTERNAL_URL__" "https://$domain${path_url%/}" "$config_path/gitlab.rb"
ynh_replace_string "__PORT__" "$port" "$config_path/gitlab.rb"
ynh_replace_string "__UNICORN_PORT__" "$portUnicorn" "$config_path/gitlab.rb"
ynh_replace_string "__UNICORN_WORKER_PROCESSES__" "$unicorn_worker_processes" "$config_path/gitlab.rb"
ynh_replace_string "__CLIENT_MAX_BODY_SIZE__" "$client_max_body_size" "$config_path/gitlab.rb"
ynh_replace_string "__SSH_PORT__" "$ssh_port" "$config_path/gitlab.rb"
ynh_replace_string "__SIDEKIQ_PORT__" "$portSidekiq" "$config_path/gitlab.rb"
ynh_replace_string --match_string="__GENERATED_EXTERNAL_URL__" --replace_string="https://$domain${path_url%/}" --target_file="$config_path/gitlab.rb"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_path/gitlab.rb"
ynh_replace_string --match_string="__UNICORN_PORT__" --replace_string="$portUnicorn" --target_file="$config_path/gitlab.rb"
ynh_replace_string --match_string="__UNICORN_WORKER_PROCESSES__" --replace_string="$unicorn_worker_processes" --target_file="$config_path/gitlab.rb"
ynh_replace_string --match_string="__CLIENT_MAX_BODY_SIZE__" --replace_string="$client_max_body_size" --target_file="$config_path/gitlab.rb"
ynh_replace_string --match_string="__SSH_PORT__" --replace_string="$ssh_port" --target_file="$config_path/gitlab.rb"
ynh_replace_string --match_string="__SIDEKIQ_PORT__" --replace_string="$portSidekiq" --target_file="$config_path/gitlab.rb"
ynh_store_file_checksum "$config_path/gitlab.rb"
fi
ynh_store_file_checksum --file="$config_path/gitlab.rb"
touch "$config_path/gitlab-persistent.rb"
chown admin: "$config_path/gitlab-persistent.rb"
@ -213,34 +230,40 @@ chown admin: "$config_path/gitlab-persistent.rb"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_print_info "Setting up source files..."
update_src_version() {
source ./upgrade.d/upgrade.last.sh
cp ../conf/$architecture.src.default ../conf/$architecture.src
ynh_replace_string "__VERSION__" "$gitlab_version" "../conf/$architecture.src"
ynh_replace_string "__SOURCE_FILENAME__" "$gitlab_filename" "../conf/$architecture.src"
ynh_replace_string --match_string="__VERSION__" --replace_string="$gitlab_version" --target_file="../conf/$architecture.src"
ynh_replace_string --match_string="__SOURCE_FILENAME__" --replace_string="$gitlab_filename" --target_file="../conf/$architecture.src"
if [ $architecture = "x86-64" ]; then
ynh_replace_string "__SHA256_SUM__" "$gitlab_x86_64_source_sha256" "../conf/$architecture.src"
ynh_replace_string --match_string="__SHA256_SUM__" --replace_string="$gitlab_x86_64_source_sha256" --target_file="../conf/$architecture.src"
elif [ $architecture = "arm" ]; then
ynh_replace_string "__SHA256_SUM__" "$gitlab_arm_source_sha256" "../conf/$architecture.src"
ynh_replace_string --match_string="__SHA256_SUM__" --replace_string="$gitlab_arm_source_sha256" --target_file="../conf/$architecture.src"
fi
}
update_src_version
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Setting up source files..." --weight=200
tempdir="$(mktemp -d)"
update_src_version
ynh_setup_source $tempdir $architecture
tempdir="$(mktemp -d)"
if IS_PACKAGE_CHECK; then
if ! dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env
ynh_replace_string "command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"" "command \"cat \/etc\/sysctl.conf\"" "$final_path/embedded/cookbooks/package/resources/sysctl.rb"
dpkg --configure gitlab-ce
ynh_setup_source --dest_dir=$tempdir --source_id=$architecture
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then
if ! ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env
ynh_replace_string --match_string="command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"" --replace_string="command \"cat \/etc\/sysctl.conf\"" --target_file="$final_path/embedded/cookbooks/package/resources/sysctl.rb"
ynh_exec_warn_less dpkg --configure gitlab-ce
fi
else
dpkg -i $tempdir/$gitlab_filename
else
ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename
fi
ynh_exec_warn_less ynh_secure_remove --file="$tempdir"
fi
#=================================================
@ -250,7 +273,7 @@ fi
# Overwrite the nginx configuration only if it's allowed
if [ $overwrite_nginx -eq 1 ]
then
ynh_print_info "Configuring nginx web server..."
ynh_script_progression --message="Configuring nginx web server..." --weight=2
# Create a dedicated nginx config
ynh_add_nginx_config client_max_body_size
fi
@ -270,13 +293,13 @@ yunohost service add "gitlab-runsvdir" --log "/var/log/$app/gitlab-rails/applica
# If app is public, add url to SSOWat conf as skipped_uris
if [ $is_public -eq 1 ]; then
# See install script
ynh_app_setting_set "$app" unprotected_uris "/"
ynh_app_setting_set --app="$app" --key=unprotected_uris --value="/"
fi
#=================================================
# WAITING GITLAB
#=================================================
ynh_print_info "Waiting for gitlab..."
ynh_script_progression --message="Waiting for gitlab..." --weight=15
# Action status to just wait the service
ynh_systemd_action --action=status --service_name="gitlab-runsvdir" --log_path="/var/log/$app/unicorn/current" --line_match="adopted" --timeout=3600
@ -284,7 +307,7 @@ ynh_systemd_action --action=status --service_name="gitlab-runsvdir" --log_path="
#=================================================
# RELOAD NGINX
#=================================================
ynh_print_info "Reloading nginx web server..."
ynh_script_progression --message="Reloading nginx web server..." --weight=1
ynh_systemd_action --action=reload --service_name=nginx
@ -292,5 +315,4 @@ ynh_systemd_action --action=reload --service_name=nginx
# END OF SCRIPT
#=================================================
ynh_print_info "Upgrade of $app completed"
ynh_script_progression --message="Upgrade of $app completed"--last