2017-01-05 23:37:07 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Import common cmd
|
|
|
|
source ./_common.sh
|
|
|
|
|
|
|
|
# Init script
|
|
|
|
init_script
|
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path=$YNH_APP_ARG_PATH
|
|
|
|
|
|
|
|
# Correct path if it is not correct
|
2017-01-31 21:26:13 +01:00
|
|
|
CHECK_PATH
|
2017-01-05 23:37:07 +01:00
|
|
|
|
|
|
|
# Check domain/path availability
|
|
|
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
|
|
|
|| ynh_die "Path not available: ${domain}${path}"
|
|
|
|
|
|
|
|
# Download package
|
|
|
|
get_source
|
|
|
|
|
|
|
|
# Install package
|
|
|
|
ynh_package_update
|
|
|
|
ynh_package_install rrdtool perl libwww-perl libmailtools-perl libmime-lite-perl librrds-perl libdbi-perl libxml-simple-perl libhttp-server-simple-perl libconfig-general-perl pflogsumm
|
|
|
|
sudo dpkg -i /tmp/monitorix.deb
|
|
|
|
sudo rm -rf /etc/monitorix/conf.d/00-debian.conf
|
|
|
|
ynh_package_install -f
|
|
|
|
|
|
|
|
# # Generate MySQL password and create database
|
|
|
|
dbuser=$app
|
|
|
|
dbname=$app
|
|
|
|
dbpass=$(ynh_string_random 12)
|
|
|
|
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
|
|
|
|
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
|
|
|
|
|
|
|
# Find a port for built-in monitorix HTTP server
|
2017-02-13 16:17:53 +01:00
|
|
|
NO_LOG FIND_PORT 8080
|
2017-01-05 23:37:07 +01:00
|
|
|
http_port=$port
|
|
|
|
ynh_app_setting_set $app http_port $http_port
|
2017-02-13 16:17:53 +01:00
|
|
|
NO_LOG FIND_PORT $(($port +1))
|
2017-01-05 23:37:07 +01:00
|
|
|
nginx_status_port=$port
|
|
|
|
ynh_app_setting_set $app nginx_status_port $nginx_status_port
|
|
|
|
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
|
|
nginx_conf=../conf/nginx.conf
|
|
|
|
sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf
|
|
|
|
sed -i "s@SERVICE_PORT@$http_port@g" $nginx_conf
|
|
|
|
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
|
|
|
|
# Add special hostname for monitorix status
|
|
|
|
nginx_status_conf=../conf/nginx_status.conf
|
|
|
|
sed -i "s@PORT@$nginx_status_port@g" $nginx_status_conf
|
|
|
|
sudo cp $nginx_status_conf /etc/nginx/conf.d/monitorix_status.conf
|
|
|
|
|
|
|
|
# Update monitorix configuration
|
|
|
|
monitorix_conf=../conf/monitorix.conf
|
|
|
|
sed -i "s@SERVICE_PORT@$http_port@g" $monitorix_conf
|
|
|
|
sed -i "s@YNH_DOMAIN@$domain@g" $monitorix_conf
|
|
|
|
sed -i "s@NGINX_STATUS_PORT@$nginx_status_port@g" $monitorix_conf
|
|
|
|
sed -i "s@YNH_WWW_PATH@$path@g" $monitorix_conf
|
|
|
|
sed -i "s@MYSQL_USER@$dbuser@g" $monitorix_conf
|
|
|
|
sed -i "s@MYSQL_PASSWORD@$dbpass@g" $monitorix_conf
|
|
|
|
sudo cp $monitorix_conf /etc/monitorix/monitorix.conf
|
|
|
|
|
|
|
|
# Reload services
|
|
|
|
sudo service nginx reload
|
|
|
|
sudo service monitorix restart
|