source: palm/trunk/SCRIPTS/palm_wdd @ 2417

Last change on this file since 2417 was 2416, checked in by maronga, 7 years ago

watchdog adapted for palmrun

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 7.6 KB
Line 
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3#--------------------------------------------------------------------------------#
4# This file is part of PALM.
5#
6# PALM is free software: you can redistribute it and/or modify it under the terms
7# of the GNU General Public License as published by the Free Software Foundation,
8# either version 3 of the License, or (at your option) any later version.
9#
10# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along with
15# PALM. If not, see <http://www.gnu.org/licenses/>.
16#
17# Copyright 1997-2015  Leibniz Universitaet Hannover
18#--------------------------------------------------------------------------------#
19#
20# Current revisions:
21# -----------------
22#
23#
24# Former revisions:
25# -----------------
26# $Id: palm_wdd 2416 2017-09-06 14:28:14Z suehring $
27# Adapted for palmrun
28#
29# 1619 2015-07-13 06:53:19Z maronga
30#
31# 1618 2015-07-13 06:52:15Z maronga
32# Added steering via configuration file, to be placed in the home directory of the
33# remote host to be monitored.
34#
35# 1613 2015-07-08 14:53:29Z maronga
36# Bugfix: tooltip for queuing name did not show up on first update.
37# New: added contect menu for showing the parameter file and the run control
38# output
39#
40# 1611 2015-07-07 12:23:22Z maronga
41# Initial revision
42#
43#
44# Description:
45# ------------
46# PALM watchdog client for monitoring batch jobs on a variety of hosts specified
47# by the user. The watchdog server requires python 2.7 or higher installed on
48# host to be monitored.
49#
50# Instructions:
51# -------------
52# 1) Modify the header section of palm_wd
53# 2) Move .wd.olddata and .wd.newdata to your palm directory
54#    (e.g. /home/user/current_version/.wd.newdata etc.)
55# 3) Modify a copy of palm_wdd for each host to be monitored and move it to the
56#    respective hosts
57# 4) Start the client either from mrungui or from shell by "nohup palm_wd&"
58#
59# To do:
60# ------
61# 1) Add "Options", "Help" and "Manual"
62# 2) Move user settings to a configuration file
63#------------------------------------------------------------------------------!
64
65import ConfigParser
66import os
67import pwd
68from subprocess import check_output
69import sys
70
71
72# Read configuration file
73# First check if the configuration file exists
74if ( os.path.exists('.wdd.config') == False ):
75    print "Error. No configuration file .wdd.config found."
76    raise SystemExit     
77
78config = ConfigParser.RawConfigParser()
79config.read('.wdd.config')
80
81cmd_readqueue      = config.get('Settings', 'readqueue').strip('"')
82cmd_tmpdir         = config.get('Settings', 'tmpdir').strip('"')
83cmd_canceljob      = config.get('Settings', 'canceljob').strip('"')
84cmd_checkjob       = config.get('Settings', 'checkjob').strip('"')
85cmd_realname_grep  = config.get('Settings', 'realname_grep').strip('"')
86cmd_starttime      = config.get('Settings', 'starttime').strip('"')
87cmd_starttime_grep = config.get('Settings', 'starttime_grep').strip('"')
88
89
90action   = str(sys.argv[1])
91data     = str(sys.argv[2])
92
93cmd_readqueue = cmd_readqueue + " " + pwd.getpwuid( os.getuid() )[ 0 ]
94cmd_tmpdir    = cmd_tmpdir + pwd.getpwuid( os.getuid() )[ 0 ]
95
96# reading queuing system
97def ReadQueue(username):
98 
99#  collect queuing information
100   try:
101      out = check_output(cmd_readqueue, shell=True)
102      job_list = out.splitlines()
103      out = None
104#  do nothing for empty results list
105   except:
106      job_list = []
107 
108 
109   job_data_tmp = []
110   for j in range(0,len(job_list)):
111
112      # Write temporary data array containing the job information.
113      job_data_tmp.append(j)
114      job_data_tmp[j] = job_list[j].split(" ")
115      job_data_tmp[j] = filter(None, job_data_tmp[j])
116
117      cmd_realname = cmd_checkjob + " " + job_data_tmp[j][0] + "|grep " + cmd_realname_grep
118
119      # retrieve real job name for all jobs
120      try: 
121         out = check_output(cmd_realname, shell=True)
122         job_realname = out.split(" ")[1].rstrip()
123      except:
124         job_realname = "error"
125
126
127      # for running jobs, determine progress                 
128      if ( job_data_tmp[j][2] == "Running" ):
129 
130         # collect progress information
131         cmd_progress = "cat " + cmd_tmpdir + "/" + username + "." + job_data_tmp[j][0].partition(".")[2] + "/PROGRESS"
132         try: 
133
134            devnull = open(os.devnull, 'w')
135            out = check_output(cmd_progress, shell=True, stderr=devnull)
136            progress_lines = out.splitlines()
137            job_progress = progress_lines[1].split(" ")[3]
138            out = None
139         except:
140            job_progress = "0" 
141
142      else:
143         job_progress = "0" 
144
145      # return the job data
146      job_starttime = GetStartTime(job_data_tmp[j][0])
147      print job_realname + " " + job_data_tmp[j][0] + " " + job_data_tmp[j][3] + " " + job_data_tmp[j][2] + " " + job_progress + " "  + job_data_tmp[j][4] + " " + job_starttime
148
149
150# check details of specific job
151def CheckJob(jobid):
152
153   cmd_checkjob_tmp = cmd_checkjob + " " + jobid
154
155   try: 
156      out = check_output(cmd_checkjob_tmp, shell=True)
157      job_details = out
158   except:
159      job_details = "No details available." 
160
161   return job_details
162
163
164# cancel a specific job
165def CancelJob(jobid):
166
167   cmd_canceljob_tmp = cmd_canceljob + " " + jobid
168
169   try: 
170      out = check_output(cmd_canceljob_tmp, shell=True)
171      job_canceled = out
172   except:
173      job_canceled = "Action failed." 
174
175   return job_canceled
176
177
178# retrieve estimated start time of job
179def GetStartTime(jobid):
180
181   cmd_starttime_tmp = cmd_starttime + " " + jobid + "|grep \"" + cmd_starttime_grep + "\"" 
182
183   try: 
184      out = check_output(cmd_starttime_tmp, shell=True)
185      job_starttime = out.split()[5]
186   except:
187      job_starttime = "Action failed." 
188
189   return job_starttime
190
191
192def DoStopNow(jobid):
193
194   # collect progress information
195   cmd_dostop = "touch " + cmd_tmpdir + "/" + jobid + "/DO_STOP_NOW"
196   try: 
197      devnull = open(os.devnull, 'w')
198      out = check_output(cmd_dostop, shell=True, stderr=devnull)
199      out = None
200   except:
201      return_message = "Action failed." 
202      return return_message
203
204def DoRestartNow(jobid):
205
206   # collect progress information
207   cmd_dorestart = "touch " + cmd_tmpdir + "/" + jobid + "/DO_RESTART_NOW"
208   try: 
209      devnull = open(os.devnull, 'w')
210      out = check_output(cmd_dorestart, shell=True, stderr=devnull)
211      out = None
212   except:
213      return_message = "Action failed." 
214      return return_message
215
216def GetPARIN(jobid):
217
218   # collect progress information
219   cmd_dorestart = "cat " + cmd_tmpdir + "/" + jobid + "/PARIN"
220   try: 
221      devnull = open(os.devnull, 'w')
222      out = check_output(cmd_dorestart, shell=True, stderr=devnull)
223      return_message = out
224      out = None
225   except:
226      return_message = "Action failed."   + "cat " + cmd_tmpdir + "/" + jobid + "/PARIN" 
227     
228   return return_message
229
230def GetRC(jobid):
231
232   # collect progress information
233   cmd_dorestart = "cat " + cmd_tmpdir + "/" + jobid + "/RUN_CONTROL"
234   try: 
235      devnull = open(os.devnull, 'w')
236      out = check_output(cmd_dorestart, shell=True, stderr=devnull)
237      return_message = out
238      out = None
239   except:
240      return_message = "Action failed."
241     
242   return return_message
243
244# START OF MAIN
245if ( action == "queue" ):
246   ReadQueue(data)
247elif ( action == "check"):
248   print CheckJob(data)
249elif ( action == "cancel"):
250   print CancelJob(data)
251elif ( action == "start"):
252   print GetStartTime(data)
253elif ( action == "stop"):
254   print DoStopNow(data)
255elif ( action == "restart"):
256   print DoRestartNow(data)
257elif ( action == "parin"):
258   print GetPARIN(data)
259elif ( action == "rc"):
260   print GetRC(data) 
261else:
262   print "Error. Action " + action + " unknown."
263
Note: See TracBrowser for help on using the repository browser.