From 1fff8898a92aaaa4d197b42171b839304cb65179 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sun, 26 Aug 2018 21:45:44 +0200 Subject: [PATCH] Fix install and exec --- conf/systemd.service | 1 + scripts/_common.sh | 102 +++++++++++++++++++++++++++++++++++++++++++ scripts/backup | 5 --- scripts/install | 10 ++--- scripts/remove | 4 -- scripts/restore | 6 --- 6 files changed, 108 insertions(+), 20 deletions(-) diff --git a/conf/systemd.service b/conf/systemd.service index f7e76b2..21eff83 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -6,6 +6,7 @@ After=network.target Type=simple User=__APP__ Group=__APP__ +Environment="PYTHONHOME=__FINALPATH__/ve3/bin/" "PYTHONPATH=__FINALPATH__/.pythonz/pythons/CPython-3.6.6/lib/python3.6" WorkingDirectory=__FINALPATH__ ExecStart=__FINALPATH__/ve3/bin/python ./run.py /home/CI_package_check/analyseCI.sh >> /var/log/__APP__/__APP__.log 2&>1 diff --git a/scripts/_common.sh b/scripts/_common.sh index 61f13bf..547c448 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -197,6 +197,108 @@ ynh_handle_getopts_args () { #================================================= +ynh_print_log () { + echo "${1}" +} + +# Print an info on stdout +# +# usage: ynh_print_info "Text to print" +# | arg: text - The text to print +ynh_print_info () { + ynh_print_log "[INFO] ${1}" +} + +# Print a warning on stderr +# +# usage: ynh_print_warn "Text to print" +# | arg: text - The text to print +ynh_print_warn () { + ynh_print_log "[WARN] ${1}" >&2 +} + +# Print a error on stderr +# +# usage: ynh_print_err "Text to print" +# | arg: text - The text to print +ynh_print_err () { + ynh_print_log "[ERR] ${1}" >&2 +} + +# Execute a command and print the result as an error +# +# usage: ynh_exec_err command to execute +# usage: ynh_exec_err "command to execute | following command" +# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe. +# +# | arg: command - command to execute +ynh_exec_err () { + ynh_print_err "$(eval $@)" +} + +# Execute a command and print the result as a warning +# +# usage: ynh_exec_warn command to execute +# usage: ynh_exec_warn "command to execute | following command" +# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe. +# +# | arg: command - command to execute +ynh_exec_warn () { + ynh_print_warn "$(eval $@)" +} + +# Execute a command and force the result to be printed on stdout +# +# usage: ynh_exec_warn_less command to execute +# usage: ynh_exec_warn_less "command to execute | following command" +# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe. +# +# | arg: command - command to execute +ynh_exec_warn_less () { + eval $@ 2>&1 +} + +# Execute a command and redirect stdout in /dev/null +# +# usage: ynh_exec_quiet command to execute +# usage: ynh_exec_quiet "command to execute | following command" +# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe. +# +# | arg: command - command to execute +ynh_exec_quiet () { + eval $@ > /dev/null +} + +# Execute a command and redirect stdout and stderr in /dev/null +# +# usage: ynh_exec_fully_quiet command to execute +# usage: ynh_exec_fully_quiet "command to execute | following command" +# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe. +# +# | arg: command - command to execute +ynh_exec_fully_quiet () { + eval $@ > /dev/null 2>&1 +} + +# Remove any logs for all the following commands. +# +# usage: ynh_print_OFF +# WARNING: You should be careful with this helper, and never forgot to use ynh_print_ON as soon as possible to restore the logging. +ynh_print_OFF () { + set +x +} + +# Restore the logging after ynh_print_OFF +# +# usage: ynh_print_ON +ynh_print_ON () { + set -x + # Print an echo only for the log, to be able to know that ynh_print_ON has been called. + echo ynh_print_ON > /dev/null +} + +#================================================= + # Read the value of a key in a ynh manifest file # # usage: ynh_read_manifest manifest key diff --git a/scripts/backup b/scripts/backup index 207770a..4de007a 100644 --- a/scripts/backup +++ b/scripts/backup @@ -53,8 +53,3 @@ ynh_backup "/etc/logrotate.d/$app" ynh_backup "/etc/systemd/system/$app.service" -#================================================= -# BACKUP OF PYTHONZ -#================================================= - -ynh_backup "$HOME/.pythonz" diff --git a/scripts/install b/scripts/install index 7265666..2b9c4e4 100644 --- a/scripts/install +++ b/scripts/install @@ -94,24 +94,24 @@ ynh_system_user_create $app # Créer un utilisateur système dédié à l'app # Get pythonz # curl -kL https://raw.githubusercontent.com/saghul/pythonz/master/pythonz-install # ./pythonz-install -ynh_setup_source "$HOME/.pythonz" pythonz +ynh_setup_source "$final_path/.pythonz" pythonz # Then install it -python $HOME/.pythonz/pythonz_install.py +python $final_path/.pythonz/pythonz_install.py # if ! grep --quiet "YunoRunner" /root/.bashrc # then -# [[ -s $HOME/.pythonz/etc/bashrc ]] && source $HOME/.pythonz/etc/bashrc # Added by YunoRunner +# [[ -s $final_path/.pythonz/etc/bashrc ]] && source $final_path/.pythonz/etc/bashrc # Added by YunoRunner # fi # Install Python 3.6.6 -$HOME/.pythonz/bin/pythonz install 3.6.6 +$final_path/.pythonz/bin/pythonz install 3.6.6 #================================================= # INSTALL YUNORUNNER DEPENDENCIES #================================================= ( cd $final_path -virtualenv -p $($HOME/.pythonz/bin/pythonz locate 3.6.6) ve3 +virtualenv -p $($final_path/.pythonz/bin/pythonz locate 3.6.6) ve3 ve3/bin/pip3 install -r requirements.txt ) #================================================= diff --git a/scripts/remove b/scripts/remove index fe01e3a..a4ba2cb 100755 --- a/scripts/remove +++ b/scripts/remove @@ -72,10 +72,6 @@ fi #================================================= # SPECIFIC REMOVE #================================================= -# REMOVE PYTHONZ -#================================================= - -ynh_secure_remove "$HOME/.pythonz" # Suppression des log ynh_secure_remove "/var/log/$app" diff --git a/scripts/restore b/scripts/restore index 1965428..2366206 100644 --- a/scripts/restore +++ b/scripts/restore @@ -90,12 +90,6 @@ ynh_restore_file "/etc/systemd/system/$app.service" ## Démarrage auto du service systemctl enable $app.service -#================================================= -# RESTORE OF PYTHONZ -#================================================= - -ynh_restore_file "$HOME/.pythonz" - #================================================= # BACKUP OF THE LOGROTATE CONFIGURATION #=================================================