1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00
Roopa Prabhu 5f8c03e7a1 ifupdown2: mstpctl: check mstpd running just once during init of mstpctl modules
Ticket: CM-8035
Reviewed By: wkok
Testing Done: Tested mstp commands in interfaces file

(cherry picked from commit 2c3471f2082c8adbdcc395cbd0066680f280b9e5)
2015-12-09 14:02:07 -05:00

57 lines
1.5 KiB
Python

#!/usr/bin/python
#
# Copyright 2015 Cumulus Networks, Inc. All rights reserved.
# Author: Roopa Prabhu, roopa@cumulusnetworks.com
#
import os
from utilsbase import *
class systemUtils():
@classmethod
def is_service_running(cls, procname=None, pidfile=None):
utilsobj = utilsBase()
if pidfile:
if os.path.exists(pidfile):
pid = utilsobj.read_file_oneline(pidfile)
if not os.path.exists('/proc/%s' %pid):
return False
else:
return False
return True
if procname:
try:
utilsobj.exec_command('/bin/pidof %s' %procname)
except:
return False
else:
return True
return False
@classmethod
def check_service_status(cls, servicename=None):
if not servicename:
return False
utilsobj = utilsBase()
try:
utilsobj.subprocess_check_call(['/usr/sbin/service',
'%s' %servicename, 'status'])
except Exception:
# XXX: check for subprocess errors vs os error
return False
return True
@classmethod
def is_process_running(self, processname):
if not processname:
return False
utilsobj = utilsBase()
try:
utilsobj.exec_command('/bin/pidof %s' %processname)
except:
return False
else:
return True