root/IoTa-Installer/lib/tomcat.py @ 96454bcd
2e0a7cb1 | Sylvain L. Sauvage | # -*- coding: utf-8 -*-
|
|
#
|
|||
# This program is a part of the IoTa project.
|
|||
#
|
|||
# Copyright © 2012 Université de Caen Basse-Normandie, GREYC
|
|||
#
|
|||
# This program is free software: you can redistribute it and/or modify
|
|||
# it under the terms of the GNU General Public License as published by
|
|||
# the Free Software Foundation, either version 3 of the License, or
|
|||
# (at your option) any later version.
|
|||
#
|
|||
# This program is distributed in the hope that it will be useful,
|
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|||
# GNU General Public License for more details.
|
|||
# <http://www.gnu.org/licenses/>
|
|||
#
|
|||
# See AUTHORS for a list of contributors.
|
|||
#
|
|||
import os
|
|||
import shutil
|
|||
import xml.dom.minidom
|
|||
import utils
|
|||
import installer
|
|||
class TomcatInstaller(installer.Installer):
|
|||
def __init__(self):
|
|||
installer.Installer.__init__(self, "Apache Tomcat", "tomcat", [
|
|||
("Enter the archive file pathname", "tomcat", "repo",
|
|||
{"when": ("tomcat", "install"), "type": "file"}),
|
|||
("Enter the path where you want to unpack it", "tomcat", "directory",
|
|||
{"when": ("tomcat", "install"), "type": "path"}),
|
|||
("Enter the name of the directory", "tomcat", "name",
|
|||
{"when": ("tomcat", "install")}),
|
|||
("Enter the Catalina Home directory", "tomcat", "catalina_home",
|
|||
{"unless": ("tomcat", "install"), "type": "path"}),
|
|||
96454bcd | Sylvain L. Sauvage | ("Enter the HTTP port", "tomcat", "http_port", {}),
|
|
("Enter the server shutdown port", "tomcat", "shutdown_port",
|
|||
{"when": ("tomcat", "install")}),
|
|||
("Enter the AJP port", "tomcat", "ajp_port",
|
|||
{"when": ("tomcat", "install")}),
|
|||
("Enter the redirect port", "tomcat", "redirect_port",
|
|||
{"when": ("tomcat", "install")}),
|
|||
("Use the manager webapp?", "tomcat", "use_manager", {"type": "YN"}),
|
|||
("Enter the manager’s path", "tomcat", "manager_path",
|
|||
{"when": ("tomcat", "use_manager")}),
|
|||
("Enter the manager’s login (manager or manager-script role)", "tomcat", "login",
|
|||
{"when": ("tomcat", "use_manager")}),
|
|||
("Enter the manager’s password", "tomcat", "password",
|
|||
{"when": ("tomcat", "use_manager")}),
|
|||
2e0a7cb1 | Sylvain L. Sauvage | ("Is autodeploy enabled?", "tomcat", "autodeploy",
|
|
{"unless": ("tomcat", "install"), "type": "YN"})
|
|||
])
|
|||
def postConfigure(self):
|
|||
catalina_home = ""
|
|||
if self.installp:
|
|||
96454bcd | Sylvain L. Sauvage | tomcat_repo = self.cget("repo")
|
|
tomcat_dir = self.cget("directory")
|
|||
tomcat_name = self.cget("name")
|
|||
2e0a7cb1 | Sylvain L. Sauvage | catalina_home = tomcat_dir + tomcat_name + "/"
|
|
96454bcd | Sylvain L. Sauvage | self.cset("catalina_home", catalina_home)
|
|
2e0a7cb1 | Sylvain L. Sauvage | utils.putMessage("The Catalina Home directory will be: " + catalina_home)
|
|
else:
|
|||
96454bcd | Sylvain L. Sauvage | catalina_home = self.cget("catalina_home")
|
|
self.cset("name", catalina_home.rstrip("/").rpartition("/")[2])
|
|||
2e0a7cb1 | Sylvain L. Sauvage | ||
def postUnpack(self):
|
|||
utils.putWait("Configuring Apache Tomcat’s ports")
|
|||
96454bcd | Sylvain L. Sauvage | serverConfigFile = self.cget("catalina_home") + "conf/server.xml"
|
|
2e0a7cb1 | Sylvain L. Sauvage | doc = xml.dom.minidom.parse(serverConfigFile)
|
|
configuration = doc.getElementsByTagName("Server")[0]
|
|||
96454bcd | Sylvain L. Sauvage | configuration.setAttribute("port", self.cget("shutdown_port"))
|
|
2e0a7cb1 | Sylvain L. Sauvage | properties = configuration.getElementsByTagName("Connector")
|
|
for prop in properties:
|
|||
if prop.getAttribute("protocol") == "HTTP/1.1":
|
|||
96454bcd | Sylvain L. Sauvage | prop.setAttribute("port", self.cget("http_port"))
|
|
prop.setAttribute("redirectPort", self.cget("redirect_port"))
|
|||
2e0a7cb1 | Sylvain L. Sauvage | elif prop.getAttribute("protocol") == "AJP/1.3":
|
|
96454bcd | Sylvain L. Sauvage | prop.setAttribute("port", self.cget("ajp_port"))
|
|
prop.setAttribute("redirectPort", self.cget("redirect_port"))
|
|||
2e0a7cb1 | Sylvain L. Sauvage | with open(serverConfigFile, "w") as scf:
|
|
scf.write(doc.toxml())
|
|||
utils.putDoneOK()
|
|||
96454bcd | Sylvain L. Sauvage | if self.cisTrue("use_manager"):
|
|
2e0a7cb1 | Sylvain L. Sauvage | utils.putWait("Configuring Apache Tomcat’s managering account")
|
|
96454bcd | Sylvain L. Sauvage | usersConfigFile = self.cget("catalina_home") + "conf/tomcat-users.xml"
|
|
2e0a7cb1 | Sylvain L. Sauvage | doc = xml.dom.minidom.parse(usersConfigFile)
|
|
configuration = doc.getElementsByTagName("tomcat-users")[0]
|
|||
role = doc.createElement("role")
|
|||
role.setAttribute("rolename", "manager-script")
|
|||
configuration.appendChild(role)
|
|||
role = doc.createElement("role")
|
|||
role.setAttribute("rolename", "manager")
|
|||
configuration.appendChild(role)
|
|||
user = doc.createElement("user")
|
|||
96454bcd | Sylvain L. Sauvage | user.setAttribute("username", self.cget("login"))
|
|
user.setAttribute("password", self.cget("password"))
|
|||
2e0a7cb1 | Sylvain L. Sauvage | user.setAttribute("roles", "manager,manager-script")
|
|
configuration.appendChild(user)
|
|||
with open(usersConfigFile, "w") as scf:
|
|||
scf.write(doc.toxml())
|
|||
utils.putDoneOK()
|
|||
def install(self):
|
|||
# try to install
|
|||
if not installer.Installer.install(self):
|
|||
# else, get infos
|
|||
self.configure()
|
|||
utils.startTomcat()
|