]>
Commit | Line | Data |
---|---|---|
dae9c5de WK |
1 | #!/usr/bin/python |
2 | # | |
3 | # Copyright 2015 Cumulus Networks, Inc. All rights reserved. | |
4 | # Author: Roopa Prabhu, roopa@cumulusnetworks.com | |
5 | # | |
6 | ||
7 | import os | |
8 | from utilsbase import * | |
a193d8d1 | 9 | from ifupdown.utils import utils |
dae9c5de WK |
10 | |
11 | class systemUtils(): | |
12 | @classmethod | |
13 | def is_service_running(cls, procname=None, pidfile=None): | |
14 | utilsobj = utilsBase() | |
15 | if pidfile: | |
16 | if os.path.exists(pidfile): | |
17 | pid = utilsobj.read_file_oneline(pidfile) | |
18 | if not os.path.exists('/proc/%s' %pid): | |
19 | return False | |
20 | else: | |
21 | return False | |
22 | return True | |
23 | ||
24 | if procname: | |
25 | try: | |
a193d8d1 | 26 | utils.exec_command('/bin/pidof %s' % procname, stdout=False) |
dae9c5de WK |
27 | except: |
28 | return False | |
29 | else: | |
30 | return True | |
31 | ||
32 | return False | |
20045383 RP |
33 | |
34 | @classmethod | |
35 | def check_service_status(cls, servicename=None): | |
36 | if not servicename: | |
37 | return False | |
20045383 | 38 | try: |
a193d8d1 JF |
39 | utils.exec_commandl(['/usr/sbin/service', servicename, 'status'], |
40 | stdout=False) | |
20045383 RP |
41 | except Exception: |
42 | # XXX: check for subprocess errors vs os error | |
43 | return False | |
44 | return True | |
5f8c03e7 RP |
45 | |
46 | @classmethod | |
47 | def is_process_running(self, processname): | |
48 | if not processname: | |
49 | return False | |
5f8c03e7 | 50 | try: |
a193d8d1 | 51 | utils.exec_command('/bin/pidof %s' % processname, stdout=False) |
5f8c03e7 RP |
52 | except: |
53 | return False | |
54 | else: | |
55 | return True |