IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 19, 2008, 12:29:10 PM (18 years ago)
Author:
eugene
Message:

adding host tracking and restart

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/pantasks/ControllerOps.c

    r18085 r19125  
    1010static IOBuffer stderr_buffer;
    1111static int ControllerPID = 0;
     12
     13/* local static variables to track the controller host properties */
     14static Host *hosts = NULL;
     15static int Nhosts = 0;
     16static int NHOSTS = 0;
     17
     18int AddHost (char *hostname, int max_threads) {
     19
     20  int N;
     21
     22  N = Nhosts;
     23  Nhosts ++;
     24
     25  CHECK_REALLOCATE (hosts, Host, NHOSTS, Nhosts, 16);
     26
     27  hosts[N].hostname = strcreate (hostname);
     28  hosts[N].max_threads = max_threads;
     29 
     30  return (TRUE);
     31}
     32
     33int DeleteHost (char *hostname) {
     34
     35  int i, j;
     36
     37  for (i = 0; i < Nhosts; i++) {
     38    if (strcmp (hosts[i].hostname, hostname)) continue;
     39   
     40    // delete this one
     41    free (hosts[i].hostname);
     42    for (j = i; j < Nhosts - 1; j++) {
     43      hosts[j].hostname = hosts[j+1].hostname;
     44      hosts[j].max_threads = hosts[j+1].max_threads;
     45    }
     46    Nhosts --;
     47    return (TRUE);
     48  }
     49  return (FALSE);
     50}
    1251
    1352/* test if the controller is running */
     
    146185
    147186  /* is pipe still open? */
    148   if ((status == -1) && (errno == EPIPE)) return (CONTROLLER_DOWN);
     187  // XXX call StopController() here?
     188  if ((status == -1) && (errno == EPIPE)) {
     189    StopController ();
     190    return (CONTROLLER_DOWN);
     191  }
    149192
    150193  /* read at least Nbytes, then watch for CONTROLLER_PROMPT */
     
    158201    if (status == -1) nanosleep (&request, &remain);
    159202  }
    160   if (status ==  0) return (CONTROLLER_DOWN);
     203  if (status ==  0) {
     204    StopController ();
     205    return (CONTROLLER_DOWN);
     206  }
    161207  if (status == -1) return (CONTROLLER_HUNG);
    162208
     
    245291  if (VarConfig ("CONTROLLER", "%s", cmd) == NULL) strcpy (cmd, "pcontrol");
    246292
     293  if (hosts == NULL) {
     294    NHOSTS = 16;
     295    ALLOCATE (hosts, Host, NHOSTS);
     296  }
     297
    247298  bzero (stdin_fd,  2*sizeof(int));
    248299  bzero (stdout_fd, 2*sizeof(int));
     
    360411  if ((status == -1) && (errno == EPIPE)) {
    361412    StopController ();
    362     gprint (GP_ERR, "controller is down\n");
     413    gprint (GP_ERR, "controller is down, restarting\n");
     414    if (!RestartController ()) {
     415      return (FALSE);
     416    }
    363417    return (FALSE);
    364418  }
     
    509563  return (TRUE);
    510564}
     565
     566int RestartController () {
     567
     568  int i, status;
     569  char command[256];
     570  IOBuffer buffer;
     571
     572  gprint (GP_ERR, "controller is down, restarting\n");
     573  if (!StartController ()) {
     574    gprint (GP_ERR, "failure to re-start pcontrol\n");
     575    return (FALSE);
     576  }
     577
     578  InitIOBuffer (&buffer, 0x100);
     579
     580  // XXX lock the host table? SerialThreadLock ();
     581  fprintf (stderr, "controller is down, restarting\n");
     582  for (i = 0; i < Nhosts; i++) {
     583    fprintf (stderr, "controller host add %s -threads %d\n", hosts[i].hostname, hosts[i].max_threads);
     584    snprintf (command, 256, "host add %s -threads %d\n", hosts[i].hostname, hosts[i].max_threads);
     585    status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer);
     586  }
     587  // SerialThreadUnlock ();
     588
     589  if (status) gwrite (buffer.buffer, 1, buffer.Nbuffer, GP_LOG);
     590
     591  FreeIOBuffer (&buffer);
     592
     593  return (TRUE);
     594}
Note: See TracChangeset for help on using the changeset viewer.