如果odoo 服务太多的话,一个一个的重启会比较麻烦
写一个python脚本来批量重启:
import paramiko
import configparser
def get_conf():
cf = configparser.ConfigParser()
cf.read('./data/server.conf')
sections = cf.sections()
list_dict_conf = []
for opt in sections:
dev_item = cf.items(opt)
list_dict_conf.append(dict(dev_item))
return list_dict_conf
class OdooServer(object):
def __init__(self, hostname, port, username, password, command=''):
# 建立一个sshclient对象
self.ssh = paramiko.SSHClient()
# 允许将信任的主机自动加入到host_allow 列表,此方法必须放在connect方法的前面
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# 调用connect方法连接服务器
self.ssh.connect(hostname=hostname, port=port, username=username, password=password)
self.command = command
def exec_command(self):
if not isinstance(self.command, str):
return None
stdin, stdout, stderr = self.ssh.exec_command(self.command)
if stdout:
print('Return Message:', stdout.read().decode())
if stderr:
print('Error Message:', stderr.read().decode())
self.ssh.close()
if __name__ == '__main__':
list_config = get_conf()
for dict_config in list_config:
print('restart server:', dict_config)
server = OdooServer(**dict_config)
server.exec_command()
server.conf
[odoo12_dev1]
hostname=localhost
port = 22
username=test
password=password
command = ./reload_supervisor_odoo.sh
[odoo12_dev2]
hostname=localhost
port = 22
username=test
password=password
command = ./reload_supervisor_odoo.sh