How to use restart_container method in localstack

Best Python code snippet using localstack_python

app.py

Source:app.py Github

copy

Full Screen

...46 os.system('echo Waiting ...')47 c_dst=find_src[0]['container']['name'] + ':' + find_src[0]['container']['path']48 copy_to(src, c_dst)49 print('[PROVISION] File `{}` as been push to the {}'.format(src, c_dst))50 if restart: restart_container(find_src[0]['container']['name'])51 #copy_to(src, dst)52 #restart_container(c_id)53 # TEST 54 #for watcher in config["watchers"]:55 #os.system("cp -Rv /test-file {}".format(watcher['file_to_watch']))56 #os.system("/etc/incron/cmd/update {}".format(watcher['file_to_watch']))57 #dst = watcher['container']['name'] + ":" + watcher['container']['path']58 #src = watcher['file_to_watch']59 #copy_to(src, dst)60 #restart_container(watcher['container']['name'])61 62def cli():63 parser = argparse.ArgumentParser()64 parser.add_argument("--template", help="Default template is locate on /etc/template.watcher.yml")65 parser.add_argument("--config", help="Default incron config is locate on /etc/incron.d/config")66 parser.add_argument("--provide", help="Provide repo[ulrs] to a container")67 parser.add_argument("--restart", help="Provide repo[ulrs] to a container")68 return parser.parse_args()69if __name__ == "__main__":70 opts=cli()71 template = '/etc/template.watcher.yml'72 incron = '/etc/incron.d/config'73 if opts.template: template = opts.template74 if opts.config: incron = opts.config...

Full Screen

Full Screen

monitor-website.py

Source:monitor-website.py Github

copy

Full Screen

...18 while True:19 nginx_server = client.load(linode_api4.Instance, 24920590)20 if nginx_server.status == 'running':21 time.sleep(5)22 restart_container()23 break24def send_notification(email_msg):25 print('Sending an email...')26 with smtplib.SMTP('smtp.gmail.com', 587) as smtp:27 smtp.starttls()28 smtp.ehlo()29 smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)30 message = f"Subject: SITE DOWN\n{email_msg}"31 smtp.sendmail(EMAIL_ADDRESS, EMAIL_ADDRESS, message)32def restart_container():33 print('Restarting the application...')34 ssh = paramiko.SSHClient()35 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())36 ssh.connect(hostname='139.162.130.236', username='root', key_filename='/Users/nanajanashia/.ssh/id_rsa')37 stdin, stdout, stderr = ssh.exec_command('docker start c3e706bc905e')38 print(stdout.readlines())39 ssh.close()40def monitor_application():41 try:42 response = requests.get('http://li1388-236.members.linode.com:8080/')43 if response.status_code == 200:44 print('Application is running successfully!')45 else:46 print('Application Down. Fix it!')47 msg = f'Application returned {response.status_code}'48 send_notification(msg)49 restart_container()50 except Exception as ex:51 print(f'Connection error happened: {ex}')52 msg = 'Application not accessible at all'53 send_notification(msg)54 restart_server_and_container()55schedule.every(5).minutes.do(monitor_application)56while True:...

Full Screen

Full Screen

docker.py

Source:docker.py Github

copy

Full Screen

...31 os.system('docker-compose up --build -d {name}'.format(name=name))32def start_container(name):33 os.system('docker start {name}'.format(name=name))34 print('Started {name}'.format(name=name))35def restart_container(name):36 os.system('docker restart {name}'.format(name=name))37 print('Restarted {name}'.format(name=name))38 39def check_container(name):40 try:41 log = subprocess.check_output('docker container inspect {name}'.format(name=name), shell=True)42 data = json.loads(log)43 process = data[0]44 45 state = process['State']46 status = state['Status']47 running = state['Running']48 paused = state['Paused']49 restarting = state['Restarting']50 dead = state['Dead']51 52 return status, (running, paused, restarting, dead)53 except Exception as e:54 return False, (False, False, False, False)55 56def restart_seed():57 restart_container('mongodb-seed')58def check_express():59 # Check seed container, if bad then restart it60 status, states = check_container('mongo-express')61 if (status == 'exited'):62 start_container('mongo-express')63def check_backend():64 status, (running, paused, restarting, dead) = check_container('xprt-backend-dev')65 66 if (not status):67 create_container('xprt-backend-dev')68 elif (not running):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful