From fc8927e00cbc561c4ea1dafdae988aea654c830d Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Mon, 29 Jan 2018 23:42:11 -0500 Subject: [PATCH] Ticket 49548 - Cockpit UI - installer should also setup Cockpit Description: Add option to installer to also configure Cockpit: - Add port to firewall (if running), - Enable/start the Cockpit socket. https://pagure.io/389-ds-base/issue/49548 Reviewed by: ? --- src/lib389/cli/ds-cockpit-setup | 64 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/src/lib389/cli/ds-cockpit-setup b/src/lib389/cli/ds-cockpit-setup index a72208520..5fcce5c2f 100755 --- a/src/lib389/cli/ds-cockpit-setup +++ b/src/lib389/cli/ds-cockpit-setup @@ -30,6 +30,8 @@ if __name__ == '__main__': print ("You need to install the 'cockpit' package before installing the UI plugin") sys.exit(1) + # We also need cockpit-dashboard + # Check the server's cockpit plugin exists if not os.path.isdir(cockpit_plugin): print ("Can not find cockpit UI plugin under '/usr/share/dirsrv'") @@ -43,6 +45,9 @@ if __name__ == '__main__': parser.add_argument('-i', '--install', help="Install the cockpit plugin (must be root)", action='store_true', dest='install', default=False) + parser.add_argument('-c', '--cockpit', + help="Enable Cockpit on the system", + action='store_true', dest='enable_cockpit', default=False) parser.add_argument('-t', '--testing', help="Install the cockpit plugin under users's home directory for testing (~/.local/share/cockpit)", action='store_true', dest='testing', default=False) @@ -106,6 +111,63 @@ if __name__ == '__main__': print("Failed to install cockpit plugin: " + str(e)) sys.exit(1) + # Setup and Enabled Cockpit + if options.enable_cockpit: + firewall = False + print ("Enabling Cockpit...") + + # Is the firewall running + if options.verbose: + print("Checking firewall...") + try: + cmd = ["firewall-cmd", "--state",] + subprocess.check_call(cmd, stdout=subprocess.PIPE) + firewall = True + except: + print ("Firewall not running") + + + # Configure firewall for port 9090 and set it permanent + if firewall: + if options.verbose: + print("Opening port 9090 in firewall...") + try: + cmd = ["firewall-cmd", "--add-port=9090/tcp",] + subprocess.check_call(cmd, stdout=subprocess.PIPE) + except: + print ("Failed to add port 9090 to the firewall") + sys.exit(1) + + if options.verbose: + print("Setting 9090 permanent in firewall...") + try: + cmd = ["firewall-cmd", "--permanent","--add-port=9090/tcp"] + subprocess.check_call(cmd, stdout=subprocess.PIPE) + except: + print ("Failed to add port 9090 to the firewall") + sys.exit(1) + + # Enable and start Cockpit socket + if options.verbose: + print("Enabling Cockpit socket...") + try: + cmd = ["systemctl", "enable","cockpit.socket"] + subprocess.check_call(cmd, stdout=subprocess.PIPE) + except: + print ("Failed to enable cockpit socket") + sys.exit(1) + + if options.verbose: + print("Starting Cockpit socket...") + try: + cmd = ["systemctl", "start","cockpit.socket"] + subprocess.check_call(cmd, stdout=subprocess.PIPE) + except: + print ("Failed to enable cockpit socket") + sys.exit(1) + + print("Cockpit has been enabled and started.") + # Done! print("Installation is complete!") - print("Open UI with this URL: http://{}:9090/389-console".format(socket.getfqdn())) + print("Open UI with this URL: http://{}:9090/".format(socket.getfqdn())) -- 2.13.6