Script for deploying to jboss with fabric. It is assumed that the post-build artifacts have been created.
from fabric.api import run, env, put
env.use_ssh_config = True
def deploy():
put("./trunk/project/build/libs/app.war", "/home/ec2-user/app.war")
run("sudo chown jboss:jboss /home/ec2-user/app.war")
run("sudo /opt/jboss7/bin/./jboss-cli.sh -c --command='undeploy app.war'")
run("sudo /opt/jboss7/bin/./jboss-cli.sh -c --command='deploy /home/ec2-user/app.war'")
run("sudo /etc/init.d/jboss restart")
fab -H {hostname} deploy
How to use a stepping server. Introducing two methods, one is to specify it as an argument and the other is to describe it in the config file.
Describe the settings of each server in .ssh / config.
Host proxy #Name of bastion server
HostName XXX.XXX.XXX.XXX #Stepping stone server host
User deploy #Ssh connection username
IdentityFile /home/ec2-user/.ssh/key.pem #Ssh connection key file
Host remote #Name of the connection destination
HostName XXX.XXX.XXX.XXX #Host to connect to
User deploy #Ssh connection username
IdentityFile /home/ec2-user/.ssh/key.pem #Ssh connection key file
Execute the command by specifying the host name of the bastion server with the "-g" option.
fab -H remote -g proxy deploy
Specify directly in config as shown below.
Host proxy #Name of bastion server
HostName XXX.XXX.XXX.XXX #Stepping stone server host
User deploy #Ssh connection username
IdentityFile /home/ec2-user/.ssh/key.pem #Ssh connection key file
Host remote #Name of the connection destination
HostName XXX.XXX.XXX.XXX #Host to connect to
User deploy #Ssh connection username
IdentityFile /home/ec2-user/.ssh/key.pem #Ssh connection key file
ProxyCommand ssh -W %h:%p proxy #Specify the bastion server
Execute the command by specifying the host name.
fab -H remote deploy