<?xml version="1.0"?> <metainfo> <schemaVersion>2.0</schemaVersion> <services> <service> <!-- Internal name for service (must be unique) --> <name>TOMCAT</name> <!-- display name in Ambari UI --> <displayName>TOMCAT</displayName> <!-- Description of service - will be displayed when user clicks add service --> <comment>Apache Tomcat™ is an open source software implementation of the Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies</comment> <!-- Version of component--> <version>7.0.69</version> <components> <!-- In this case, there is only one master component --> <component> <name>TOMCAT</name> <displayName>Tomcat</displayName> <category>MASTER</category> <!-- how many of these components are allowed in a cluster --> <cardinality>1</cardinality> <!-- reference to (and details of) what script is to be used to install/stop/start/config the service --> <commandScript> <script>scripts/master.py</script> <scriptType>PYTHON</scriptType> <timeout>10000</timeout> </commandScript> </component> </components> <!-- what yum packages need to be installed --> <osSpecifics> <osSpecific> <osFamily>any</osFamily> <packages> <package><name>tomcat</name></package> </packages> </osSpecific> </osSpecifics> <!-- names for config files (under configuration dir) --> <configuration-dependencies> <config-type>tomcat-config</config-type> </configuration-dependencies> <restartRequiredAfterChange>true</restartRequiredAfterChange> </service> </services> </metainfo>
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <!-- Define configuration paramaters for service: property name, default value and description (shown as help text) --> <!-- service log file --> <property> <name>tomcat.install_dir</name> <value>/opt</value> <description>Local dir where to install component. tomcat folder will be created as a subdir of this dir e.g. /opt/tomcat-3.0.0</description> </property> <property> <name>tomcat.port</name> <value>8088</value> <description>Port tomcat runs on</description> </property> <property> <name>tomcat.webapp.address</name> <value>localhost:8088</value> </property> <property> <name>tomcat.JAVA_OPTS</name> <value>-Xms2048m -Xmx2048m -Xmn422m</value> </property> </configuration>
#!/usr/bin/env python from resource_management import * from tomcat import tomcat classMaster(Script): definstall(self, env): # Install packages listed in metainfo.xml self.install_packages(env) #if any other install steps were needed they can be added here self.configure(env) #if any other install steps were needed they can be added here defconfigure(self, env): import params env.set_params(params) tomcat() #To stop the service, use the linux service stop command and pipe output to log file defstop(self, env): import params env.set_params(params) Execute('systemctl stop tomcat') #To start the service, use the linux service start command and pipe output to log file defstart(self, env): import params env.set_params(params) #这里需要configure,可以让配置生效 self.configure(env) Execute('systemctl start tomcat') #To get status of the, use the linux service status command defstatus(self, env): import params Execute('systemctl status tomcat') if __name__ == "__main__": Master().execute()