mirror of
https://github.com/YunoHost-Apps/distbin_ynh.git
synced 2024-09-03 18:26:10 +02:00
commit
da3b8f5376
7 changed files with 139 additions and 17 deletions
|
@ -9,7 +9,7 @@ Group=__APP__
|
||||||
Environment="PATH=__NODEJS_PATH__"
|
Environment="PATH=__NODEJS_PATH__"
|
||||||
Environment="PORT=__PORT__"
|
Environment="PORT=__PORT__"
|
||||||
WorkingDirectory=__FINALPATH__/
|
WorkingDirectory=__FINALPATH__/
|
||||||
ExecStart=__FINALPATH__/node_modules/.bin/ts-node --project __FINALPATH__/tsconfig.json __FINALPATH__/bin/server.ts >> /var/log/__APP__/__APP__.log 2>&1
|
ExecStart=/bin/sh -c '__FINALPATH__/node_modules/.bin/ts-node --project __FINALPATH__/tsconfig.json __FINALPATH__/bin/server.ts >> /var/log/__APP__/__APP__.log 2>&1'
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source ../settings/scripts/_common.sh
|
source ../settings/scripts/_common.sh
|
||||||
|
source ../settings/scripts/ynh_systemd_action
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -15,7 +16,7 @@ source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
ynh_clean_setup () {
|
ynh_clean_setup () {
|
||||||
### Remove this function if there's nothing to clean before calling the remove script.
|
### Remove this function if there's nothing to clean before calling the remove script.
|
||||||
true
|
ynh_clean_check_starting
|
||||||
}
|
}
|
||||||
# Exit if an error occurs during the execution of the script
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
|
source ynh_systemd_action
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -15,7 +16,7 @@ source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
ynh_clean_setup () {
|
ynh_clean_setup () {
|
||||||
### Remove this function if there's nothing to clean before calling the remove script.
|
### Remove this function if there's nothing to clean before calling the remove script.
|
||||||
true
|
ynh_clean_check_starting
|
||||||
}
|
}
|
||||||
# Exit if an error occurs during the execution of the script
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
@ -167,11 +168,15 @@ ynh_system_user_create "$app" "$final_path"
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC SETUP
|
# SPECIFIC SETUP
|
||||||
#=================================================
|
#=================================================
|
||||||
# ...
|
# CREATE LOG FOLDER
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
mkdir -p /var/log/$app
|
mkdir -p "/var/log/$app"
|
||||||
chown -R $app:$app /var/log/$app
|
chown -R "$app":"$app" "/var/log/$app"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# MAKE SETUP
|
||||||
|
#=================================================
|
||||||
|
|
||||||
chown -R "$app":"$app" "$final_path"
|
chown -R "$app":"$app" "$final_path"
|
||||||
pushd $final_path
|
pushd $final_path
|
||||||
|
@ -202,7 +207,6 @@ popd
|
||||||
ynh_replace_string "__NODEJS_PATH__" "$nodejs_path" "../conf/systemd.service"
|
ynh_replace_string "__NODEJS_PATH__" "$nodejs_path" "../conf/systemd.service"
|
||||||
ynh_replace_string "__PORT__" "$port" "../conf/systemd.service"
|
ynh_replace_string "__PORT__" "$port" "../conf/systemd.service"
|
||||||
ynh_add_systemd_config
|
ynh_add_systemd_config
|
||||||
systemctl start $app
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP APPLICATION WITH CURL
|
# SETUP APPLICATION WITH CURL
|
||||||
|
@ -313,4 +317,9 @@ fi
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
systemctl reload nginx
|
systemctl reload nginx
|
||||||
sleep 30
|
|
||||||
|
#=================================================
|
||||||
|
# START SERVICE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_systemd_action --action=start --service_name=$app --line_match="http://localhost:"
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
|
source ynh_systemd_action
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -18,7 +19,6 @@ app=$YNH_APP_INSTANCE_NAME
|
||||||
domain=$(ynh_app_setting_get $app domain)
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
port=$(ynh_app_setting_get $app port)
|
port=$(ynh_app_setting_get $app port)
|
||||||
#db_name=$(ynh_app_setting_get $app db_name)
|
#db_name=$(ynh_app_setting_get $app db_name)
|
||||||
#db_user=$db_name
|
|
||||||
final_path=$(ynh_app_setting_get $app final_path)
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -55,7 +55,7 @@ ynh_remove_nodejs
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Remove a database if it exists, along with the associated user
|
# Remove a database if it exists, along with the associated user
|
||||||
#ynh_mysql_remove_db $db_user $db_name
|
#ynh_mysql_remove_db $db_name $db_name
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE APP MAIN DIR
|
# REMOVE APP MAIN DIR
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source ../settings/scripts/_common.sh
|
source ../settings/scripts/_common.sh
|
||||||
|
source ../settings/scripts/ynh_systemd_action
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -15,7 +16,7 @@ source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
ynh_clean_setup () {
|
ynh_clean_setup () {
|
||||||
#### Remove this function if there's nothing to clean before calling the remove script.
|
#### Remove this function if there's nothing to clean before calling the remove script.
|
||||||
true
|
ynh_clean_check_starting
|
||||||
}
|
}
|
||||||
# Exit if an error occurs during the execution of the script
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
@ -102,7 +103,7 @@ ynh_install_nodejs 8
|
||||||
|
|
||||||
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
|
systemctl daemon-reload
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# ADVERTISE SERVICE IN ADMIN PANEL
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||||
|
@ -130,4 +131,16 @@ ynh_restore_file "/etc/logrotate.d/$app"
|
||||||
|
|
||||||
#systemctl reload php5-fpm
|
#systemctl reload php5-fpm
|
||||||
systemctl reload nginx
|
systemctl reload nginx
|
||||||
sleep 30
|
|
||||||
|
#=================================================
|
||||||
|
# CREATE LOG FOLDER
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
mkdir -p "/var/log/$app"
|
||||||
|
chown -R "$app":"$app" "/var/log/$app"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# START SERVICE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_systemd_action --action=start --service_name=$app --line_match="http://localhost:"
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
|
source ynh_systemd_action
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -58,10 +59,17 @@ ynh_backup_before_upgrade
|
||||||
ynh_clean_setup () {
|
ynh_clean_setup () {
|
||||||
# restore it if the upgrade fails
|
# restore it if the upgrade fails
|
||||||
ynh_restore_upgradebackup
|
ynh_restore_upgradebackup
|
||||||
|
ynh_clean_check_starting
|
||||||
}
|
}
|
||||||
# Exit if an error occurs during the execution of the script
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STOP SERVICE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_systemd_action --action=stop --service_name=$app
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CHECK THE PATH
|
# CHECK THE PATH
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -75,8 +83,6 @@ path_url=$(ynh_normalize_url_path $path_url)
|
||||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
systemctl stop $app
|
|
||||||
|
|
||||||
# Download, check integrity, uncompress and patch the source from app.src#
|
# Download, check integrity, uncompress and patch the source from app.src#
|
||||||
#ynh_setup_source "$final_path"
|
#ynh_setup_source "$final_path"
|
||||||
(cd $final_path && git pull)
|
(cd $final_path && git pull)
|
||||||
|
@ -148,7 +154,6 @@ ynh_replace_string "__NODEJS_PATH__" "$nodejs_path" "../conf/systemd.service"
|
||||||
ynh_replace_string "__PORT__" "$port" "../conf/systemd.service"
|
ynh_replace_string "__PORT__" "$port" "../conf/systemd.service"
|
||||||
# Create a dedicated systemd config
|
# Create a dedicated systemd config
|
||||||
ynh_add_systemd_config
|
ynh_add_systemd_config
|
||||||
systemctl start $app
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALIZATION
|
# GENERIC FINALIZATION
|
||||||
|
@ -179,4 +184,9 @@ fi
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
systemctl reload nginx
|
systemctl reload nginx
|
||||||
sleep 30
|
|
||||||
|
#=================================================
|
||||||
|
# START SERVICE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_systemd_action --action=start --service_name=$app --line_match="http://localhost:"
|
||||||
|
|
89
scripts/ynh_systemd_action
Normal file
89
scripts/ynh_systemd_action
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 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
|
||||||
|
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
|
||||||
|
}
|
Loading…
Reference in a new issue