2019-12-17 16:40:10 +01:00
|
|
|
#!/usr/bin/env python3
|
2015-09-10 13:57:14 -07:00
|
|
|
#
|
2018-12-13 11:43:32 -08:00
|
|
|
# Copyright 2015-2017 Cumulus Networks, Inc. All rights reserved.
|
2015-09-10 13:57:14 -07:00
|
|
|
# Author: Roopa Prabhu, roopa@cumulusnetworks.com
|
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
2018-12-13 11:43:32 -08:00
|
|
|
|
|
|
|
try:
|
|
|
|
from ifupdown2.ifupdown.utils import utils
|
|
|
|
from ifupdown2.ifupdownaddons.utilsbase import *
|
2019-12-17 17:25:32 +01:00
|
|
|
except (ImportError, ModuleNotFoundError):
|
2018-12-13 11:43:32 -08:00
|
|
|
from ifupdown.utils import utils
|
|
|
|
from ifupdownaddons.utilsbase import *
|
|
|
|
|
2015-09-10 13:57:14 -07:00
|
|
|
|
|
|
|
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:
|
2018-12-13 11:43:32 -08:00
|
|
|
utils.exec_command('%s %s' %
|
|
|
|
(utils.pidof_cmd, procname))
|
2015-09-10 13:57:14 -07:00
|
|
|
except:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
2015-11-25 14:12:14 -08:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def check_service_status(cls, servicename=None):
|
|
|
|
if not servicename:
|
|
|
|
return False
|
|
|
|
try:
|
2018-12-13 11:43:32 -08:00
|
|
|
utils.exec_commandl([utils.service_cmd,
|
|
|
|
servicename, 'status'])
|
2015-11-25 14:12:14 -08:00
|
|
|
except Exception:
|
|
|
|
# XXX: check for subprocess errors vs os error
|
|
|
|
return False
|
|
|
|
return True
|
2015-11-27 19:31:25 -08:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def is_process_running(self, processname):
|
|
|
|
if not processname:
|
|
|
|
return False
|
|
|
|
try:
|
2018-12-13 11:43:32 -08:00
|
|
|
utils.exec_command('%s %s' %
|
|
|
|
(utils.pidof_cmd, processname))
|
2015-11-27 19:31:25 -08:00
|
|
|
except:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return True
|