Skip to content
Snippets Groups Projects
check_services.py 1.49 KiB
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
This script checks services that require /home are started.
If /home is not mounted, a mail is sent and in the other case,
it checks that all services that depend on /home are started.
'''
import os
import sys
import imp
import socket
import datetime


if __name__ == '__main__':
    ec = os.system('cat /etc/fstab | grep /home')
    if ec != 0:
        # /home is not a mount point
        print('/home is not a mount point.')
        sys.exit(0)
    ec = os.system('mount | grep /home')
    if ec != 0:
        os.system('mount -a')
    ec = os.system('mount | grep /home')
    if ec != 0:
        # Mounting has failed, send a email to warn admins
        if os.path.exists('/etc/mediaserver/msconf.py'):
            from django.conf import settings
            config = imp.load_source('config', '/etc/mediaserver/msconf.py')
            settings.configure(**config.__dict__)
            from django.core.mail import send_mail
            send_mail(
                u'The system %s did not correctly mount home partition' % socket.gethostname(),
                u'Date: %s' % datetime.datetime.now(),
                u'"%s" <support@ubicast.eu>' % socket.gethostname(),
                [u'"Support" <support@ubicast.eu>'],
                fail_silently=True
            )
    else:
        os.system('service apache2 start')
        os.system('mscontroller.py start')
        os.system('msmonitor-website.sh start')
        os.system('/etc/init.d/campus-manager start')