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

[fix] Clean code

This commit is contained in:
magikcypress 2017-04-01 18:19:41 +02:00
parent 9de0faffee
commit 8f3d9cb22f
7 changed files with 14 additions and 275 deletions

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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"

View file

@ -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

View file

@ -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}"

View file

@ -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" ];