Created
August 6, 2015 13:46
-
-
Save tasdikrahman/67609dd984309d0a82f9 to your computer and use it in GitHub Desktop.
Service Check module - Checks some of the services which runs on the server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import commands | |
import os | |
output = commands.getoutput('ps -A') | |
def print_spaces() : | |
print "\n-----XXXXXXXXXXX----------XXXXXXXXXX--------\n" | |
def mongo() : | |
if 'mongodb' in output : | |
print 'mongod ------ running' | |
else : | |
print 'mongodb ------ stopped' | |
print 'starting mongodb : ' | |
os.system('sudo service mongodb start') | |
print '------ >> now checking the status : << ------ ' | |
os.system('sudo service mongodb status') | |
def apache() : | |
if 'apache2' in output : | |
print 'apache2 ------ running' | |
else : | |
print 'apache2 ------ stopped' | |
print 'starting apache2 : ' | |
os.system('sudo service apache2 start') | |
print '------ >> now checking the status : << ------ ' | |
os.system('sudo service apache2 status') | |
def mysql() : | |
if 'mysqld' in output : | |
print 'mysqld ------ running' | |
else : | |
print 'mysqld ------ stopped' | |
print 'starting mysql : ' | |
os.system('sudo service mysql start') | |
print '------ >> now checking the status : << ------ ' | |
os.system('sudo service mysql status') | |
def ssh() : | |
if 'ssh' in output : | |
print 'ssh ------ running' | |
else : | |
print 'ssh ------ stopped' | |
print 'starting ssh : ' | |
os.system('sudo service ssh start') | |
print '------ >> now checking the status : << ------ ' | |
os.system('sudo service ssh status') | |
def services(): | |
''' | |
Here are the services which need to be checked whether they are running on the server or not ! | |
- mysqld | |
- ssh | |
- mongodb | |
- apache2 | |
### further functions to be added would be to ### | |
- start the services if they are not running | |
''' | |
print "====== >> Service check module <<====== " | |
print "service ---|| --- Status\n" | |
print_spaces() | |
mongo() | |
######## | |
print_spaces() | |
apache() | |
######## | |
print_spaces() | |
mysql() | |
######## | |
print_spaces() | |
ssh() | |
def main() : | |
services() | |
if __name__ == '__main__' : | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment