opensource-developer
opensource-developer

Reputation: 3068

start mysql service if it is down programatically

I have a ubuntu server and i want to monitor it and start mysql service if it goes down, what can i do programatically to implement this.

I see this solution and set it via cron to execute every minute.

#!/bin/bash
if [[ ! "$(/usr/sbin/service mysql status)" =~ "start/running" ]]
then
    /usr/sbin/service mysql start
fi

but would setting a cron to execute every minute load my server.

Any help in this direction will be appreciated. Thanks.

Upvotes: 2

Views: 115

Answers (1)

drewyupdrew
drewyupdrew

Reputation: 1609

For the most part, running a short script like that every minute won't stress your server. So programmatically, assuming you tested it and all, I don't see much wrong with your approach.

I'd be more concerned as to why your service randomly shuts down though, have you looked for clues in logs? Depending on the severity of the cause, perhaps implementing a monitoring tool like nagios or icinga might be useful.

Upvotes: 2

Related Questions