This is my piece of code that I am trying to use to restart a service but I am not able to. I am using python's paramiko module to restart a service by going into the container of the service.
def sshOpensips(ip):
warnings.filterwarnings(action='ignore',module='.*paramiko.*')
client = pm.SSHClient()
commands = ["docker exec -it opensips bash", "service opensips restart"]
client.set_missing_host_key_policy(pm.AutoAddPolicy())
pk = pm.RSAKey.from_private_key(open('/home/asad.javed/.ssh/y'))
try:
client.connect(ip, username='asad.javed', pkey=pk)
print("Connection Established")
except pm.SSHException:
print("Connection Failed")
for command in commands:
stdin, stdout, stderr = client.exec_command(command);
client.close()
return True
Can someone please guide how can I restart a service by going into a docker container?