GithubHelp home page GithubHelp logo

sierracircle / services-checker Goto Github PK

View Code? Open in Web Editor NEW
158.0 12.0 59.0 25 KB

Bash Script to check if services are running and restart if not. Sends email to you.

License: MIT License

Shell 100.00%

services-checker's Introduction

Services Checker

Bash Script to check if services are running and restart if not. Sends email to you. Tested with Ubuntu 18.04, 20.04 and 22.04.

Installation

  1. Put it into your scripts folder
  2. Uncomment the email and set your email address if you want an email notification
  3. Uncomment the log option if you want a log-file (it creates it automatically in the same directory as the script)
  4. Set the services you want to keep an eye on (by default it has mariadb and apache2... you can modify them as you need) For ubuntu 20.04 and below I had to use mysql instead of mariadb. In ubuntu 22.04 I had to use mariadb
  5. Save your changes
  6. Ensure it has enough privilege to run:
chmod +x /your/path/to/scripts/restart-services
  1. Create a cronjob as root (sudo crontab -e) and add something like this, which runs every minute (adjust to your needs):
#check on services
*/1 *  * * * /your/path/to/scripts/restart-services

The script will check the status of each service. If the service is stopped, it tries to restart the service. If the service starts, it sends you an email saying the service stopped but was restarted.

If the service does not start for some reason, it sends you an email telling you it was not started.

After that, it will continue to try and start, but not send any more emails until the service is finally started.

services-checker's People

Contributors

appel avatar dct-infra avatar mfyz avatar sierracircle avatar ttodua avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

services-checker's Issues

script is not working

I tried to use this script, take a look at how i configured it like below in "crontab -e"

*/1 * * * * sh /var/www/html/jobs/services.sh

I changed the email and stopped my apache2. I didn't get any email.

Can u pls help me in resolving this.

Thank you.

Email not sent after crash

Looking at the closed issues, and one which was that the email wasn't sent, i configured my droplet for mail to be sent via sendmail (as you suggested to someone to install sendmail). Did some tests and server email works. However, not when the service crashes. Now, i am really FAR from knowing anything about this, but i noticed in your code, you use echo $MESSAGE | mail -s "$SUBJECT" "$EMAIL" but shouldn't it be sendmail instead of mail?

Can't restart my nginx service

I'm naive to bash script so please bear me and help me out here.
I added this service file at: /root/donotdelete

Then I added that path to the service file as well
Added my email address
In Services removed apache and mysql.
Then added 'nginx'
also added the code in crontab

Then I stopped my nginx service by this command "service nginx stop"
waited for 2 minutes, but it didn't restart.

Thank you

Keep a log of the reboots maybe?

I don't know if this repo is still alive, but what would be awesome (if it's not already the case?) would be that there's a log file of the reboots (or unsuccessful restarts). Right now, since my server doesn't send out emails (another of my own problems lol) i would like to have a way to verify if the script actually works, AND how often do my services crash.

Thanks!

How to install the script on serverpilot setup

I am rather new to the "server world" and am actually using serverpilot.io (that installs all the necessary components for web, mainly LAMP).

I am also running a droplet using digitalocean. You recommended your script there.

Now I would like to install the script but do not know how. You start with 1. put into your scripts folder, could you just give an example of the how-to? And is this a special folder or can you define it yourself? Can I just upload it via FTP? Is the file services a SH file?

PS: I already found out how to do the cronjob setup via serverpilot.

Email not sent

the script did restart the service, however, it did not send any email notification

Temp file purpose

Hey, thanks for the script!

Just a question: what's the purpose of the temp file that is created when a service could not be restarted?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.