Exemplo n.º 1
0
void CEclAgentExecutionServer::rebuildLogfileName()
{
    logfilespec.clear().append(logDir).append("eclagent");
    addFileTimestamp(logfilespec, true);
    logfilespec.append(".log");
    appendLogFile(logfilespec.str(), 0,0);
}
Exemplo n.º 2
0
int main( int argc, char *argv[] )
{
    int res=0;
    if (argc < 3)
    {
        printf
            ("frunssh <nodelistfile> \"command\" [options] \n"
            "    options: -i:<identity-file> \n"
            "             -u:<user> \n"
            "             -n:<number_of_threads>\n"
            "             -t:<connect-timeout-secs>\n"
            "             -a:<connect-attempts>\n"
            "             -d:<working_directory>\n"
            "             -s                -- strict, must match known_hosts\n"
            "             -b                -- background\n"
            "             -pw:<password>    -- INSECURE: requires pssh (NB identity file preferred)\n"
            "             -pe:<password>    -- INSECURE: as -pw except encrypted password\n"
            "             -pl               -- use plink (on windows)\n"
            "             -v                -- verbose, lists commands run\n"
            "             -d                -- dry run (for testing, enables verbose)\n"
            );
        return 255;
    }


    InitModuleObjects();
    try  {
        StringBuffer logname;
        splitFilename(argv[0], NULL, NULL, &logname, NULL);
        StringBuffer logdir;
        if (getConfigurationDirectory(NULL,"log","frunssh",logname.str(),logdir)) {
            recursiveCreateDirectory(logdir.str());
            StringBuffer tmp(logname);
            addPathSepChar(logname.clear().append(logdir)).append(tmp);
        }
        addFileTimestamp(logname, true);
        logname.append(".log");
        appendLogFile(logname.str(),0,false);
        queryStderrLogMsgHandler()->setMessageFields(MSGFIELD_prefix);

        Owned<IFRunSSH> runssh = createFRunSSH();
        runssh->init(argc,argv);
        runssh->exec();
    }
    catch(IException *e)
    {
        EXCLOG(e,"frunssh");
        e->Release();
        res=255;
    }
    releaseAtoms();
    return res;
}
Exemplo n.º 3
0
StringBuffer& MessageGenerator::generateMessage(const char* method, const char* templatemsg, StringBuffer& message)
{
    if(!method || !*method)
        return message;

    if(http_tracelevel >= 1)
        fprintf(m_logfile, "Automatically generating message from schema for method \"%s\"%s", method, LT);
    
    initCfgDefValues(method);

    if (m_isRoxie)
        genRoxieMessage(templatemsg, message);
    else 
        genNonRoxieMessage(method, templatemsg, message);

    if (m_gfile.get())
    {
        Owned<IFile> tf = createIFile(m_gfile.get());
        {
            Owned<IFileIO> tio = tf->open(IFOcreaterw);
            tio->write(0, message.length(), message.str());
        }
    }

    else if(http_tracelevel > 0)
    {
        fprintf(stderr, "Request for method %s has been generated:\n", method);
        if(http_tracelevel >= 5)
            fprintf(stderr, "%s\n", message.str());

        char c = 'n';
        if(!(m_globals && m_globals->getPropBool("useDefault")))
        {
            fprintf(stderr, "Do you want to modify it?[n/y]");
            c = getchar();
        }

        if(c == 'y' || c == 'Y' || m_keepfile)
        {
            StringBuffer tmpfname;
            tmpfname.append(method);
            addFileTimestamp(tmpfname, false);
#ifdef _WIN32
            tmpfname.insert(0, "c:\\Temp\\");
#else
            tmpfname.insert(0, "/tmp/");
#endif
            Owned<IFile> tf = createIFile(tmpfname.str());
            {
                Owned<IFileIO> tio = tf->open(IFOcreaterw);
                tio->write(0, message.length(), message.str());
            }
            
            if(c == 'y' || c == 'Y')
            {
                StringBuffer cmdline;
#ifdef _WIN32
                cmdline.appendf("notepad.exe %s", tmpfname.str());
                STARTUPINFO sinfo;
                PROCESS_INFORMATION pinfo;
                GetStartupInfo(&sinfo);
                CreateProcess(0, (char*)cmdline.str(), 0, 0, false, 0, 0, 0, &sinfo, &pinfo);
                WaitForSingleObject(pinfo.hProcess, INFINITE);
#else
                cmdline.appendf("vi %s", tmpfname.str());
                if (system(cmdline.str()) == -1)
                    throw MakeStringException(-1, "MessageGenerator::generateMessage: could not execute command %s", cmdline.str());
#endif
                message.clear().loadFile(tmpfname.str(), true);
            }

            if(!m_keepfile)
                tf->remove();
            else
                printf("A copy is saved at %s (unless you specified another location)\n", tmpfname.str());
        }
    }

    return message;
}
Exemplo n.º 4
0
int main(int argc, const char *argv[])
{
    InitModuleObjects();

    int ret = 0;
    bool dryRun = false;
    bool offline = false;
    StringAttr daliServer, envPath;

    enum CmdType { cmd_none, cmd_swap, cmd_auto, cmd_history, cmd_email, cmd_swapped, cmd_reset, cmd_resetspares, cmd_addspares, cmd_removespares, cmd_resethistory };
    CmdType cmd = cmd_none;

    ArgvIterator iter(argc, argv);

    try
    {
        bool stop=false;
        StringArray params;
        for (; !ret&&!iter.done(); iter.next())
        {
            const char *arg = iter.query();
            if ('-' == *arg)
            {
                bool value;
                if (iter.matchFlag(value, "-dryrun"))
                    dryRun = value;
                else if (iter.matchFlag(value, "-offline"))
                    offline = value;
                else
                {
                    PROGLOG("Unknown option");
                    ret = 2;
                    usage();
                    break;
                }
            }
            else
            {
                switch (cmd)
                {
                    case cmd_none:
                        if (strieq("swap", arg))
                            cmd = cmd_swap;
                        else if (strieq("auto", arg))
                            cmd = cmd_auto;
                        else if (strieq("history", arg))
                            cmd = cmd_history;
                        else if (strieq("email", arg))
                            cmd = cmd_email;
                        else if (strieq("swapped", arg))
                            cmd = cmd_swapped;
                        else if (strieq("reset", arg))
                            cmd = cmd_reset;
                        else if (strieq("resetspares", arg))
                            cmd = cmd_resetspares;
                        else if (strieq("addspares", arg))
                            cmd = cmd_addspares;
                        else if (strieq("removespares", arg))
                            cmd = cmd_removespares;
                        else if (strieq("resethistory", arg))
                            cmd = cmd_resethistory;
                        else
                        {
                            PROGLOG("Unknown command");
                            usage();
                            ret = 2;
                        }
                        break;
                    default:
                        params.append(iter.query());
                        break;
                }
            }
        }
        unsigned requiredParams=UINT_MAX;
        switch (cmd)
        {
            case cmd_swap:
                requiredParams = 4;
                break;
            case cmd_addspares:
            case cmd_removespares:
                requiredParams = 3;
                break;
            case cmd_auto:
            case cmd_history:
            case cmd_email:
            case cmd_swapped:
            case cmd_reset:
            case cmd_resetspares:
            case cmd_resethistory:
                requiredParams = 2;
                break;
        }
        if (params.ordinality() < requiredParams)
        {
            usage();
            ret = 2;
        }
        else
        {
            StringAttr daliServer = params.item(0);
            StringAttr clusterName = params.item(1);

            DaliClient dclient(daliServer);
            StringBuffer logname;
            splitFilename(argv[0], NULL, NULL, &logname, NULL);
            addFileTimestamp(logname, true);
            logname.append(".log");
            StringBuffer lf;
            openLogFile(lf, logname.str(),0,false,true);
            queryStderrLogMsgHandler()->setMessageFields(MSGFIELD_prefix);

            Owned<IRemoteConnection> conn = querySDS().connect("/Environment", myProcessSession(), RTM_LOCK_READ, SDS_LOCK_TIMEOUT);
            IPropertyTree *environment = conn->queryRoot();
            StringBuffer xpath("Software/ThorCluster[@name=\"");
            xpath.append(clusterName).append("\"]");
            IPropertyTree *cluster = environment->queryPropTree(xpath.str());
            if (!cluster)
            {
                PROGLOG("Unknown cluster: %s", clusterName.get());
                ret = 3;
            }
            if (!ret)
            {
                Owned<IPropertyTree> options = createPTreeFromIPT(cluster);
                conn.clear();
                if (options&&options->getPropBool("@enableSysLog",true))
                    UseSysLogForOperatorMessages();

                switch (cmd)
                {
                    case cmd_auto:
                    {
                        if (!autoSwapNode(clusterName, dryRun))
                            ret = 3;
                        break;
                    }
                    case cmd_swap:
                    {
                        const char *oldip=params.item(2);
                        const char *newip=params.item(3);
                        if (!swapNode(clusterName, oldip, newip))
                            ret = 3;
                        break;
                    }
                    case cmd_history:
                    case cmd_swapped:
                    case cmd_email:
                    {
                        unsigned days = params.isItem(2) ? atoi(params.item(2)) : 0; // for history or swapped
                        switch (cmd)
                        {
                            case cmd_history:
                                swapNodeHistory(clusterName, days, NULL);
                                break;
                            case cmd_swapped:
                                swappedList(clusterName, days, NULL);
                                break;
                            case cmd_email:
                            {
                                bool sendSwapped = false;
                                bool sendHistory = false;
                                if (params.isItem(2))
                                {
                                    if (strieq("swapped", params.item(2)))
                                        sendSwapped = true;
                                    else if (strieq("history", params.item(2)))
                                        sendHistory = true;
                                }
                                emailSwap(clusterName, NULL, true, sendSwapped, sendHistory);
                                break;
                            }
                        }
                        break;
                    }
                    case cmd_reset:
                    case cmd_resetspares:
                    {
                        StringBuffer response;
                        if (!resetClusterGroup(clusterName, "ThorCluster", cmd==cmd_resetspares, response))
                        {
                            WARNLOG("%s", response.str());
                            ret = 3;
                        }
                        break;
                    }
                    case cmd_addspares:
                    case cmd_removespares:
                    {
                        SocketEndpointArray allEps;
                        unsigned p=2;
                        do
                        {
                            const char *ipOrRange = params.item(p);
                            SocketEndpointArray epa;
                            epa.fromText(ipOrRange, 0);
                            ForEachItemIn(e, epa)
                                allEps.append(epa.item(e));
                            p++;
                        }
                        while (p<params.ordinality());
                        StringBuffer response;
                        bool res;
                        if (cmd == cmd_addspares)
                            res = addClusterSpares(clusterName, "ThorCluster", allEps, response);
                        else
                            res = removeClusterSpares(clusterName, "ThorCluster", allEps, response);
                        if (!res)
                        {
                            WARNLOG("%s", response.str());
                            ret = 3;
                        }
                        break;
                    }
                    case cmd_resethistory:
                    {
                        Owned<IRemoteConnection> conn = querySDS().connect("/SwapNode", myProcessSession(), RTM_LOCK_WRITE, SDS_LOCK_TIMEOUT);
                        if (conn)
                        {
                            StringBuffer groupName;
                            getClusterGroupName(*options, groupName);
                            VStringBuffer xpath("Thor[@group=\"%s\"]", groupName.str());
                            if (conn->queryRoot()->removeProp(xpath.str()))
                                PROGLOG("SwapNode info for cluster %s removed", clusterName.get());
                            else
                                PROGLOG("SwapNode info for cluster %s not found", clusterName.get());
                        }
                        break;
                    }
                }
            }
        }
        UseSysLogForOperatorMessages(false);
    }
    catch (IException *e) {
        EXCLOG(e,"SWAPNODE");
        e->Release();
        ret = -1;
    }

    ExitModuleObjects();
    return ret;
}