在这个例子中,我们将创建一个称为“SAMPLESRV”的自定义的服务,将它添加到现有源里面。这服务包括MASTER, SLAVE和CLIENT 组件。
在Ambari服务器,进入/var/lib/ambari-server/resources/stacks/HDP/2.0.6/services目录。在这种情况下,我们将浏览到HDP-2源的。
cd /var/lib/ambari-server/resources/stacks/HDP/
2.0
.
6
/services
|
创建目录 /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/SAMPLESRV
,里面将放SAMPLESRV的定义信息.
mkdir /var/lib/ambari-server/resources/stacks/HDP/
2.0
.
6
/services/SAMPLESRV
cd /var/lib/ambari-server/resources/stacks/HDP/
2.0
.
6
/services/SAMPLESRV
|
浏览到新创建的samplesrv目录,创建新服务的描述文件metainfo.xml。例如:
2.0
1.0
.
0
1
600
1
+
600
1
+
600
|
下一步,让我们创建命令脚本. 为命令脚本创建一个目录 /var/lib/ambari-server/resources/stacks/HDP/2.0.6/servi
ces/
SAMPLESRV
/
package/scripts
,需要我们在服务的metainfo里面配置。
mkdir -p /var/lib/ambari-server/resources/stacks/HDP/
2.0
.
6
/services/SAMPLESRV/
package
/scripts
cd /var/lib/ambari-server/resources/stacks/HDP/
2.0
.
6
/services/SAMPLESRV/
package
/scripts
|
进入脚本目录,并创建.py命令脚本文件。
例如 master.py 文件
:
import
sys
from resource_management
import
*
class
Master(Script):
def install(self, env):
print
'Install the Sample Srv Master'
;
def stop(self, env):
print
'Stop the Sample Srv Master'
;
def start(self, env):
print
'Start the Sample Srv Master'
;
def status(self, env):
print
'Status of the Sample Srv Master'
;
def configure(self, env):
print
'Configure the Sample Srv Master'
;
if
__name__ ==
"__main__"
:
Master().execute()
|
例如 slave
.py
文件:
import
sys
from resource_management
import
*
class
Slave(Script):
def install(self, env):
print
'Install the Sample Srv Slave'
;
def stop(self, env):
print
'Stop the Sample Srv Slave'
;
def start(self, env):
print
'Start the Sample Srv Slave'
;
def status(self, env):
print
'Status of the Sample Srv Slave'
;
def configure(self, env):
print
'Configure the Sample Srv Slave'
;
if
__name__ ==
"__main__"
:
Slave().execute()
|
例如 sample_client
.py
文件:
import
sys
from resource_management
import
*
class
SampleClient(Script):
def install(self, env):
print
'Install the Sample Srv Client'
;
def configure(self, env):
print
'Configure the Sample Srv Client'
;
if
__name__ ==
"__main__"
:
SampleClient().execute()
|
现在, 重启ambari服务器
ambari-server restart
|
注意:通过web界面添加自定义服务是在1.7.0极以后版本上
metainfo.xml
文件里面定义的名称)。