← Back to team overview

nagios-charmers team mailing list archive

[Merge] ~xavpaice/charm-nagios:bug/1819537 into charm-nagios:master

 

Xav Paice has proposed merging ~xavpaice/charm-nagios:bug/1819537 into charm-nagios:master.

Requested reviews:
  Nagios Charm developers (nagios-charmers)
Related bugs:
  Bug #1819537 in Nagios Charm: "config-changed hook fails with enable_livestatus enabled"
  https://bugs.launchpad.net/charm-nagios/+bug/1819537

For more details, see:
https://code.launchpad.net/~xavpaice/charm-nagios/+git/nagios-charm/+merge/391667
-- 
Your team Nagios Charm developers is requested to review the proposed merge of ~xavpaice/charm-nagios:bug/1819537 into charm-nagios:master.
diff --git a/hooks/upgrade_charm.py b/hooks/upgrade_charm.py
index 4152e53..37d73ba 100755
--- a/hooks/upgrade_charm.py
+++ b/hooks/upgrade_charm.py
@@ -12,6 +12,7 @@ import shutil
 import stat
 import string
 import subprocess
+import time
 
 try:
     from enum import Enum  # noqa: F401
@@ -171,32 +172,33 @@ def fixpath(path):
 
 
 def enable_livestatus_config():
-    if enable_livestatus:
-        hookenv.log("Livestatus is enabled")
-        fetch.apt_update()
-        fetch.apt_install("check-mk-livestatus")
-
-        # Make the directory and fix perms on it
-        hookenv.log("Fixing perms on livestatus_path")
-        livestatus_dir = os.path.dirname(livestatus_path)
-
-        if not os.path.isdir(livestatus_dir):
-            hookenv.log("Making path for livestatus_dir")
-            mkdir_p(livestatus_dir)
-        fixpath(livestatus_dir)
-
-        # Fix the perms on the socket
-        hookenv.log("Fixing perms on the socket")
-        uid = pwd.getpwnam(nagios_user).pw_uid
-        gid = grp.getgrnam("www-data").gr_gid
-        os.chown(livestatus_path, uid, gid)
-        os.chown(livestatus_dir, uid, gid)
-        st = os.stat(livestatus_path)
-        os.chmod(livestatus_path, st.st_mode | stat.S_IRGRP)
-        os.chmod(
-            livestatus_dir,
-            st.st_mode | stat.S_IRGRP | stat.S_ISGID | stat.S_IXUSR | stat.S_IXGRP,
-        )
+    livestatus_dir = os.path.dirname(livestatus_path)
+    hookenv.log("Livestatus is enabled")
+    if not os.path.isdir(livestatus_dir):
+        hookenv.log("Making path for livestatus_dir")
+        mkdir_p(livestatus_dir)
+    # fix perms on livestatus dir
+    hookenv.log("Fixing perms on livestatus_path")
+    fixpath(livestatus_dir)
+    fetch.apt_update()
+    install_packages = fetch.filter_installed_packages(["check-mk-livestatus"])
+    if install_packages:
+        fetch.apt_install()
+        # This needs a nagios restart to actually make the socket
+        host.service_reload("nagios3")
+
+    # Fix the perms on the socket
+    hookenv.log("Fixing perms on the socket")
+    uid = pwd.getpwnam(nagios_user).pw_uid
+    gid = grp.getgrnam("www-data").gr_gid
+    os.chown(livestatus_path, uid, gid)
+    os.chown(livestatus_dir, uid, gid)
+    st = os.stat(livestatus_path)
+    os.chmod(livestatus_path, st.st_mode | stat.S_IRGRP)
+    os.chmod(
+        livestatus_dir,
+        st.st_mode | stat.S_IRGRP | stat.S_ISGID | stat.S_IXUSR | stat.S_IXGRP,
+    )
 
 
 def enable_pagerduty_config():
@@ -627,7 +629,6 @@ if ssl_configured():
 enable_pagerduty_config()
 update_contacts()
 update_config()
-enable_livestatus_config()
 update_apache()
 update_localhost()
 update_cgi_config()
@@ -639,6 +640,8 @@ if password:
 
 if nagiosadmin != "nagiosadmin":
     update_password("nagiosadmin", False)
+if enable_livestatus:
+    enable_livestatus_config()
 
 subprocess.call(["scripts/postfix_loopback_only.sh"])
 subprocess.call(["hooks/mymonitors-relation-joined"])

Follow ups