Browse Source

Merge pull request #147 from YunoHost-Apps/fix-logrotate-side-effects

Fix logrotate side effects
HgO 1 month ago
parent
commit
61305171ea
6 changed files with 35 additions and 20 deletions
  1. 2 2
      conf/openvpn_client.conf.tpl
  2. 8 8
      conf/ynh-vpnclient
  3. 2 2
      scripts/_common.sh
  4. 2 3
      scripts/install
  5. 1 2
      scripts/restore
  6. 20 3
      scripts/upgrade

+ 2 - 2
conf/openvpn_client.conf.tpl

@@ -34,8 +34,8 @@ __CERT_COMMENT__key /etc/openvpn/keys/user.key
 # Logs
 # Logs
 verb 3
 verb 3
 mute 5
 mute 5
-status /var/log/openvpn-client.status
+status /var/log/vpnclient/openvpn-client.status
-log-append /var/log/openvpn-client.log
+log-append /var/log/vpnclient/openvpn-client.log
 
 
 # Routing
 # Routing
 route-ipv6 2000::/3
 route-ipv6 2000::/3

+ 8 - 8
conf/ynh-vpnclient

@@ -21,7 +21,7 @@
 # Logging helpers                                                                 #
 # Logging helpers                                                                 #
 ###################################################################################
 ###################################################################################
 
 
-LOGFILE="/var/log/ynh-vpnclient.log"
+LOGFILE="/var/log/vpnclient/ynh-vpnclient.log"
 touch $LOGFILE
 touch $LOGFILE
 chown root:root $LOGFILE
 chown root:root $LOGFILE
 chmod 600 $LOGFILE
 chmod 600 $LOGFILE
@@ -187,15 +187,15 @@ case "$action" in
     if systemctl start openvpn@client.service; then
     if systemctl start openvpn@client.service; then
       success "OpenVPN client started!"
       success "OpenVPN client started!"
     else
     else
-      tail -n 20 /var/log/openvpn-client.log | tee -a $LOGFILE
+      tail -n 20 /var/log/vpnclient/openvpn-client.log | tee -a $LOGFILE
 	    critical "Failed to start OpenVPN client"
 	    critical "Failed to start OpenVPN client"
     fi
     fi
 
 
     info "Waiting for tun0 interface to show up"
     info "Waiting for tun0 interface to show up"
-    openvpn_log_start=$(find_last_line_number "process exiting" /var/log/openvpn-client.log)
+    openvpn_log_start=$(find_last_line_number "process exiting" /var/log/vpnclient/openvpn-client.log)
-    if ! timeout 180 tail -n-${openvpn_log_start} -f /var/log/openvpn-client.log 2>/dev/null | grep -q "TUN/TAP device tun0 opened"; then
+    if ! timeout 180 tail -n-${openvpn_log_start} -f /var/log/vpnclient/openvpn-client.log 2>/dev/null | grep -q "TUN/TAP device tun0 opened"; then
       error "The VPN client didn't open tun0 interface"
       error "The VPN client didn't open tun0 interface"
-      tail -n 20 /var/log/openvpn-client.log | tee -a $LOGFILE
+      tail -n 20 /var/log/vpnclient/openvpn-client.log | tee -a $LOGFILE
       critical "Failed to start OpenVPN client"
       critical "Failed to start OpenVPN client"
     fi
     fi
 
 
@@ -203,14 +203,14 @@ case "$action" in
       success "tun0 interface is up!"
       success "tun0 interface is up!"
     else
     else
       error "tun0 interface did not show up, most likely an issue happening in OpenVPN client"
       error "tun0 interface did not show up, most likely an issue happening in OpenVPN client"
-      tail -n 20 /var/log/openvpn-client.log | tee -a $LOGFILE
+      tail -n 20 /var/log/vpnclient/openvpn-client.log | tee -a $LOGFILE
       critical "Failed to start OpenVPN client"
       critical "Failed to start OpenVPN client"
     fi
     fi
 
 
     info "Waiting for VPN client to be ready..."
     info "Waiting for VPN client to be ready..."
-    if ! timeout 180 tail -n-${openvpn_log_start} -f /var/log/openvpn-client.log 2>/dev/null | grep -q "Initialization Sequence Completed"; then
+    if ! timeout 180 tail -n-${openvpn_log_start} -f /var/log/vpnclient/openvpn-client.log 2>/dev/null | grep -q "Initialization Sequence Completed"; then
       error "The VPN client didn't complete initiliasation"
       error "The VPN client didn't complete initiliasation"
-      tail -n 20 /var/log/openvpn-client.log | tee -a $LOGFILE
+      tail -n 20 /var/log/vpnclient/openvpn-client.log | tee -a $LOGFILE
       critical "Failed to start OpenVPN client"
       critical "Failed to start OpenVPN client"
     fi
     fi
 
 

+ 2 - 2
scripts/_common.sh

@@ -188,14 +188,14 @@ function convert_ovpn_file()
   sed -i 's@^\s*key\s.*$@key /etc/openvpn/keys/user.key@g' ${config_file}
   sed -i 's@^\s*key\s.*$@key /etc/openvpn/keys/user.key@g' ${config_file}
   sed -i 's@^\s*tls-auth\s.*$@tls-auth /etc/openvpn/keys/user_ta.key 1@g' ${config_file}
   sed -i 's@^\s*tls-auth\s.*$@tls-auth /etc/openvpn/keys/user_ta.key 1@g' ${config_file}
 
 
-  status="status /var/log/openvpn-client.status"
+  status="status /var/log/vpnclient/openvpn-client.status"
   if grep -q '^\s*status\s.*$' ${config_file}; then
   if grep -q '^\s*status\s.*$' ${config_file}; then
     sed -i "s@^\s*status\s.*\$@$status@g" ${config_file}
     sed -i "s@^\s*status\s.*\$@$status@g" ${config_file}
   else
   else
     echo "$status" >> ${config_file}
     echo "$status" >> ${config_file}
   fi
   fi
 
 
-  log_append="log-append /var/log/openvpn-client.log"
+  log_append="log-append /var/log/vpnclient/openvpn-client.log"
   if grep -E -q '^\s*log(-append)?\s.*$' ${config_file}; then
   if grep -E -q '^\s*log(-append)?\s.*$' ${config_file}; then
     sed -E -i "s@^\s*log(-append)?\s.*\$@$log_append@g" ${config_file}
     sed -E -i "s@^\s*log(-append)?\s.*\$@$log_append@g" ${config_file}
   else
   else

+ 2 - 3
scripts/install

@@ -31,11 +31,10 @@ systemctl stop openvpn
 
 
 # main service
 # main service
 
 
-yunohost service add $service_name --description "Tunnels the internet traffic through a VPN" --need_lock --test_status="systemctl is-active openvpn@client.service" --log "/var/log/ynh-vpnclient.log"
+yunohost service add $service_name --description "Tunnels the internet traffic through a VPN" --need_lock --test_status="systemctl is-active openvpn@client.service" --log "/var/log/vpnclient/ynh-vpnclient.log"
 yunohost service enable $service_name
 yunohost service enable $service_name
 
 
-ynh_config_add_logrotate "/var/log/ynh-vpnclient.log"
+ynh_config_add_logrotate
-ynh_config_add_logrotate "/var/log/openvpn-client.log"
 
 
 # checker service
 # checker service
 
 

+ 1 - 2
scripts/restore

@@ -27,8 +27,7 @@ systemctl stop openvpn
 yunohost service add $service_name --description "Tunnels the internet traffic through a VPN" --need_lock --test_status="systemctl is-active openvpn@client.service" --log "/var/log/ynh-vpnclient.log"
 yunohost service add $service_name --description "Tunnels the internet traffic through a VPN" --need_lock --test_status="systemctl is-active openvpn@client.service" --log "/var/log/ynh-vpnclient.log"
 yunohost service enable "$service_name"
 yunohost service enable "$service_name"
 
 
-ynh_config_add_logrotate "/var/log/ynh-vpnclient.log"
+ynh_config_add_logrotate
-ynh_config_add_logrotate "/var/log/openvpn-client.log"
 
 
 # checker service
 # checker service
 
 

+ 20 - 3
scripts/upgrade

@@ -44,6 +44,13 @@ if [ -e "/etc/openvpn/client.conf.tpl" ]; then
   ynh_safe_rm "/etc/openvpn/client.conf.tpl"
   ynh_safe_rm "/etc/openvpn/client.conf.tpl"
 fi
 fi
 
 
+# Fixing incorrect logrotate config
+if grep -q -e "/var/log/ynh-vpnclient.log" -e "/var/log/openvpn-client.log" "/etc/logrotate.d/$app"; then
+  ynh_config_remove_logrotate
+  chmod 0755 /var/log
+  chown root:root /var/log
+fi
+
 # New stuff
 # New stuff
 
 
 ynh_app_setting_set_default --key="dns_method" --value="custom"
 ynh_app_setting_set_default --key="dns_method" --value="custom"
@@ -114,10 +121,20 @@ ynh_safe_rm "${tmp_dir}"
 ynh_print_info "Configuring VPN client services..."
 ynh_print_info "Configuring VPN client services..."
 
 
 # main service
 # main service
-yunohost service add $service_name --description "Tunnels the internet traffic through a VPN" --need_lock --test_status="systemctl is-active openvpn@client.service" --log "/var/log/ynh-vpnclient.log"
+yunohost service add $service_name --description "Tunnels the internet traffic through a VPN" --need_lock --test_status="systemctl is-active openvpn@client.service" --log "/var/log/$app/ynh-vpnclient.log"
+
+ynh_config_add_logrotate
 
 
-ynh_config_add_logrotate "/var/log/ynh-vpnclient.log"
+# Moving log files from legacy location
-ynh_config_add_logrotate "/var/log/openvpn-client.log"
+if [[ -e "/var/log/openvpn-client.log" ]]; then
+  mv "/var/log/openvpn-client.log" "/var/log/$app/"
+fi
+if [[ -e "/var/log/openvpn-client.status" ]]; then
+  mv "/var/log/openvpn-client.status" "/var/log/$app/"
+fi
+if [[ -e "/var/log/ynh-vpnclient.log" ]]; then
+  mv "/var/log/ynh-vpnclient.log" "/var/log/$app/"
+fi
 
 
 # checker service (this service was previously integrated in yunohost but we do not do this anymore)
 # checker service (this service was previously integrated in yunohost but we do not do this anymore)
 if ynh_hide_warnings yunohost service status $service_checker_name >/dev/null
 if ynh_hide_warnings yunohost service status $service_checker_name >/dev/null