mysqld异常重启后,自动启动应用srm进程

本博客介绍了一个Python脚本,用于监控MySQL错误文件,检查MySQL服务是否在线,并在必要时通过SSH连接执行SRM命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/usr/bin/python
#-*- coding: utf-8 -*-

import paramiko
import os
import commands
import time

os.environ['PATH'] = '$PATH:$HOME/bin:/veris/usr/bin:/veris/usr/sbin'
os.environ['LD_LIBRARY_PATH'] = '/veris/usr/lib64:$LD_LIBBRARY_PATH'

port=5320
veris_name="billing"
error_file="/veris/%s/mysql/%d/log/error/error_%d.log" % (veris_name,port,port)
    
if os.path.isfile(error_file):
    if "mysqld restarted" in open(error_file).read():
        check_mysql_cmd = "mysqladmin -h127.0.0.1 -P%d -uroot -pxxxxxx ping 2>/dev/null" % port
        try:
            is_up=commands.getoutput(check_mysql_cmd)
        except Exception, err1:
            print err1
        if is_up == "mysqld is alive":
            ssh = paramiko.SSHClient()
            ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            ssh.connect("10.1.196.90",22,"aibilling", "123456")
            try:
                stdin, stdout, stderr = ssh.exec_command("srm")
            except Exception, err2:
                print err2
            print stdout.read()
            ssh.close()             
            error_path=os.path.dirname(error_file)
            error_name=os.path.basename(error_file)
            os.rename(error_file,error_path + os.sep + "bak" + os.sep + time.strftime('%Y%m%d.%H%M.') + error_name)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值