ambari 添加自定义服务

1 告诉ambari添加什么服务

/var/lib/ambari-server/resources/stacks/HDP/2.5/services

目录下添加 服务名称 比如TEST

然后在目录下新建metainfo.xml 

cat /var/lib/ambari-server/resources/stacks/HDP/2.5/services/TEST/metainfo.xml

包括服务名称 版本号 加载资源的路径

       2.0

       

               

                       TEST

                       4.0

                       common-services/TEST/4.0

               

       

 

2 告诉ambari服务在哪怎么加载

在/var/lib/ambari-server/resources/common-services下

新建 TEST/4.0 要和上面对应起来

.
└── TEST
    └── 4.0
        ├── configuration
        │   └── test-env.xml
        ├── metainfo.xml
        └── package
            └── scripts
                ├── params.py
                └── test-ccc.py

目录结果如下 必须按照这个模板来 

gu里面的内容也必须按照这个模板来

 

configuation/test-env.xml   配置引用参数




 
    test_user
    test
    USER
    user
 

 
 
    test_group
    test
    GROUP
    group
 

 
 
    test_base_dir
    /opt/test
    test base directory
 

 
 
    test_pid_dir
    /var/run/test
    test PID directory
 


 

 

metainfo.xml 多个组件多个component 



  2.0
 
   
      test
      test
      custom service
      3.0
     
       
          test-ccc
          test-ccc
          MASTER
          1
         
           
            PYTHON
            1200
         

       

     
     
       
          any
       

     

   
 

 

test-ccc.py 组件安装启动等

#! /usr/bin/env python
import sys
import os
import glob
import pwd
import grp
import signal
import time
from resource_management import *
 
class Master(Script):
 
    # Install testsearch
    def install(self, env):
        # Import properties defined in -config.xml file from the params class
        import params
 
        # This allows us to access the params.test_pid_file property as
        # format('{test_pid_file}')
        env.set_params(params)
 
        # Install dependent packages
        self.install_packages(env)
 
        # Create user and group for test if they don't exist
        try: grp.getgrnam(params.test_group)
        except KeyError: Group(group_name=params.test_group)
 
        try: pwd.getpwnam(params.test_user)
        except KeyError: User(username=params.test_user,
                              gid=params.test_group,
                              groups=[params.test_group],
                              ignore_failures=True
                              )
 
        # Create test directories
        Directory([params.test_base_dir, params.test_pid_dir],
                  mode=0755,
                  cd_access='a',
                  owner=params.test_user,
                  group=params.test_group,
                  create_parents=True
                  )
 
 
        # Download testsearch
        cmd = format("cd {test_base_dir};wget {test_actualTimeMonitor_download}")
        Execute(cmd, user="root")
 
        cmd1 = format("cd {test_base_dir}; unzip test-actualTimeMonitor.zip")
        Execute(cmd1, user="root")
 
        cmd2 = format("cd {test_base_dir}; rm test-actualTimeMonitor.zip")
        Execute(cmd2, user=params.test_user)
 
        Execute('echo "Install complete"')
 
 
    def configure(self, env):
        # Import properties defined in -config.xml file from the params class
        import params
 
        # This allows us to access the params.test_pid_file property as
        # format('{test_pid_file}')
        env.set_params(params)
 
        Execute('echo "Configuration complete"')
 
    def stop(self, env):
        # Import properties defined in -config.xml file from the params class
        import params
 
        # Import properties defined in -env.xml file from the status_params class
        import status_params
 
        # This allows us to access the params.test_pid_file property as
        #  format('{test_pid_file}')
        env.set_params(params)
 
        # Stop testsearch
        cmd = format("kill  -9 `cat {test_actualTimeMonitor_pid_file}`")
        Execute(cmd, user="root")
 
 
    def start(self, env):
        # Import properties defined in -config.xml file from the params class
        import params
 
        # This allows us to access the params.test_pid_file property as
        #  format('{test_pid_file}')
        env.set_params(params)
 
        # Configure testsearch
        self.configure(env)
 
        # Start testsearch
        cmd = format("cd {test_base_dir};sh test-actualTimeMonitor/start.sh {test_actualTimeMonitor_pid_file}")
        Execute(cmd, user="root")
 
 
    def status(self, env):
        # Import properties defined in -env.xml file from the status_params class
        import status_params
 
        # This allows us to access the params.test_pid_file property as
        #  format('{test_pid_file}')
        env.set_params(status_params)
 
        #try:
        #    pid_file = glob.glob(status_params.test_pid_file)[0]
        #except IndexError:
        #    pid_file = ''
 
        # Use built-in method to check status using pidfile
        check_process_status(status_params.test_actualTimeMonitor_pid_file)
 
if __name__ == "__main__":
    Master().execute()

 

param.py  参数引用

#! /usr/bin/env python
from resource_management import *
import os
 
# config object that holds the configurations declared in the -config.xml file
config = Script.get_config()
 
java64_home = config['hostLevelParams']['java_home']
 
hostname = config['hostname']
 
test_user = config['configurations']['test-env']['test_user']
test_group = config['configurations']['test-env']['test_group']
 
test_base_dir = config['configurations']['test-env']['test_base_dir']
 
test_pid_dir = config['configurations']['test-env']['test_pid_dir']

test_ccc_pid_file = format("{test_pid_dir}/ccc.pid")
 
test_ccc_download = 'http://127.0.0.1/test-ccc.zip'

 

注意全部的配置项对大小写以及下划线特别敏感,会无法执行

所以建议  小写 和_ 下划线
 

 

 

 

你可能感兴趣的:(ambari)