Fabric は redis サーバーを停止しますが、起動しません。ファブリックで試してみましたが、パラミコでうまくいきました。Fabric が redis サーバーを起動しないのはなぜですか? paramiko を使用できますが、それはちょっとひねくれたようです。
[ec2-xxx-xxx-xxx.compute-1.amazonaws.com] Executing task 'redis_master_role'
[master.redis.htdevops.com] Executing task 'redis_master_stop'
[master.redis.htdevops.com] sudo: service redis_6379 stop
[master.redis.htdevops.com] out: Stopping ...
[master.redis.htdevops.com] out: Waiting for Redis to shutdown ...
[master.redis.htdevops.com] out: Redis stopped
[master.redis.htdevops.com] out:
#Fail 1
[master.redis.htdevops.com] sudo: service redis_6379 start
[master.redis.htdevops.com] out: Starting Redis server...
[master.redis.htdevops.com] out:
#Fail 2
[master.redis.htdevops.com] sudo: service redis_6379 start
[master.redis.htdevops.com] out: Starting Redis server...
[master.redis.htdevops.com] out:
#Started by paramiko
Starting Redis server...
def redis_master_role():
env.roles = ['redis']
def redis_master_stop():
sudo('service redis_6379 stop')
time.sleep(5)
def redis_master_start():
sudo('service redis_6379 start')
time.sleep(5)
sudo('service redis_6379 start')
keypair_path = "/home/ubuntu/.ec2/test.pem"
key = paramiko.RSAKey.from_private_key_file(keypair_path)
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(redis_master,22,username='ubuntu',pkey=key,timeout=60)
cmd = 'sudo service redis_6379 start'
stdin, stdout, stderr = ssh.exec_command(cmd)
print stdout.read()
ssh.close()
def redis_bootstrap():
env.user = "ubuntu"
env.key_filename = "/home/ubuntu/.ec2/test.pem"
execute('redis_master_role')
execute('redis_master_stop')
execute('redis_master_put')
execute('redis_master_start')