This repository has been archived by the owner on Sep 23, 2020. It is now read-only.
/
nimbus_register_mds.py
executable file
·89 lines (77 loc) · 3.12 KB
/
nimbus_register_mds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#! /usr/bin/python
"""*
* Copyright 2009 University of Victoria
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* AUTHOR - Adam Bishop - ahbishop@uvic.ca
*
* For comments or questions please contact the above e-mail address
* OR
* HEPNet Technical Manager - Ian Gable - igable@uvic.ca
*
* """
import os
import sys
import resource
import subprocess
from subprocess import *
import time
REG_FILE = "mdsVirtReg.xml"
#Update this for your respective server location/address
SERVER_ADDRESS = "https://vmcgs29.phys.uvic.ca:8443/wsrf/services/DefaultIndexService"
PID_PATH = "/tmp/nimbusMDSReg.pid"
# Since this script is NOT invoked by NAGIOS as a plug-in, environment variables may
# be used in the subprocess.Popen call below without error
def mdsRegister():
try:
if(os.path.exists(PID_PATH)):
try:
pidFile = open(PID_PATH,"r")
pid = pidFile.readline()
pidFile.close()
print "A PID file exists (another instance is running) with a PID of: "+pid
sys.exit(0)
except IOError:
print >>sys.stderr, "Error opening the PID file for reading at: ",PID_PATH
sys.exit(-1)
else:
pid = os.getpid()
try:
pidFile = open(PID_PATH,"w")
pidFile.write(str(pid))
pidFile.close()
except IOError:
print >>sys.stderr, "Error opening the PID file for writing at: ",PID_PATH
sys.exit(-1)
argString = SERVER_ADDRESS + " " + REG_FILE
try:
process = subprocess.Popen("$GLOBUS_LOCATION/bin/mds-servicegroup-add -s "+argString , shell=True,stderr=PIPE, stdout=PIPE)
output = process.communicate()
# The above statement never finishes executing (such is the nature of mds-servicegroup-add)
# This code snippet exists in case of some sort of error in the sub-process
# Graceful cleanup (removing a defunct pid file) is desired
if(os.path.exists(PID_PATH)):
os.remove(PID_PATH)
except OSError, e:
print >>sys.stderr,"OSError encountered within the subprocess: ",e
if(os.path.exists(PID_PATH)):
os.remove(PID_PATH)
sys.exit(-1)
except KeyboardInterrupt:
print "KeyboardInterrupt encountered - Terminating gracefully"
if(os.path.exists(PID_PATH)):
os.remove(PID_PATH)
mdsRegister()
sys.exit(0)