...
On the Ambari Server, browse to the
/var/lib/ambari-server/resources/stacks/HDP/2.0.6/services
directory. In this case, we will browse to the HDP 2.0 Stack definition.Code Block cd /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services
Create a directory named
/var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTSRV
that will contain the service definition for TESTSRV.Code Block mkdir /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTSRV
Browse to the newly created
TESTSRV
directory, create ametainfo.xml
file that describes the new service. For example:Code Block <?xml version="1.0"?> <metainfo> <schemaVersion>2.0</schemaVersion> <services> <service> <name>TESTSRV</name> <displayName>My<displayName>New Test Service</displayName> <comment>A New Test Service</comment> <version>0.1.0</version> <components> <component> <name>TEST_CLIENT</name> <displayName>New Test Client</displayName> <category>CLIENT</category> <commandScript> <script>scripts/test_client.py</script> <scriptType>PYTHON</scriptType> <timeout>600</timeout> </commandScript> <customCommands> <customCommand> <name>SOMETHINGCUSTOM</name> <commandScript> <script>scripts/test_client.py</script> <scriptType>PYTHON</scriptType> <timeout>600</timeout> </commandScript> </customCommand> </customCommands> </component> </components> <osSpecifics> <osSpecific> <osFamily>any</osFamily> </osSpecific> </osSpecifics> </service> </services> </metainfo>
- In the above, my service name is "TESTSRV", and it contains one component "TEST_CLIENT" that is of component category "CLIENT". That client is managed via the command script
scripts/test_client.py
. Next, let's create that command script. Create a directory for the command script
/var/lib/ambari-server/resources/stacks/HDP/2.0.6/servi
ces/
TESTSRV
/
package/scripts
that we designated in the service metainfo.Code Block mkdir -p /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTSRV/package/scripts
Browse to the scripts directory and create the
test_client.py
file. For example:Code Block import sys from resource_management import * class TestClient(Script): def install(self, env): print 'Install the client'; def configure(self, env): print 'Configure the client'; def somethingcustom(self, env): print 'Something custom'; if __name__ == "__main__": TestClient().execute()
Now, restart Ambari Server for this new service definition to be distributed to all the Agents in the cluster.
Code Block ambari-server restart
...