mirror of
https://github.com/YunoHost-Apps/netdata_ynh.git
synced 2024-09-03 19:46:33 +02:00
Configure web_logs based on YunoHost domains:
- add existing domains at installation - add hooks to process added/removed domains
This commit is contained in:
parent
cc25c1f921
commit
586b1f63cc
5 changed files with 44 additions and 0 deletions
12
hooks/post_domain_add
Normal file
12
hooks/post_domain_add
Normal file
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Retrieve arguments
|
||||
domain=$1
|
||||
domain_label=${domain//\./_} # Replace "." by "_" for the domain label
|
||||
# Add a web_log entry for this new domain
|
||||
cat >> /opt/netdata/etc/netdata/python.d/web_log.conf <<EOF
|
||||
${domain_label}_log:
|
||||
name: '${domain_label}'
|
||||
path: '/var/log/nginx/$domain-access.log'
|
||||
|
||||
EOF
|
10
hooks/post_domain_remove
Normal file
10
hooks/post_domain_remove
Normal file
|
@ -0,0 +1,10 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Retrieve arguments
|
||||
domain=$1
|
||||
|
||||
# Look for the domain entry, and delete the related lines
|
||||
# by deleting every line between:
|
||||
# - the domain label (with "." replaced by "_")
|
||||
# - and the domain file specification (need to replace "." by "\." in order not to get interpreted by sed)
|
||||
sed --in-place "/${domain//\./_}_log/,/${domain//\./\\\.}/d" /opt/netdata/etc/netdata/python.d/web_log.conf
|
|
@ -32,6 +32,20 @@ configure_netdata() {
|
|||
mv ./netdata-uninstaller.sh /opt/netdata/etc/netdata
|
||||
}
|
||||
|
||||
# Add a web_log entry for every YunoHost domain
|
||||
netdata_add_yunohost_web_logs () {
|
||||
echo "# ------------YUNOHOST DOMAINS---------------" >> /opt/netdata/etc/netdata/python.d/web_log.conf
|
||||
for domain in $(yunohost domain list --output-as plain); do
|
||||
domain_label=${domain//\./_} # Replace "." by "_" for the domain label
|
||||
cat >> /opt/netdata/etc/netdata/python.d/web_log.conf <<EOF
|
||||
${domain_label}_log:
|
||||
name: '${domain_label}'
|
||||
path: '/var/log/nginx/$domain-access.log'
|
||||
|
||||
EOF
|
||||
done
|
||||
}
|
||||
|
||||
# ============= FUTURE YUNOHOST HELPER =============
|
||||
# Delete a file checksum from the app settings
|
||||
#
|
||||
|
|
|
@ -93,6 +93,9 @@ ynh_add_nginx_config
|
|||
pushd $NETDATA_TMPDIR
|
||||
./netdata-installer.sh --install /opt --dont-wait
|
||||
|
||||
# Add a web_log entry for every YunoHost domain
|
||||
netdata_add_yunohost_web_logs
|
||||
|
||||
configure_netdata
|
||||
|
||||
# Store the app.src file
|
||||
|
|
|
@ -91,6 +91,11 @@ exec 3>${tmp}
|
|||
pushd $NETDATA_TMPDIR
|
||||
./netdata-installer.sh --install /opt --dont-wait >&3 2>&3 || ynh_die "FAILED TO COMPILE/INSTALL NETDATA"
|
||||
|
||||
# If YunoHost web logs have never been set in netdata configuration, set them
|
||||
if [ -z "$(grep "YUNOHOST" /opt/netdata/etc/netdata/python.d/web_log.conf)" ] ; then
|
||||
netdata_add_yunohost_web_logs
|
||||
fi
|
||||
|
||||
configure_netdata
|
||||
|
||||
# Store the app.src file
|
||||
|
|
Loading…
Add table
Reference in a new issue