|
@@ -10,8 +10,23 @@
|
|
function tripal_daemon_block_info() {
|
|
function tripal_daemon_block_info() {
|
|
$blocks = array();
|
|
$blocks = array();
|
|
|
|
|
|
- $blocks['tripal_daemon_status'] = array(
|
|
|
|
|
|
+ // Status Blocks.
|
|
|
|
+ $blocks['trpdaemon_status'] = array(
|
|
'info' => t('Tripal Daemon Status'),
|
|
'info' => t('Tripal Daemon Status'),
|
|
|
|
+ 'cache' => DRUPAL_NO_CACHE,
|
|
|
|
+ );
|
|
|
|
+ $blocks['trpdaemon_status_admin'] = array(
|
|
|
|
+ 'info' => t('Tripal Daemon Status: ADMIN'),
|
|
|
|
+ 'cache' => DRUPAL_NO_CACHE,
|
|
|
|
+ 'status' => TRUE,
|
|
|
|
+ 'region' => 'dashboard_sidebar',
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ // Display Log Block.
|
|
|
|
+ $blocks['trpdaemon_log'] = array(
|
|
|
|
+ 'info' => t('Tripal Daemon Log'),
|
|
|
|
+ 'status' => TRUE,
|
|
|
|
+ 'region' => 'dashboard_main',
|
|
);
|
|
);
|
|
|
|
|
|
return $blocks;
|
|
return $blocks;
|
|
@@ -24,59 +39,166 @@ function tripal_daemon_block_view($delta='') {
|
|
$block = array();
|
|
$block = array();
|
|
|
|
|
|
switch($delta) {
|
|
switch($delta) {
|
|
- case 'tripal_daemon_status':
|
|
|
|
- $is_running = drushd_is_daemon_running('tripal_daemon');
|
|
|
|
- $status_class = ($is_running) ? 'active' : 'inactive';
|
|
|
|
|
|
+ case 'trpdaemon_status_admin':
|
|
|
|
+ $block['subject'] = t('Job Daemon Status');
|
|
|
|
+ $block['content'] = theme_tripal_daemon_status_block_content(TRUE);
|
|
|
|
+ break;
|
|
|
|
+ case 'trpdaemon_status':
|
|
$block['subject'] = t('Job Daemon Status');
|
|
$block['subject'] = t('Job Daemon Status');
|
|
$block['content'] = theme_tripal_daemon_status_block_content();
|
|
$block['content'] = theme_tripal_daemon_status_block_content();
|
|
break;
|
|
break;
|
|
|
|
+ case 'trpdaemon_log':
|
|
|
|
+ $block['subject'] = t('Job Daemon Log');
|
|
|
|
+ $block['content'] = drupal_get_form('trpdaemon_display_log_form');
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
|
|
|
|
return $block;
|
|
return $block;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * Provide markup for the Tripal Job Daemon Status block.
|
|
*
|
|
*
|
|
|
|
+ * @param $show_all
|
|
|
|
+ * A boolean indicating whether to show administrative detail (TRUE) or not (FALSE).
|
|
|
|
+ * @return
|
|
|
|
+ * HTML to be rendered for the block.
|
|
*/
|
|
*/
|
|
-function theme_tripal_daemon_status_block_content() {
|
|
|
|
|
|
+function theme_tripal_daemon_status_block_content($show_all = FALSE) {
|
|
$output = '';
|
|
$output = '';
|
|
|
|
|
|
// Get information.
|
|
// Get information.
|
|
$is_running = drushd_is_daemon_running('tripal_daemon');
|
|
$is_running = drushd_is_daemon_running('tripal_daemon');
|
|
$status_file = drushd_get_daemon_status_file('tripal_daemon');
|
|
$status_file = drushd_get_daemon_status_file('tripal_daemon');
|
|
$status = unserialize(file_get_contents($status_file));
|
|
$status = unserialize(file_get_contents($status_file));
|
|
|
|
+ $PID = $status['PID'];
|
|
|
|
+ $is_alive = `ps h --pid $PID | wc -l`;
|
|
|
|
+ $is_alive = trim($is_alive);
|
|
|
|
|
|
$status_class = ($is_running) ? 'active' : 'inactive';
|
|
$status_class = ($is_running) ? 'active' : 'inactive';
|
|
|
|
+ $status_class = ($is_running AND !$is_alive) ? 'dead' : $status_class;
|
|
|
|
|
|
// Theme content.
|
|
// Theme content.
|
|
drupal_add_css(drupal_get_path('module','tripal_daemon') . '/theme/status_block.css');
|
|
drupal_add_css(drupal_get_path('module','tripal_daemon') . '/theme/status_block.css');
|
|
|
|
|
|
|
|
+ // Display the status.
|
|
$output .= '<div class="daemon-status">';
|
|
$output .= '<div class="daemon-status">';
|
|
- if ($is_running) {
|
|
|
|
|
|
+ if ($is_running and $is_alive) {
|
|
$output .= theme_image(array(
|
|
$output .= theme_image(array(
|
|
'path' => 'misc/message-24-ok.png',
|
|
'path' => 'misc/message-24-ok.png',
|
|
'alt' => 'status-ok',
|
|
'alt' => 'status-ok',
|
|
));
|
|
));
|
|
- $output .= 'Running';
|
|
|
|
|
|
+ if ($status['Running Job']) {
|
|
|
|
+ $output .= 'Running Job(s)';
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $output .= 'Waiting for Job';
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
$output .= theme_image(array(
|
|
$output .= theme_image(array(
|
|
'path' => 'misc/message-24-error.png',
|
|
'path' => 'misc/message-24-error.png',
|
|
'alt' => 'status-error',
|
|
'alt' => 'status-error',
|
|
));
|
|
));
|
|
- $output .= 'Stopped';
|
|
|
|
|
|
+ if ($is_running AND !$is_alive) {
|
|
|
|
+ $output .= 'Dead';
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $output .= 'Stopped';
|
|
|
|
+ }
|
|
}
|
|
}
|
|
$output .= '</div>';
|
|
$output .= '</div>';
|
|
|
|
|
|
- $output .= '<ul>';
|
|
|
|
- foreach ($status as $k => $v) {
|
|
|
|
- if (is_bool($v)) {
|
|
|
|
- $v = ($v) ? 'True' : 'False';
|
|
|
|
- }
|
|
|
|
|
|
+ // If asked, show all the details.
|
|
|
|
+ if ($show_all) {
|
|
|
|
+ $output .= '<ul>';
|
|
|
|
+ foreach ($status as $k => $v) {
|
|
|
|
+
|
|
|
|
+ // If it's a boolean, then make it readable.
|
|
|
|
+ if (is_bool($v)) {
|
|
|
|
+ $v = ($v) ? 'True' : 'False';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // If these are current jobs then we want to link to details.
|
|
|
|
+ if ($k == 'Current Jobs' AND !empty($v)) {
|
|
|
|
+ foreach ($v as $job_id) {
|
|
|
|
+ $url = 'admin/tripal/tripal_jobs/view/' . $job_id;
|
|
|
|
+ $v[$job_id] = l($job_id, $url);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- $output .= '<li><strong>' . $k . '</strong>: ' . $v . '</li>';
|
|
|
|
|
|
+ // If it's an array then make it a list.
|
|
|
|
+ if (is_array($v)) {
|
|
|
|
+ if (empty($v)) {
|
|
|
|
+ $v = 'None';
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $v = implode(', ', $v);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $output .= '<li><strong>' . $k . '</strong>: ' . $v . '</li>';
|
|
|
|
+ }
|
|
|
|
+ $output .= '</ul>';
|
|
}
|
|
}
|
|
- $output .= '</ul>';
|
|
|
|
|
|
|
|
return '<div class="inner '.$status_class.'">' . $output . '</div>';
|
|
return '<div class="inner '.$status_class.'">' . $output . '</div>';
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Form to display a user selected number of lines from the Tripal Job Daemon log file.
|
|
|
|
+ */
|
|
|
|
+function trpdaemon_display_log_form($form, $form_state) {
|
|
|
|
+
|
|
|
|
+ $form['#attached']['css'][] = drupal_get_path('module','tripal_daemon') . '/theme/tripal_daemon.log_block.css';
|
|
|
|
+
|
|
|
|
+ $status_file = drushd_get_daemon_status_file('tripal_daemon');
|
|
|
|
+ $status = unserialize(file_get_contents($status_file));
|
|
|
|
+ $file = $status['Current Log File'];
|
|
|
|
+
|
|
|
|
+ $form['num_lines'] = array(
|
|
|
|
+ '#type' => 'radios',
|
|
|
|
+ '#title' => 'Lines',
|
|
|
|
+ '#description' => 'The number of lines to display from the end of the Tripal Job Daemon Log file.',
|
|
|
|
+ '#options' => array(
|
|
|
|
+ '10' => '10',
|
|
|
|
+ '25' => '25',
|
|
|
|
+ '50' => '50',
|
|
|
|
+ '100' => '100',
|
|
|
|
+ '200' => '200',
|
|
|
|
+ '500' => '500',
|
|
|
|
+ ),
|
|
|
|
+ '#default_value' => '25',
|
|
|
|
+ '#attributes' => array(
|
|
|
|
+ 'onChange' => 'this.form.submit();',
|
|
|
|
+ 'class' => array('container-inline'),
|
|
|
|
+ ),
|
|
|
|
+ );
|
|
|
|
+ $num_lines = (isset($form_state['values'])) ? $form_state['values']['num_lines'] : $form['num_lines']['#default_value'];
|
|
|
|
+
|
|
|
|
+ $text = `tail -n $num_lines $file`;
|
|
|
|
+ $text = str_replace("\n", '<br />', $text);
|
|
|
|
+ $form['log'] = array(
|
|
|
|
+ '#type' => 'markup',
|
|
|
|
+ '#markup' => $text,
|
|
|
|
+ '#prefix' => '<pre id="daemon-log">',
|
|
|
|
+ '#suffix' => '</pre>',
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ $form['submit'] = array(
|
|
|
|
+ '#type' => 'submit',
|
|
|
|
+ '#value' => t('Apply'),
|
|
|
|
+ '#attributes' => array(
|
|
|
|
+ 'style' => array('display: none;'),
|
|
|
|
+ ),
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ return $form;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Display Log Form: Submit.
|
|
|
|
+ */
|
|
|
|
+function trpdaemon_display_log_form_submit($form, &$form_state) {
|
|
|
|
+ $form_state['rebuild'] = TRUE;
|
|
|
|
+}
|