From 8f3d9cb22f313c08fd825beb2aa30d634e158017 Mon Sep 17 00:00:00 2001 From: magikcypress Date: Sat, 1 Apr 2017 18:19:41 +0200 Subject: [PATCH] [fix] Clean code --- conf/lufi.default | 6 -- conf/lufi.init | 198 ---------------------------------------------- scripts/backup | 4 - scripts/install | 43 +++------- scripts/remove | 7 -- scripts/restore | 28 ++----- scripts/upgrade | 3 - 7 files changed, 14 insertions(+), 275 deletions(-) delete mode 100644 conf/lufi.default delete mode 100644 conf/lufi.init diff --git a/conf/lufi.default b/conf/lufi.default deleted file mode 100644 index 6f6d756..0000000 --- a/conf/lufi.default +++ /dev/null @@ -1,6 +0,0 @@ -# LDIR is the path where you installed Lufi -# It has to end with a final / -LDIR=__FINALPATH__ - -# USER is the user who will launch Lufi -USER=www-data diff --git a/conf/lufi.init b/conf/lufi.init deleted file mode 100644 index be29204..0000000 --- a/conf/lufi.init +++ /dev/null @@ -1,198 +0,0 @@ - -#!/bin/sh -# vim: set ts=4 sw=4 sts=4 tw=0: -# vim: set expandtab: - -### BEGIN INIT INFO -# Provides: lufi -# Required-Start: $local_fs $remote_fs $network $syslog -# Required-Stop: $local_fs $remote_fs $network $syslog -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: starts lufi with hypnotoad -# Description: starts lufi with hypnotoad -### END INIT INFO - - -PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin -DAEMON=script/lutim -NAME=lufi -DESC=lufi - -if [ -f "/etc/default/lufi" ] -then - . /etc/default/lutim - if [ -z $LDIR ] - then - echo "LDIR variable is empty, please fill it in /etc/default/lufi" - exit 0 - fi - if [ -z $USER ] - then - echo "USER variable is empty, please fill it in /etc/default/lufi" - exit 0 - fi -else - echo "Missing /etc/default/lutim file" - exit 0 -fi - -if [ ! -f "$LDIR$DAEMON" ] -then - echo "Missing $LDIR$DAEMON file" - exit 0 -fi - -set -e - -. /lib/lsb/init-functions - -do_start() -{ - # Return - # 0 if daemon has been started - # 1 if daemon was already running - # 2 if daemon could not be started - - cd $LDIR - su $USER -c "carton exec hypnotoad $DAEMON >> /var/log/lufi/production.log 2>&1" - return "$?" -} - -do_stop() -{ - # Return - # 0 if daemon has been stopped - # 1 if daemon was already stopped - # 2 if daemon could not be stopped - # other if a failure occurred - - cd $LDIR - su $USER -c "carton exec hypnotoad -s $DAEMON >> /var/log/lufi/production.log 2>&1" - return "$?" -} - -do_status() -{ - cd $LDIR - if [ -f "script/hypnotoad.pid" ] - then - pgrep -lf $DAEMON >/dev/null 2>&1 - if [ "$?" = "0" ]; then - log_progress_msg "$NAME is running" - else - log_failure_msg "$NAME is NOT running but PID file exists" - fi - else - log_failure_msg "$NAME is NOT running" - fi -} - -case "$1" in - start) - log_daemon_msg "Starting $NAME" - cd $LDIR - if [ -f "script/hypnotoad.pid" ] - then - pgrep -lf $DAEMON >/dev/null 2>&1 - if [ "$?" = "0" ] - then - log_progress_msg "$NAME is already running. Unable to start." - log_end_msg 1; - else - do_start - case "$?" in - 0|1) - log_progress_msg "done" - log_end_msg 0 - ;; - 2) - log_failure_msg "failed" - log_end_msg 1 - ;; - esac - fi - else - do_start - case "$?" in - 0|1) - log_progress_msg "done" - log_end_msg 0 - ;; - 2) - log_failure_msg "failed" - log_end_msg 1 - ;; - esac - fi - ;; - stop) - log_daemon_msg "Stopping $NAME" - cd $LDIR - if [ -f "script/hypnotoad.pid" ] - then - pgrep -lf $DAEMON >/dev/null 2>&1 - if [ "$?" = "0" ]; then - do_stop - case "$?" in - 0|1) - log_progress_msg "done" - log_end_msg 0 - ;; - *) - log_failure_msg "failed" - log_end_msg 1 - ;; - esac - else - log_failure_msg "$NAME is NOT running. Unable to stop" - log_end_msg 1 - fi - else - log_failure_msg "$NAME is NOT running. Unable to stop" - log_end_msg 1 - fi - ;; - status) - log_daemon_msg "Checking $NAME status" - do_status - log_end_msg 0 - ;; - reload) - log_daemon_msg "Reloading $NAME" - do_start - sleep 1 - case "$?" in - 0|1) - log_progress_msg "done" - log_end_msg 0 - ;; - 2) - log_failure_msg "failed" - log_end_msg 1 - ;; - esac - ;; - restart) - log_daemon_msg "Restarting $NAME" - do_stop - sleep 6 - do_start - case "$?" in - 0|1) - log_progress_msg "done" - log_end_msg 0 - ;; - 2) - log_failure_msg "failed"; - log_end_msg 1 - ;; - esac - ;; - *) - echo "Usage: $0 {start|stop|status|reload|restart}" >&2 - exit 3 - ;; -esac - -exit 0 diff --git a/scripts/backup b/scripts/backup index 7d5f8ef..897ea78 100644 --- a/scripts/backup +++ b/scripts/backup @@ -18,13 +18,9 @@ ynh_backup "${final_path}" "sources" 1 # Copy the nginx conf files ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf" -# Copy the php-fpm conf files -ynh_backup "/etc/php5/fpm/pool.d/${app}.conf" "php-fpm.conf" -ynh_backup "/etc/php5/fpm/conf.d/20-${app}.ini" "php-fpm.ini" # Copy the lufi fonf file ynh_backup "${final_path}/lufi.conf" "lufi.conf" -ynh_backup "/etc/default/lufi" "default_lufi" ynh_backup "/etc/systemd/system/lufi.service" "systemd_lufi.service" ynh_backup "/etc/cron.d/${app}" "cron_lufi" ynh_backup "/etc/logrotate.d/${app}" "logrotate_lufi" \ No newline at end of file diff --git a/scripts/install b/scripts/install index 965ac92..143c7b1 100644 --- a/scripts/install +++ b/scripts/install @@ -78,27 +78,12 @@ CHECK_VAR "$secret" "secret empty" sudo sed -i "s@__SECRET__@$secret@g" "${final_path}/lufi.conf" STORE_MD5_CONFIG "lufi.conf" "${final_path}/lufi.conf" # Enregistre la somme de contrôle du fichier de config -codename=$(lsb_release -a 2>/dev/null | grep Codename | cut -f 2) -CHECK_VAR "$codename" "codename empty" -ynh_app_setting_set $app codename $codename -if [ "$codename" = "wheezy" ] -then # On utilise le script init pour wheezy. - # Mise en place du script init - sudo cp ../conf/lufi.init /etc/init.d/lufi - sudo cp ../conf/lufi.default /etc/default/lufi - sudo chmod +x /etc/init.d/lufi - sudo chown root: /etc/init.d/lufi /etc/default/lufi - sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/default/lufi - ## Démarrage auto du service - sudo update-rc.d lufi defaults -else # Et le script systemd à partir de jessie - # Mise en place du script systemd - sudo cp ../conf/lufi.service /etc/systemd/system/lufi.service - sudo chown root: /etc/systemd/system/lufi.service - sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/systemd/system/lufi.service - ## Démarrage auto du service - sudo systemctl enable lufi.service -fi +# Mise en place du script systemd +sudo cp ../conf/lufi.service /etc/systemd/system/lufi.service +sudo chown root: /etc/systemd/system/lufi.service +sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/systemd/system/lufi.service +## Démarrage auto du service +sudo systemctl enable lufi.service ## Mise en place des crons sudo cp ../conf/cron_lufi /etc/cron.d/$app @@ -148,19 +133,9 @@ sudo ln -s /var/log/$app/production.log "$final_path/log/production.log" sudo chown -R www-data: $final_path # Start lufi -codename=$(lsb_release -a 2>/dev/null | grep Codename | cut -f 2) -CHECK_VAR "$codename" "codename empty" -ynh_app_setting_set $app codename $codename -if [ "$codename" = "wheezy" ] -then # On utilise le script init pour wheezy. - sudo /etc/init.d/lufi start - sudo update-rc.d lufi defaults - sudo service lufi start -else - sudo systemctl daemon-reload - sudo systemctl start lufi.service - sudo systemctl enable lufi.service -fi +sudo systemctl daemon-reload +sudo systemctl start lufi.service +sudo systemctl enable lufi.service # Set right permissions on new files created at first start sudo chown -R www-data: "$final_path" diff --git a/scripts/remove b/scripts/remove index 03d97cd..abda5de 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,13 +12,6 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) # Arrêt du service -if [ -e "/etc/init.d/lufi" ]; then - echo "Delete init.d script" - sudo service lufi stop - sudo rm "/etc/init.d/lufi" - sudo rm "/etc/default/lufi" - sudo update-rc.d -f lufi remove -fi if [ -e "/etc/systemd/system/lufi.service" ]; then echo "Delete systemd script" sudo service lufi stop diff --git a/scripts/restore b/scripts/restore index 35bc3df..5b51471 100644 --- a/scripts/restore +++ b/scripts/restore @@ -37,20 +37,9 @@ if [ -f "${lufi_conf}" ]; then ynh_die "The LUFI CONF configuration already exists at '${lufi_conf}'. You should safely delete it before restoring this app." fi -codename=$(lsb_release -a 2>/dev/null | grep Codename | cut -f 2) -CHECK_VAR "$codename" "codename empty" -ynh_app_setting_set $app codename $codename -if [ "$codename" = "wheezy" ] -then # On utilise le script init pour wheezy. - lufi_default="/etc/default/lufi" - if [ -f "${lufi_default}" ]; then - ynh_die "The LUFI DEFAULT configuration already exists at '${lufi_default}'. You should safely delete it before restoring this app." - fi -else # Et le script systemd à partir de jessie - lufi_systemd="/etc/systemd/system/lufi.service" - if [ -f "${lufi_default}" ]; then - ynh_die "The LUFI SYSTEMD configuration already exists at '${lufi_systemd}'. You should safely delete it before restoring this app." - fi +lufi_systemd="/etc/systemd/system/lufi.service" +if [ -f "${lufi_default}" ]; then + ynh_die "The LUFI SYSTEMD configuration already exists at '${lufi_systemd}'. You should safely delete it before restoring this app." fi lufi_cron="/etc/cron.d/${app}" @@ -78,15 +67,8 @@ sudo cp -a ./php-fpm.ini "${phpfpm_ini}" # Restore lufi configuration files sudo cp -a ./lufi.conf "${lufi_conf}" -codename=$(lsb_release -a 2>/dev/null | grep Codename | cut -f 2) -CHECK_VAR "$codename" "codename empty" -ynh_app_setting_set $app codename $codename -if [ "$codename" = "wheezy" ] -then # On utilise le script init pour wheezy. - sudo cp -a ./default_lufi "${lufi_default}" -else - sudo cp -a ./systemd_lufi.service "${lufi_systemd}" -fi +# Restore service +sudo cp -a ./systemd_lufi.service "${lufi_systemd}" sudo cp -a ./cron_lufi "${lufi_cron}" sudo cp -a ./logrotate_lufi "${lufi_logrotate}" diff --git a/scripts/upgrade b/scripts/upgrade index e245413..cb20c1d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -31,9 +31,6 @@ then sudo sed -i "s@#--PRIVATE--@@g" /etc/nginx/conf.d/$domain.d/$app.conf fi -# Create the php-fpm pool config -POOL_FPM - # Setup SSOwat ynh_app_setting_set "$app" is_public "$is_public" if [ "$is_public" = "Yes" ];