Exemplo n.º 1
0
static void
operateHost (char *host, int opCode, int confirm)
{
    char msg1[MAXLINELEN];
    char msg[MAXLINELEN];

    if (opCode == LIM_CMD_REBOOT)
	sprintf(msg1, I18N(256, "Restart LIM on <%s>"), host); /* catgets 256 */
    else
	sprintf(msg1, I18N(257, "Shut down LIM on <%s>"), host); /* catgets 257 */

    if (confirm) {
	sprintf(msg, "%s ? [y/n] ", msg1);
        if (!getConfirm(msg))
	    return;
    }
    fprintf(stderr, "%s ...... ", msg1);
    fflush(stderr);
    if (ls_limcontrol(host, opCode) == -1) {
	ls_perror ("ls_limcontrol");
	exitrc = -1;
    } else {
	char *delay = getenv("LSF_RESTART_DELAY");
	int  delay_time;
	if (delay == 0)
	    delay_time = 500;
	else
	    delay_time = atoi(delay) * 1000;

	millisleep_(delay_time);
	fprintf (stderr, "%s\n", I18N_done);
    }
    fflush(stderr);

}
Exemplo n.º 2
0
static int
doConfirm(int opCode, char *host)
{
    char msg[MAXLINELEN];

    if (host == NULL)
        host = (_i18n_msg_get(ls_catd,NL_SETN,916, "all the hosts")); /* catgets  916  */

    sprintf(msg, "\n%s %s? [y/n] ", opStr, host);

    return getConfirm(msg);

}
Exemplo n.º 3
0
static
void doAllHosts(int opCode)
{
    int numhosts = 0, i;
    struct hostInfo *hostinfo;
    int ask = FALSE, try = FALSE;
    char msg[128];

    hostinfo = ls_gethostinfo("-:server", &numhosts, NULL, 0, LOCAL_ONLY);
    if (hostinfo == NULL) {
	ls_perror("ls_gethostinfo");
	fprintf(stderr, "Operation aborted\n");
        exitrc = -1;
	return;
    }

    if (!fFlag) {
	if (opCode == LIM_CMD_REBOOT)
            sprintf(msg, "Do you really want to restart LIMs on all hosts? [y/n] ");
        else
	    sprintf(msg, "Do you really want to shut down LIMs on all hosts? [y/n] ");
	ask = (!getConfirm(msg));
    }

    for (i = 0; i < numhosts; i++)
        if (hostinfo[i].maxCpus > 0)
	    operateHost (hostinfo[i].hostName, opCode, ask);
        else
	    try = 1;
    if (try) {
        fprintf(stderr, "\n%s :\n\n", "Trying unavailable hosts");
        for (i = 0; i < numhosts; i++)
            if (hostinfo[i].maxCpus <= 0)
	        operateHost (hostinfo[i].hostName, opCode, ask);
    }

}
Exemplo n.º 4
0
int
limCtrl(int argc, char **argv, int opCode)
{
    char *optName;
    char *localHost;
    int vFlag = 0;
    int config = 0, checkReply;

    fFlag = 0;
    if (strcmp(argv[optind-1], "reconfig") == 0) {
	config = 1;
    }

    while ((optName = myGetOpt(argc, argv, "f|v|")) != NULL) {
        switch (optName[0]) {
            case 'v':
                if (opCode == LIM_CMD_SHUTDOWN)
                    return(-2);
                vFlag = 1;
                break;
            case 'f':
                fFlag = 1;
                break;
            default:
                return(-2);
        }
    }
    exitrc = 0;
    if (config && optind != argc)
        return -2;

    switch (checkReply)  {
	case EXIT_FATAL_ERROR:
            return -1;
	case EXIT_WARNING_ERROR:
            if (fFlag)
                break;
            if (!getConfirm(I18N(250, "Do you want to reconfigure? [y/n] "))) /* catgets 250 */ {
                fprintf(stderr, I18N(251, "Reconfiguration aborted.\n")); /* catgets 251 */
                return(-1);
            }
            break;
        default:
            break;
    }

    if (config) {
        doAllHosts(opCode);
        return(exitrc);
    }

    if (optind == argc) {
	if ((localHost = ls_getmyhostname()) == NULL) {
            ls_perror("ls_getmyhostname");
            return -1;
	}
        operateHost(localHost, opCode, 0);
    }
    else
    {
	doHosts(argc, argv, opCode);
    }

    return(exitrc);

}
Exemplo n.º 5
0
int
breconfig (int argc, char **argv, int configFlag)
{
  char *optName;
  int vFlag = 0;
  int fFlag = 0;
  int checkReply;
  int stdoutsave;
  int fd;
  FILE *fp;
  char *linep;
  char tmpfile[256];
  char *tmpname = "tmpXXXXXX";

  while ((optName = myGetOpt (argc, argv, "f|v|")) != NULL)
    {
      switch (optName[0])
	{
	case 'v':
	  vFlag = 1;
	  break;
	case 'f':
	  fFlag = 1;
	  break;
	default:
	  return (-2);
	}
    }
  if (optind < argc)
    {
      return (-2);
    }

  if (!vFlag && !fFlag)
    {

      fprintf (stderr, "\nChecking configuration files ...\n\n");

      stdoutsave = dup (1);
      sprintf (tmpfile, "/tmp/%s", tmpname);
      mktemp (tmpfile);
      fd = open (tmpfile, O_RDWR | O_CREAT | O_TRUNC, 0666);
      if (fd > 0)
	{

	  dup2 (fd, 1);
	  dup2 (fd, 2);
	  checkReply = checkConf (1, 2);
	  fflush (stderr);
	  close (fd);
	  dup2 (stdoutsave, 1);
	  dup2 (stdoutsave, 2);
	  fp = fopen (tmpfile, "r");
	  if (fp != 0)
	    {
	      if (checkReply == EXIT_FATAL_ERROR
		  || checkReply == EXIT_WARNING_ERROR)
		{
		  if (checkReply == EXIT_FATAL_ERROR)
		    fprintf (stderr, "There are fatal errors.\n\n");
		  else
		    fprintf (stderr, "There are warning errors.\n\n");
		  fflush (stderr);

		  if (getConfirm ((_i18n_msg_get (ls_catd, NL_SETN, 2563, "Do you want to see detailed messages? [y/n] "))))	/* catgets  2563  */
		    while ((linep = getNextLine_ (fp, 0)))
		      fprintf (stderr, "%s\n", linep);
		}
	      else
		fprintf (stderr, I18N (2586, "No errors found.\n\n"));	/* catgets 2586 */
	      fflush (stderr);
	    }
	  fclose (fp);
	  unlink (tmpfile);
	}
      else
	checkReply = checkConf (0, 2);
    }
  else
    checkReply = checkConf (vFlag, 2);

  if (configFlag == MBD_CKCONFIG)
    {
      return (0);
    }

  switch (checkReply)
    {
    case EXIT_FATAL_ERROR:
      return -1;
    case EXIT_WARNING_ERROR:
      if (fFlag)
	break;
      if (configFlag == MBD_RECONFIG)
	{
	  if (!getConfirm
	      ((_i18n_msg_get
		(ls_catd, NL_SETN, 2564,
		 "\nDo you want to reconfigure? [y/n] "))))
	    {			/* catgets  2564  */
	      fprintf (stderr, (_i18n_msg_get (ls_catd, NL_SETN, 2565, "Reconfiguration aborted.\n")));	/* catgets  2565  */
	      return (-1);
	    }
	}
      else
	{
	  if (!getConfirm
	      (I18N (2570, "\nDo you want to restart MBD? [y/n] ")))
	    {			/* catgets  2570  */
	      fprintf (stderr, (I18N (2571, "MBD restart aborted.\n")));	/* catgets  2571  */
	      return (-1);
	    }
	}
    default:
      ;
    }

  if (lsb_reconfig (configFlag) < 0)
    {
      lsb_perror ((_i18n_msg_get (ls_catd, NL_SETN, 2566, "Failed")));	/* catgets  2566  */
      return (-1);
    }

  if (configFlag == MBD_RECONFIG)
    {
      printf ("%s\n", _i18n_msg_get (ls_catd, NL_SETN, 2567, "Reconfiguration initiated"));	/* catgets  2567  */
    }
  else
    {
      printf ("%s\n", I18N (2569, "MBD restart initiated"));	/* catgets  2569  */
    }
  return (0);

}
Exemplo n.º 6
0
static int
doLsCmd (int argc, char *argv[])
{
    int cmdRet = 0, cc, myIndex;

    if ((myIndex = adminCmdIndex(argv[optind-1], cmdList)) == -1) {
        fprintf(stderr, "Invalid command <%s>. Try help\n", argv[optind - 1]);
            return -1;
    }
    switch (myIndex) {
        case LSADM_CKCONFIG :
            if ((argc == optind + 1) && strcmp(argv[optind], "-v") == 0)
                cc =  checkConf(1, 1);
            else if (argc == optind) {
                cc = checkConf(0, 1);
                if (cc == -1 || cc == -2)
                    if (getConfirm("Do you want to see detailed messages? [y/n] "));
                cc =  checkConf(1, 1);
            } else
                cmdRet = -2;
            if (cmdRet == 0 && cc != 0)
                cmdRet = -1;
            break;
        case LSADM_RECONFIG :
        case LSADM_LIMREBOOT :
        case LSADM_LIMSHUTDOWN :
            cmdRet = limCtrl(argc, argv, opCodeList[myIndex]);
            break;
        case LSADM_LIMSTARTUP :
            cmdRet = startup(argc, argv, myIndex);
            break;
        case LSADM_LIMLOCK :
            cmdRet = limLock(argc, argv);
            break;
        case LSADM_LIMUNLOCK :
            cmdRet = limUnlock(argc, argv);
            break;
        case LSADM_RESREBOOT :
        case LSADM_RESSHUTDOWN :
        case LSADM_RESLOGON :
        case LSADM_RESLOGOFF :
            cmdRet = resCtrl(argc, argv, opCodeList[myIndex]);
            break;
        case LSADM_LIMDEBUG:
        case LSADM_LIMTIME:
        case LSADM_RESDEBUG:
        case LSADM_RESTIME:
            cmdRet = lsadminDebug(argc, argv, opCodeList[myIndex]);
            break;
        case LSADM_RESSTARTUP :
            cmdRet = startup(argc, argv, myIndex);
            break;
        case LSADM_HELP :
        case LSADM_QES :
            cmdHelp(argc, argv, cmdList, cmdInfo, cmdSyntax);
            break;
        case LSADM_QUIT :
            exit(0);
        default :
            fprintf(stderr, "adminCmdIndex: Error");
            exit(-1);
    }
    if (cmdRet == -2)
	oneCmdUsage(myIndex, cmdList, cmdSyntax);

    fflush(stderr);
    return (cmdRet);

}