2018-01-31 16:07:43 +01:00
#=================================================
# SET ALL CONSTANTS
#=================================================
2017-07-21 22:11:45 +02:00
2024-04-04 00:28:32 +02:00
readonly systemd_user = root
readonly nginx_status_conf = " /etc/nginx/conf.d/ ${ app } _status.conf "
2018-01-31 16:07:43 +01:00
2024-04-04 00:28:32 +02:00
readonly db_user = $app
2024-04-16 23:17:24 +02:00
readonly var_list_to_manage = 'mysql_installed postgresql_installed memcached_installed redis_installed phpfpm_installed jail_list mount_parts home_user_dirs net_gateway net_interface_list net_max_speed ssh_port port_infos process_infos php_pools_infos'
2023-12-09 00:35:51 +01:00
2018-01-31 16:07:43 +01:00
#=================================================
# DEFINE ALL COMMON FONCTIONS
#=================================================
2017-01-05 23:37:07 +01:00
2024-04-04 00:28:32 +02:00
installed_php_fpm_filter( ) {
while read -r item; do
local version = ${ item %,* }
2024-08-31 01:07:34 +02:00
if _ynh_apt_package_is_installedphp" $version " -fpm; then
2024-04-04 00:28:32 +02:00
echo " $item "
fi
done
}
home_dir_filter( ) {
while read -r -d' ' item; do
if [ " $item " != /home/yunohost.app ] && [ " $item " != /home/yunohost.backup ] ; then
echo " $item "
fi
done
}
interface_speed_map( ) {
while read -r item; do
2024-04-09 20:29:45 +02:00
speed = $( cat /sys/class/net/" $item " /speed 2>/dev/null || echo 1000)
2024-04-16 22:49:56 +02:00
if [ " $speed " = = -1 ] ; then
speed = 1000
fi
2024-04-04 00:28:32 +02:00
echo " $item , $speed "
done
}
load_vars( ) {
2024-04-09 20:29:45 +02:00
# Big warning here
# This function is called by the hook in install/upgrade/remove yunohost operation
# We we need to ensure that this function the quickest as possible
2024-04-16 23:18:14 +02:00
# Note that we don't use the yunohost command intentionally for optimization
2024-08-31 01:07:34 +02:00
if _ynh_apt_package_is_installedmysql || _ynh_apt_package_is_installedmariadb-server; then
2024-04-04 00:28:32 +02:00
readonly mysql_installed = true
else
readonly mysql_installed = false
fi
2024-08-31 01:07:34 +02:00
if _ynh_apt_package_is_installedpostgresql; then
2024-04-04 00:28:32 +02:00
readonly postgresql_installed = true
else
readonly postgresql_installed = false
fi
2024-08-31 01:07:34 +02:00
if _ynh_apt_package_is_installedmemcached; then
2024-04-04 00:28:32 +02:00
readonly memcached_installed = true
else
readonly memcached_installed = false
fi
2024-08-31 01:07:34 +02:00
if _ynh_apt_package_is_installedredis-server; then
2024-04-04 00:28:32 +02:00
readonly redis_installed = true
else
readonly redis_installed = false
fi
2024-08-31 01:07:34 +02:00
if _ynh_apt_package_is_installed'php*-fpm' ; then
2024-04-04 00:28:32 +02:00
readonly phpfpm_installed = true
else
readonly phpfpm_installed = false
fi
readonly jail_list = " $( fail2ban-client status |
grep 'Jail list:' | sed 's/.*Jail list://' | sed 's/,//g' ) "
readonly mount_parts = " $( mount |
cut -d' ' -f3 |
2024-04-16 21:28:33 +02:00
grep -E -v '^/run|^/dev|^/proc|^/sys|^/snap|^/$' ) "
2024-04-04 00:28:32 +02:00
app_data_dirs = " $( echo /home/yunohost.app/*) "
readonly home_user_dirs = " $( echo /home/* | home_dir_filter) "
readonly net_gateway = " $( ip --json route show default | jq -r '.[0].dev' ) "
readonly net_interface_list = " $( ip --json link show | jq -r '.[].ifname | select(. != "lo")' | interface_speed_map) "
2024-04-26 21:48:22 +02:00
readonly net_max_speed = " $( cat /sys/class/net/*/speed 2>/dev/null | sort | tail -n1 | sed 's|-1|1000|g' ) "
2024-04-09 20:29:45 +02:00
readonly ssh_port = " $(( grep ssh_port / etc/yunohost/settings.yml | | echo 22 ) | cut - d: - f2 | xargs) "
readonly port_infos = " $( python3 <<EOF
import yaml, socket
hard_coded_ports = [ "25" , "53" , "80" , "443" , "587" , "993" ]
with open( "/etc/yunohost/firewall.yml" , "r" ) as f:
firewall = yaml.safe_load( f)
tcp4_port_list = [ str( port) for port in firewall[ 'ipv4' ] [ 'TCP' ]
if str( port) not in hard_coded_ports]
tcp6_port_list = [ str( port) for port in firewall[ 'ipv6' ] [ 'TCP' ]
if str( port) not in hard_coded_ports]
udp4_port_list = [ str( port) for port in firewall[ 'ipv4' ] [ 'UDP' ]
if str( port) not in hard_coded_ports]
udp6_port_list = [ str( port) for port in firewall[ 'ipv6' ] [ 'UDP' ]
if str( port) not in hard_coded_ports]
with open( "/etc/yunohost/services.yml" , "r" ) as f:
services = yaml.safe_load( f)
2024-04-26 23:52:06 +02:00
if services is None:
services = dict( )
2024-04-09 20:29:45 +02:00
port_map = dict( )
for key, value in services.items( ) :
if 'needs_exposed_ports' in value:
for port in value[ 'needs_exposed_ports' ] :
port_map[ str( port) ] = key
def generate_port_info( proto, ip_version, port) :
if port in port_map:
name = port_map[ port]
else :
try:
name = socket.getservbyport( int( port) , proto)
except:
name = "Port_" + port
return "%s,%s,%s,%s" % ( port, ip_version, proto, name)
result = [ generate_port_info( "tcp" , "4" , port) for port in tcp4_port_list] + \
[ generate_port_info( "tcp" , "6" , port) for port in tcp6_port_list] + \
[ generate_port_info( "udp" , "4" , port) for port in udp4_port_list] + \
[ generate_port_info( "udp" , "6" , port) for port in udp6_port_list]
result.sort( )
print( '\n' .join( result) )
EOF
2024-04-16 23:12:46 +02:00
) "
readonly process_infos = " $( python3 <<EOF
import yaml, socket
hard_coded_ports = [ "25" , "53" , "80" , "443" , "587" , "993" ]
with open( "/etc/yunohost/services.yml" , "r" ) as f:
services = yaml.safe_load( f)
2024-04-26 23:52:06 +02:00
if services is None:
services = dict( )
2024-04-16 23:20:53 +02:00
results = [ "%s|%s" % ( k, v[ "description" ] if "description" in v else k) for k, v in services.items( ) ]
2024-04-16 23:12:46 +02:00
print( '\n' .join( results) )
EOF
2024-04-09 20:29:45 +02:00
) "
2024-04-05 12:18:48 +02:00
if compgen -G /etc/php/*/fpm/pool.d; then
# Note that 'pm.status_listen' option is only supported on php >= 8.0 so we ignore older pools
readonly php_pools_infos = " $( grep -E '^\[.*\]' \
--exclude= /etc/php/*/fpm/pool.d/" $app " _status.conf \
--exclude= /etc/php/7.*/fpm/pool.d/* /etc/php/*/fpm/pool.d/* |
sed -E 's|/etc/php/([[:digit:]]\.[[:digit:]]+)/fpm/pool.d/.+\.conf\:\[(.+)\]|\1,\2|' |
installed_php_fpm_filter) "
else
readonly php_pools_infos = ''
fi
2024-04-04 00:28:32 +02:00
}
# Used by update_config_if_needed.sh hook
save_vars_current_value( ) {
for var in $var_list_to_manage ; do
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= " previous_ $var " --value= " ${ !var } "
2024-04-04 00:28:32 +02:00
done
}
2023-12-09 00:35:51 +01:00
install_monitorix_package( ) {
# Create the temporary directory
tempdir = " $( mktemp -d) "
2017-01-05 23:37:07 +01:00
2023-12-09 00:35:51 +01:00
# Download the deb files
ynh_setup_source --dest_dir= " $tempdir " --source_id= "main"
2017-01-31 21:26:13 +01:00
2023-12-09 00:35:51 +01:00
# Install the package
2024-08-31 01:07:34 +02:00
_ynh_apt_install " $tempdir /monitorix.deb "
2024-04-04 00:28:32 +02:00
cp -r /var/lib/monitorix/* " $data_dir " /
}
configure_db( ) {
# Here the idea is to monitor available database
# So if mysql is installed we monitor it but mysql could also not be installed and in this case don't need to monitor it
# For postgresql it's the same case
if $mysql_installed && ! ynh_mysql_user_exists --user= " $db_user " ; then
ynh_mysql_create_user " $db_user " " $db_pwd "
fi
if $postgresql_installed && ! ynh_psql_user_exists --user= " $db_user " ; then
ynh_psql_create_user " $db_user " " $db_pwd "
fi
}
config_php_fpm( ) {
for pool_dir_by_version in /etc/php/*; do
pool_version = $( echo " $pool_dir_by_version " | cut -d/ -f4)
pool_file = " /etc/php/ $pool_version /fpm/pool.d/ ${ app } _status.conf "
2024-08-31 01:07:34 +02:00
if _ynh_apt_package_is_installed" php $pool_version -fpm " ; then
ynh_config_add --jinja --template= _php_status.conf --destination= " $pool_file "
2024-04-04 00:28:32 +02:00
chown root:root " $pool_file "
chmod 444 " $pool_file "
2024-08-31 01:07:34 +02:00
ynh_systemctl --service= " php $pool_version " -fpm.service --action= reload
2024-04-04 00:28:32 +02:00
else
if [ -e " $pool_file " ] ; then
2024-08-31 01:07:34 +02:00
ynh_safe_rm " $pool_file "
2024-04-04 00:28:32 +02:00
fi
fi
done
}
2018-05-07 23:08:03 +02:00
2024-04-04 00:28:32 +02:00
configure_hooks( ) {
2024-08-31 01:07:34 +02:00
ynh_replace --match= __APP__ --replace= " $app " --file= ../hooks/post_iptable_rules
ynh_replace --match= __INSTALL_DIR__ --replace= " $install_dir " --file= ../hooks/post_app_install
ynh_replace --match= __INSTALL_DIR__ --replace= " $install_dir " --file= ../hooks/post_app_remove
ynh_replace --match= __INSTALL_DIR__ --replace= " $install_dir " --file= ../hooks/post_app_upgrade
2018-05-07 23:08:03 +02:00
2024-04-04 00:28:32 +02:00
cp ../sources/update_config_if_needed.sh " $install_dir " /
2024-08-31 01:07:34 +02:00
ynh_replace --match= __APP__ --replace= " $app " --file= " $install_dir " /update_config_if_needed.sh
2017-07-21 22:11:45 +02:00
}
2024-04-04 00:28:32 +02:00
configure_alerts_email( ) {
2024-08-31 01:07:34 +02:00
ynh_config_add --template= monitorix-alert.sh --destination= " $install_dir " /monitorix-alert.sh
2024-04-04 00:28:32 +02:00
for alias_file in system.loadavg-alert.sh \
fs.loadavg-alert.sh \
mail.mqueued-alert.sh \
mail.delvd-alert.sh
do
alias_path = " $install_dir / $alias_file "
if [ ! -h " $alias_path " ] ; then
if [ -e " $alias_path " ] ; then
2024-08-31 01:07:34 +02:00
ynh_safe_rm " $alias_path "
2020-05-13 15:19:34 +02:00
fi
2024-04-04 00:28:32 +02:00
ln -s " $install_dir /monitorix-alert.sh " " $install_dir / $alias_file "
2020-05-13 15:19:34 +02:00
fi
done
2024-04-04 00:28:32 +02:00
}
ensure_vars_set( ) {
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=db_pwd --value="$(ynh_string_random --length=12)"
2024-04-04 00:28:32 +02:00
if [ -z " ${ db_pwd :- } " ] ; then
2024-08-31 01:07:34 +02:00
db_pwd = " $( ynh_string_random --length= 12) "
ynh_app_setting_set --key= db_pwd --value= " $db_pwd "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=alerts_email --value="admins@$domain"
2024-04-04 00:28:32 +02:00
if [ -z " ${ alerts_email :- } " ] ; then
alerts_email = " admins@ $domain "
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= alerts_email --value= " $alerts_email "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=enable_hourly_view --value=n
2024-04-04 00:28:32 +02:00
if [ -z " ${ enable_hourly_view :- } " ] ; then
enable_hourly_view = n
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= enable_hourly_view --value= " $enable_hourly_view "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=image_format --value=svg
2024-04-04 00:28:32 +02:00
if [ -z " ${ image_format :- } " ] ; then
image_format = svg
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= image_format --value= " $image_format "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=theme_color --value=black
2024-04-04 00:28:32 +02:00
if [ -z " ${ theme_color :- } " ] ; then
theme_color = black
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= theme_color --value= " $theme_color "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=max_historic_years --value=5
2024-04-04 00:28:32 +02:00
if [ -z " ${ max_historic_years :- } " ] ; then
max_historic_years = 5
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= max_historic_years --value= " $max_historic_years "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=process_priority --value=0
2024-04-04 00:28:32 +02:00
if [ -z " ${ process_priority :- } " ] ; then
process_priority = 0
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= process_priority --value= " $process_priority "
2024-04-04 00:28:32 +02:00
fi
2020-05-13 15:19:34 +02:00
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=system_alerts_loadavg_enabled --value=n
2024-04-04 00:28:32 +02:00
if [ -z " ${ system_alerts_loadavg_enabled :- } " ] ; then
system_alerts_loadavg_enabled = n
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= system_alerts_loadavg_enabled --value= " $system_alerts_loadavg_enabled "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=system_alerts_loadavg_timeintvl --value=3600
2024-04-04 00:28:32 +02:00
if [ -z " ${ system_alerts_loadavg_timeintvl :- } " ] ; then
system_alerts_loadavg_timeintvl = 3600
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= system_alerts_loadavg_timeintvl --value= " $system_alerts_loadavg_timeintvl "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=system_alerts_loadavg_threshold --value=5.0
2024-04-04 00:28:32 +02:00
if [ -z " ${ system_alerts_loadavg_threshold :- } " ] ; then
system_alerts_loadavg_threshold = 5.0
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= system_alerts_loadavg_threshold --value= " $system_alerts_loadavg_threshold "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=disk_alerts_loadavg_enabled --value=false
2024-04-04 00:28:32 +02:00
if [ -z " ${ disk_alerts_loadavg_enabled :- } " ] ; then
disk_alerts_loadavg_enabled = false
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= disk_alerts_loadavg_enabled --value= " $disk_alerts_loadavg_enabled "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=disk_alerts_loadavg_timeintvl --value=3600
2024-04-04 00:28:32 +02:00
if [ -z " ${ disk_alerts_loadavg_timeintvl :- } " ] ; then
disk_alerts_loadavg_timeintvl = 3600
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= disk_alerts_loadavg_timeintvl --value= " $disk_alerts_loadavg_timeintvl "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=disk_alerts_loadavg_threshold --value=98
2024-04-04 00:28:32 +02:00
if [ -z " ${ disk_alerts_loadavg_threshold :- } " ] ; then
disk_alerts_loadavg_threshold = 98
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= disk_alerts_loadavg_threshold --value= " $disk_alerts_loadavg_threshold "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=mail_delvd_enabled --value=n
2024-04-04 00:28:32 +02:00
if [ -z " ${ mail_delvd_enabled :- } " ] ; then
mail_delvd_enabled = n
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= mail_delvd_enabled --value= " $mail_delvd_enabled "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=mail_delvd_timeintvl --value=60
2024-04-04 00:28:32 +02:00
if [ -z " ${ mail_delvd_timeintvl :- } " ] ; then
mail_delvd_timeintvl = 60
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= mail_delvd_timeintvl --value= " $mail_delvd_timeintvl "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=mail_delvd_threshold --value=100
2024-04-04 00:28:32 +02:00
if [ -z " ${ mail_delvd_threshold :- } " ] ; then
mail_delvd_threshold = 100
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= mail_delvd_threshold --value= " $mail_delvd_threshold "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=mail_mqueued_enabled --value=n
2024-04-04 00:28:32 +02:00
if [ -z " ${ mail_mqueued_enabled :- } " ] ; then
mail_mqueued_enabled = n
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= mail_mqueued_enabled --value= " $mail_mqueued_enabled "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=mail_mqueued_timeintvl --value=3600
2024-04-04 00:28:32 +02:00
if [ -z " ${ mail_mqueued_timeintvl :- } " ] ; then
mail_mqueued_timeintvl = 3600
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= mail_mqueued_timeintvl --value= " $mail_mqueued_timeintvl "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=mail_mqueued_threshold --value=100
2024-04-04 00:28:32 +02:00
if [ -z " ${ mail_mqueued_threshold :- } " ] ; then
mail_mqueued_threshold = 100
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= mail_mqueued_threshold --value= " $mail_mqueued_threshold "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=emailreports_enabled --value=n
2024-04-04 00:28:32 +02:00
if [ -z " ${ emailreports_enabled :- } " ] ; then
emailreports_enabled = n
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= emailreports_enabled --value= " $emailreports_enabled "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=emailreports_subject_prefix --value='Monitorix:'
2024-04-04 00:28:32 +02:00
if [ -z " ${ emailreports_subject_prefix :- } " ] ; then
emailreports_subject_prefix = 'Monitorix:'
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= emailreports_subject_prefix --value= " $emailreports_subject_prefix "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=emailreports_hour --value=0
2024-04-04 00:28:32 +02:00
if [ -z " ${ emailreports_hour :- } " ] ; then
emailreports_hour = 0
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= emailreports_hour --value= " $emailreports_hour "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=emailreports_minute --value=0
2024-04-04 00:28:32 +02:00
if [ -z " ${ emailreports_minute :- } " ] ; then
emailreports_minute = 0
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= emailreports_minute --value= " $emailreports_minute "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=emailreports_daily_enabled --value=n
2024-04-04 00:28:32 +02:00
if [ -z " ${ emailreports_daily_enabled :- } " ] ; then
emailreports_daily_enabled = n
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= emailreports_daily_enabled --value= " $emailreports_daily_enabled "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=emailreports_daily_graphs --value='system,fs'
2024-04-04 00:28:32 +02:00
if [ -z " ${ emailreports_daily_graphs :- } " ] ; then
emailreports_daily_graphs = 'system,fs'
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= emailreports_daily_graphs --value= " $emailreports_daily_graphs "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=emailreports_daily_to --value="admins@$domain"
2024-04-04 00:28:32 +02:00
if [ -z " ${ emailreports_daily_to :- } " ] ; then
emailreports_daily_to = " admins@ $domain "
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= emailreports_daily_to --value= " $emailreports_daily_to "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=emailreports_weekly_enabled --value=n
2024-04-04 00:28:32 +02:00
if [ -z " ${ emailreports_weekly_enabled :- } " ] ; then
emailreports_weekly_enabled = n
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= emailreports_weekly_enabled --value= " $emailreports_weekly_enabled "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=emailreports_weekly_graphs --value='system,fs'
2024-04-04 00:28:32 +02:00
if [ -z " ${ emailreports_weekly_graphs :- } " ] ; then
emailreports_weekly_graphs = 'system,fs'
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= emailreports_weekly_graphs --value= " $emailreports_weekly_graphs "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=emailreports_weekly_to --value="admins@$domain"
2024-04-04 00:28:32 +02:00
if [ -z " ${ emailreports_weekly_to :- } " ] ; then
emailreports_weekly_to = " admins@ $domain "
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= emailreports_weekly_to --value= " $emailreports_weekly_to "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=emailreports_monthly_enabled --value=n
2024-04-04 00:28:32 +02:00
if [ -z " ${ emailreports_monthly_enabled :- } " ] ; then
emailreports_monthly_enabled = n
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= emailreports_monthly_enabled --value= " $emailreports_monthly_enabled "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=emailreports_monthly_graphs --value='system,fs'
2024-04-04 00:28:32 +02:00
if [ -z " ${ emailreports_monthly_graphs :- } " ] ; then
emailreports_monthly_graphs = 'system,fs'
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= emailreports_monthly_graphs --value= " $emailreports_monthly_graphs "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=emailreports_monthly_to --value="admins@$domain"
2024-04-04 00:28:32 +02:00
if [ -z " ${ emailreports_monthly_to :- } " ] ; then
emailreports_monthly_to = " admins@ $domain "
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= emailreports_monthly_to --value= " $emailreports_monthly_to "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=emailreports_yearly_enabled --value=n
2024-04-04 00:28:32 +02:00
if [ -z " ${ emailreports_yearly_enabled :- } " ] ; then
emailreports_yearly_enabled = n
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= emailreports_yearly_enabled --value= " $emailreports_yearly_enabled "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=emailreports_yearly_graphs --value='system,fs'
2024-04-04 00:28:32 +02:00
if [ -z " ${ emailreports_yearly_graphs :- } " ] ; then
emailreports_yearly_graphs = 'system,fs'
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= emailreports_yearly_graphs --value= " $emailreports_yearly_graphs "
2024-04-04 00:28:32 +02:00
fi
2024-08-31 01:07:34 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=emailreports_yearly_to --value="admins@$domain"
2024-04-04 00:28:32 +02:00
if [ -z " ${ emailreports_yearly_to :- } " ] ; then
emailreports_yearly_to = " admins@ $domain "
2024-08-31 01:07:34 +02:00
ynh_app_setting_set --key= emailreports_yearly_to --value= " $emailreports_yearly_to "
2024-04-04 00:28:32 +02:00
fi
2018-01-29 18:57:10 +01:00
}
set_permission( ) {
2024-04-04 00:28:32 +02:00
chown " $app " :root -R /etc/monitorix
2018-01-29 18:57:10 +01:00
chmod u = rX,g= rwX,o= -R /etc/monitorix
2024-04-04 00:28:32 +02:00
chown www-data:root -R " $nginx_status_conf "
chmod u = r,g= r,o= " $nginx_status_conf "
2024-08-31 01:07:34 +02:00
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app":root "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod u=rwX,g=rwX,o= -R "$install_dir"
2024-04-04 00:28:32 +02:00
chmod 750 " $install_dir " /monitorix-alert.sh
2024-08-31 01:07:34 +02:00
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app":root -R /var/log/"$app"
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod u=rwX,g=rwX,o= -R /var/log/"$app"
2024-04-04 00:28:32 +02:00
chmod u = rwx,g= rx,o= " $data_dir "
chown " $app " :www-data " $data_dir "
2023-12-09 00:35:51 +01:00
2024-08-31 01:07:34 +02:00
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod u=rwx,g=rx,o= "$data_dir"/*.rrd || true
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app":root "$data_dir"/*.rrd || true
2024-04-04 00:28:32 +02:00
find " $data_dir " /{ reports,usage} \( \! -perm -o= \
-o \! -user " $app " \
-o \! -group " $app " \) \
-exec chown " $app : $app " { } \; \
-exec chmod o = { } \;
2023-12-09 00:35:51 +01:00
2024-04-04 00:28:32 +02:00
find " $data_dir " /www \( \! -perm -o= \
-o \! -perm -g= rX \
-o \! -user " $app " \
-o \! -group www-data \) \
-exec chown " $app :www-data " { } \; \
-exec chmod g+rX,o= { } \;
2023-12-09 00:35:51 +01:00
}