创建多个redis和启动停止脚本

import os,stat

base_dir = "/Users/xmx/Desktop/app/redis"
port=7000
num=6

os.chdir(base_dir)

for i in range(num):
    dirs = os.path.join(base_dir,str(port + i))
    os.mkdir(dirs)
    f = open(dirs+'/redis.conf', 'w+')
    f.write("daemonize yes\n")
    f.write("port "+str(port+i)+"\n")
    f.write("cluster-enabled yes\n")
    f.write("cluster-config-file nodes.conf\n")
    f.write("cluster-node-timeout 5000\n")
    f.write("appendonly yes\n")
    f.write("dir " + dirs+"\n")
    f.close()

start_sh = os.path.join(base_dir, "redis_start.sh")
stop_sh = os.path.join(base_dir, "redis_stop.sh")

f=open(start_sh,"w+")
f.write("#!/bin/bash\n")
f.write("base_dir="+base_dir+"\n")
f.write("\n")
for i in range(num):
    f.write('redis-server "${base_dir}/'+str(port+i)+'/redis.conf"\n')
f.close()


f = open(stop_sh, "w+")
f.write("#!/bin/bash\n")
f.write("\n")
for i in range(num):
    f.write("redis-cli -p "+str(port+i)+" shutdown\n")
f.close()

os.chmod(start_sh, stat.S_IRWXU | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
os.chmod(stop_sh, stat.S_IRWXU | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)

  

posted @ 2017-12-14 15:59  otwos  阅读(452)  评论(0编辑  收藏  举报