Skip to content

Instantly share code, notes, and snippets.

@seunggabi
Last active November 4, 2019 07:01
Show Gist options
  • Save seunggabi/b957c98e56bc3823985a259681ab054c to your computer and use it in GitHub Desktop.
Save seunggabi/b957c98e56bc3823985a259681ab054c to your computer and use it in GitHub Desktop.
check_restart_tomcat.py
# 5 * * * * python3 /home1/irteam/check_restart_tomcat.py
from urllib.request import urlopen
from urllib.error import HTTPError
import os
import time
URL = ""
TOMCAT_PATH = "/home/user/apps/tomcat/bin/"
SHUTDOWN = "shutdown.sh"
STARTUP = "startup.sh"
LOG_PATH = "/home/user/logs/python/"
LOG_FILENAME = "check_restart_tomcat.log"
def checkHttpStatus(url):
try:
res = urlopen(url)
return res.status
except HTTPError as e:
code = e.getcode()
return code
def restart(path, startup, shutdown):
log('restart!!!')
os.system(path + shutdown)
time.sleep(5)
# os.system("pkill java")
os.system(path + startup)
def log(message):
global LOG_PATH
global LOG_FILENAME
timestamp = time.strftime('[%Y-%m-%d(%H:%M:%S)] ')
timeline = str(timestamp) + message + '\n'
file = open(LOG_PATH + LOG_FILENAME, 'a')
file.write(timeline)
file.close()
status = checkHttpStatus(URL)
log("status: " + str(status))
if status != 200:
restart(TOMCAT_PATH, STARTUP, SHUTDOWN)
@seunggabi
Copy link
Author

OutOfMemory

  • pkill java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment