salt部署执行会hang住的应用

以JBOSS为例:

salt通过ZIP包安装JBOSS:

1.在/srv/salt下,编辑top.sls配置文件vim top.sls,如下:

 base:
  '*':
    - jboss

2.在/srv/salt下添加jboss.sls配置文件vim jboss.sls,如下:

pexpect:
pkg:
- installed

jboss1-src:
file.managed:
- name: /data/jboss.py
- source: salt://jboss/jboss.py
- include_empty: True

jboss2-src:
file.managed:
- name: /data/a.sh
- source: salt://jboss/a.sh
- include_empty: True

jboss-src:
file.managed:
- name: /data/jboss-eap-5.1.0.zip
- source: salt://jboss/jboss-eap-5.1.0.zip
- include_empty: True

jboss-install:
cmd.run:
- name: cd /data && unzip jboss-eap-5.1.0.zip && python jboss.py
- require:
- file: jboss-src
- file: jboss1-src
- file: jboss2-src
- pkg: pexpect

3.将jboss的安装包放到/srv/salt/jboss目录下


4.在/srv/salt/jboss目录下创建安装检验的python脚本:

cd /srv/salt/jboss
vim jboss.py

脚本内容如下:

#!/usr/bin/python
from time import sleep
def check_run():
import pexpect
b='nohup jboss-eap-5.1/jboss-as/bin/run.sh &'
ssh=pexpect.spawn(b)
try:
ssh.expect('\"nohup.out\"',timeout=None)
ssh.sendline('\n')
except Exception,e:
print e
print "THAT'S OK"
def check_error():
a=open('/data/jboss-eap-5.1/jboss-as/server/default/log/server.log','r')
b=a.readlines()
c=0
for i in b:
if not i.find('ERROR')==-1:
c=c+1
print i
if not c:
print "NOT ERROR IN IT"
if __name__=="__main__":
check_run()
sleep(30)
check_error()


5.在master执行同步命令:


salt '*' state.highstate


你可能感兴趣的:(SALT,jboss部署)