Parcourir la source

Merge pull request #148 from YunoHost-Apps/testing

Testing | Fix logrotate side effects
HgO il y a 1 semaine
Parent
commit
d3a32bae05
8 fichiers modifiés avec 37 ajouts et 22 suppressions
  1. 1 1
      README.md
  2. 2 2
      conf/openvpn_client.conf.tpl
  3. 8 8
      conf/ynh-vpnclient
  4. 1 1
      manifest.toml
  5. 2 2
      scripts/_common.sh
  6. 2 3
      scripts/install
  7. 1 2
      scripts/restore
  8. 20 3
      scripts/upgrade

+ 1 - 1
README.md

@@ -11,7 +11,7 @@ It shall NOT be edited by hand.
 Tunnel the internet traffic through a VPN
 
 [![🌐 Official app website](https://img.shields.io/badge/Official_app_website-darkgreen?style=for-the-badge)](https://labriqueinter.net)
-[![Version: 2.3~ynh2](https://img.shields.io/badge/Version-2.3~ynh2-rgba(0,150,0,1)?style=for-the-badge)](https://ci-apps.yunohost.org/ci/apps/vpnclient/)
+[![Version: 2.3~ynh3](https://img.shields.io/badge/Version-2.3~ynh3-rgba(0,150,0,1)?style=for-the-badge)](https://ci-apps.yunohost.org/ci/apps/vpnclient/)
 
 <div align="center">
 <a href="https://apps.yunohost.org/app/vpnclient"><img height="100px" src="https://github.com/YunoHost/yunohost-artwork/raw/refs/heads/main/badges/neopossum-badges/badge_more_info_on_the_appstore.svg"/></a>

+ 2 - 2
conf/openvpn_client.conf.tpl

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

+ 8 - 8
conf/ynh-vpnclient

@@ -21,7 +21,7 @@
 # Logging helpers                                                                 #
 ###################################################################################
 
-LOGFILE="/var/log/ynh-vpnclient.log"
+LOGFILE="/var/log/vpnclient/ynh-vpnclient.log"
 touch $LOGFILE
 chown root:root $LOGFILE
 chmod 600 $LOGFILE
@@ -187,15 +187,15 @@ case "$action" in
     if systemctl start openvpn@client.service; then
       success "OpenVPN client started!"
     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"
     fi
 
     info "Waiting for tun0 interface to show up"
-    openvpn_log_start=$(find_last_line_number "process exiting" /var/log/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
+    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/vpnclient/openvpn-client.log 2>/dev/null | grep -q "TUN/TAP device tun0 opened"; then
       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"
     fi
 
@@ -203,14 +203,14 @@ case "$action" in
       success "tun0 interface is up!"
     else
       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"
     fi
 
     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"
-      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"
     fi
 

+ 1 - 1
manifest.toml

@@ -7,7 +7,7 @@ name = "VPN Client"
 description.en = "Tunnel the internet traffic through a VPN"
 description.fr = "Fait passer le trafic internet à travers un VPN"
 
-version = "2.3~ynh2"
+version = "2.3~ynh3"
 
 maintainers = []
 

+ 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*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
     sed -i "s@^\s*status\s.*\$@$status@g" ${config_file}
   else
     echo "$status" >> ${config_file}
   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
     sed -E -i "s@^\s*log(-append)?\s.*\$@$log_append@g" ${config_file}
   else

+ 2 - 3
scripts/install

@@ -31,11 +31,10 @@ systemctl stop openvpn
 
 # 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
 
-ynh_config_add_logrotate "/var/log/ynh-vpnclient.log"
-ynh_config_add_logrotate "/var/log/openvpn-client.log"
+ynh_config_add_logrotate
 
 # 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 enable "$service_name"
 
-ynh_config_add_logrotate "/var/log/ynh-vpnclient.log"
-ynh_config_add_logrotate "/var/log/openvpn-client.log"
+ynh_config_add_logrotate
 
 # 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"
 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
 
 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..."
 
 # 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"
-ynh_config_add_logrotate "/var/log/openvpn-client.log"
+# Moving log files from legacy location
+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)
 if ynh_hide_warnings yunohost service status $service_checker_name >/dev/null