1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/lstu_ynh.git synced 2024-09-03 19:36:12 +02:00

Merge pull request #19 from YunoHost-Apps/testing

Fixing old things
This commit is contained in:
Kayou 2019-02-05 23:52:03 +01:00 committed by GitHub
commit 910740418c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 121 additions and 17 deletions

View file

@ -5,7 +5,7 @@ Requires=network.target
After=network.target After=network.target
[Service] [Service]
Type=forking Type=simple
User=www-data User=www-data
RemainAfterExit=yes RemainAfterExit=yes
Restart=always Restart=always

View file

@ -2,9 +2,9 @@
"name": "Lstu", "name": "Lstu",
"id": "lstu", "id": "lstu",
"packaging_format": 1, "packaging_format": 1,
"version": "0.21-4~ynh1", "version": "0.21-4~ynh2",
"requirements": { "requirements": {
"yunohost": ">= 2.4" "yunohost": ">= 3.0"
}, },
"description": { "description": {
"en": "URL Shortener", "en": "URL Shortener",

View file

@ -5,3 +5,93 @@ CHECK_VAR () { # Verifies that the variable is not empty.
# $2 = Display text on error # $2 = Display text on error
test -n "$1" || (echo "$2" >&2 && false) test -n "$1" || (echo "$2" >&2 && false)
} }
# 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 reload. 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.
# | 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
# 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}
# Start to read the log
if [[ -n "${line_match:-}" ]]
then
local templog="$(mktemp)"
# Following the starting of the app in its log
if [ "$log_path" == "systemd" ] ; then
# Read the systemd journal
journalctl -u $service_name -f --since=-45 > "$templog" &
else
# Read the specified log file
tail -F -n0 "$log_path" > "$templog" &
fi
# Get the PID of the tail command
local pid_tail=$!
fi
echo "${action^} the service $service_name" >&2
systemctl $action $service_name \
|| ( journalctl --lines=$length -u $service_name >&2 \
; test -n "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2 \
; false )
# Start the timeout and try to find line_match
if [[ -n "${line_match:-}" ]]
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
echo "The service $service_name has correctly started." >&2
break
fi
echo -n "." >&2
sleep 1
done
if [ $i -eq $timeout ]
then
echo "The service $service_name didn't fully started before the timeout." >&2
echo "Please find here an extract of the end of the log of the service $service_name:"
journalctl --lines=$length -u $service_name >&2
test -n "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2
fi
echo ""
ynh_clean_check_starting
fi
}
# Clean temporary process and file used by ynh_check_starting
# (usually used in ynh_clean_setup scripts)
#
# 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
}

View file

@ -101,8 +101,6 @@ ynh_setup_source "$final_path"
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
### `ynh_add_nginx_config` will use the file conf/nginx.conf
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
@ -126,6 +124,7 @@ ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lstu.conf"
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lstu.conf" ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lstu.conf"
secret=$(ynh_string_random 24) secret=$(ynh_string_random 24)
ynh_app_setting_set $app secret $secret
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf" ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf"
ynh_store_file_checksum "${final_path}/lstu.conf" ynh_store_file_checksum "${final_path}/lstu.conf"
@ -184,11 +183,11 @@ sudo chown -R www-data $final_path
#================================================= #=================================================
systemctl enable $app.service systemctl enable $app.service
systemctl start $app ynh_systemd_action -n $app -a start -l "Server available at" -p "systemd"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
# Reload Nginx # Reload Nginx
sudo service nginx reload systemctl reload nginx

View file

@ -42,6 +42,13 @@ test ! -d $final_path \
#================================================= #=================================================
# STANDARD RESTORATION STEPS # STANDARD RESTORATION STEPS
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
# Define and install dependencies
ynh_install_app_dependencies build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql
#================================================= #=================================================
# RESTORE THE NGINX CONFIGURATION # RESTORE THE NGINX CONFIGURATION
#================================================= #=================================================
@ -59,25 +66,19 @@ ynh_restore_file "$final_path"
#================================================= #=================================================
db_pwd=$(ynh_app_setting_get $app psqlpwd) db_pwd=$(ynh_app_setting_get $app psqlpwd)
ynh_psql_test_if_first_run
ynh_psql_setup_db $db_name $db_name $db_pwd ynh_psql_setup_db $db_name $db_name $db_pwd
ynh_psql_connect_as $db_name $db_pwd $db_name < ./db.sql ynh_psql_connect_as $db_name $db_pwd $db_name < ./db.sql
#================================================= #=================================================
# SPECIFIC RESTORATION # SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
# Define and install dependencies
ynh_install_app_dependencies build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
#================================================= #=================================================
ynh_restore_file "/etc/systemd/system/$app.service" ynh_restore_file "/etc/systemd/system/$app.service"
systemctl enable $app.service systemctl enable $app.service
systemctl start $app ynh_systemd_action -n $app -a start -l "Server available at" -p "systemd"
#================================================= #=================================================
# ADVERTISE SERVICE IN ADMIN PANEL # ADVERTISE SERVICE IN ADMIN PANEL

View file

@ -53,6 +53,21 @@ then # Si final_path n'est pas renseigné dans la config yunohost, cas d'ancien
final_path=/var/www/$app final_path=/var/www/$app
fi fi
if [ -z "$db_pwd" ]; then
db_pwd=$(ynh_app_setting_get $app db_pwd) # Fix old db_pwd
if [ -z "$db_pwd" ]; then
db_name=$(ynh_sanitize_dbid "$app")
db_user=$db_name
# Initialize database and store postgres password for upgrade
ynh_psql_setup_db "$db_name" "$db_user"
ynh_app_setting_set "$app" db_name "$db_name"
db_pwd=$(ynh_app_setting_get $app psqlpwd) # Password created in ynh_psql_setup_db function
else
ynh_app_setting_delete $app db_pwd
ynh_app_setting_set $app psqlpwd $db_pwd
fi
fi
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
@ -83,7 +98,6 @@ ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lstu.conf"
ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lstu.conf" ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lstu.conf"
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lstu.conf" ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lstu.conf"
secret=$(ynh_string_random 24)
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf" ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf"
ynh_store_file_checksum "${final_path}/lstu.conf" ynh_store_file_checksum "${final_path}/lstu.conf"
@ -125,7 +139,7 @@ yunohost service add $app --log "/var/log/$app.log"
# RESTART LSTU # RESTART LSTU
#================================================= #=================================================
systemctl reload $app ynh_systemd_action -n $app -a reload -l "Starting hot deployment for Hypnotoad server" -p "systemd"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT