예제 #1
0
void CALLBACK serviceMain(DWORD argc, LPTSTR *argv)
{
	serviceName.Printf(wxT("%s"), (const char *)argv[0]);
	serviceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
	serviceStatus.dwCurrentState = SERVICE_START_PENDING;
	serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE;
	serviceStatus.dwWin32ExitCode = 0;
	serviceStatus.dwCheckPoint = 0;
	serviceStatus.dwWaitHint = 15000;
	serviceStatusHandle = RegisterServiceCtrlHandler(serviceName.c_str(), serviceHandler);
	if (serviceStatusHandle)
	{
		SetServiceStatus(serviceStatusHandle, &serviceStatus);
		if (initService())
		{
			serviceStatus.dwCurrentState = SERVICE_RUNNING;
			serviceStatus.dwWaitHint = 1000;
		}
		else
			serviceStatus.dwCurrentState = SERVICE_STOPPED;

		SetServiceStatus(serviceStatusHandle, &serviceStatus);


	}
}
예제 #2
0
int mtServiceMonitorMgr::init( DataInit* pkDataInit )
{
	m_pkQueueMgr = pkDataInit->pkQueueMgr;

	initService();

	return 1;
}
예제 #3
0
int main(int argc, char *argv[])
{
    char *envp = NULL;

    set_oom_adj(-1000);
    if (initService(argc, argv) != 0)
        return -1;

    envp = ::getenv("SCI_DISABLE_IPV6");
    if (envp && (::strcasecmp(envp, "yes") == 0)) {
        Socket::setDisableIPv6(1);
    }

    ExtListener *listener = new ExtListener();
    listener->start();

    launcherList.clear();
    while (1) {
        Locker::getLocker()->freeze();

        log_debug("Delete unused launcher");
        Locker::getLocker()->lock();
        vector<ExtLauncher *>::iterator lc;
        for (lc = launcherList.begin(); lc != launcherList.end(); lc++) {
            while (!(*lc)->isLaunched()) {
                // before join, this thread should have been launched
                SysUtil::sleep(WAIT_INTERVAL);
            }
            (*lc)->join();
            delete (*lc);
        }
        launcherList.clear();
        Locker::getLocker()->unlock();

        log_info("Begin to cleanup the jobInfo");
        Locker::getLocker()->lock();
        JOB_INFO::iterator it;
        for (it = jobInfo.begin(); it != jobInfo.end(); ) {
            if ((SysUtil::microseconds() - it->second.timestamp) > FIVE_MINUTES) {
                log_crit("Erase jobInfo item %d", it->first);
                jobInfo.erase(it++);
            } else {
                ++it;
            }
        }
        log_info("Finish cleanup the jobInfo");
        Locker::getLocker()->unlock();
    }

    listener->join();
    delete listener;
    delete Log::getInstance();

    return 0;
}
예제 #4
0
int mtServiceMgr::init( DataInit* pkDataInit )
{
	m_pkSQLEnv				= pkDataInit->pkSQLEnv;
	m_lSpinCount                   = pkDataInit->lSpinCount;
	m_pkQueueMgr                   = pkDataInit->pkQueueMgr;
	m_pcServiceExeDir              = pkDataInit->pcServiceExeDir;

	initService();

	return 1;
}
예제 #5
0
void App::Register(AppIf * appif)
{
	syslog(LOG_DEBUG, "%s ENTRY",__func__);
	this->appIf=appif;
	appIf->init(argc,argv);
	initGetKey();
	initService();
	while(1)
	{
		syslog(LOG_INFO,"App Run {epoll->run()}");
		Epoll::getInstance()->run();
	}
	syslog(LOG_ERR,"this is imposible");
}
예제 #6
0
/**
 * \fn int main(int argc, char *argv[])
 *	@param argc Number of arguments provided by user
 *	@param argv[] Arguments for deciding sleep time for threads and for opening specific LOG file
 *
 *	@return '0' for normal exit, '-1' for abnormal exit/error
 *
 *  @brief Main process, runs all other processes
 *
 *      Function initializes shared memories and calls processes related to main process
 */
int main(int argc, char *argv[])
{
    pid_t pid;
    int i;


    guestPnt = shmget( (key_t)SHARED_MEM_GUEST, 1*sizeof(int), 0777|IPC_CREAT);
    //if( guestPnt < 0)
    //    perror("shmget");

    guestCount = (int *)shmat(guestPnt, 0, 0);
    guestCount[0] = 0;

    occpID = shmget( (key_t)SHARED_MEM_OCCP, 3*sizeof(int), 0777|IPC_CREAT);
    occpInd = (int *)shmat(occpID, 0 ,0);
    occpInd[0] = occpInd[1] = occpInd[2] = 0;

    masterBreakid = shmget( (key_t)SHARED_MEM_MASTERBR, 1*sizeof(int), 0777|IPC_CREAT);
    masterBreak = (int *)shmat(masterBreakid, 0 ,0);

    printf("Initializing Service Room\n");

    initService();



    //for(i = 0; i < NUM_GUESTS-1; i++)
    //  update_GuestBook( &mySRO[i] );
    for(i = 0; i < 3; i++){
        if ((pid = fork()) == 0){
            serveGuest( i );
        }
    }

    //shmctl(guestPnt, IPC_RMID, 0);

    sem_close( maachEnable);
    sem_close( dalEnable);
    sem_close( bhaatEnable);

    sem_unlink(SEM_MAACH_ENABLE);
    sem_unlink(SEM_DAL_ENABLE);
    sem_unlink(SEM_BHAAT_ENABLE);

}
예제 #7
0
StaticPoseNode::StaticPoseNode(ros::NodeHandle & n)
        : n_(n)
        , n_param_("~")
        , frequency_(FREQUENCY)
        , publishTF_(PUBLISH_TF)
        , sync_with_pub_(SYNC_WITH_A_PUBLISHER) {

    n_param_.getParam ( "frequency", frequency_ );
    ROS_INFO("\tfrequency: %5.2f", frequency_);

    std::string poseFile(POSE_FILE);
    n_param_.getParam ( "pose_file", poseFile );
    ROS_INFO("\tpose_file: %s", poseFile.c_str());


    std::string poseFileFolder(POSE_FILE_FOLDER);
    n_param_.getParam ( "pose_file_folder", poseFileFolder );
    ROS_INFO("\tpose_file_folder: %s", poseFileFolder.c_str());

    std::string poseFileFolderRegex(POSE_FILE_REGEX);
    n_param_.getParam ( "pose_file_folder_regex", poseFileFolderRegex );
    ROS_INFO("\tpose_file_folder_regex: %s", poseFileFolderRegex.c_str());

    n_param_.getParam ( "publish_tf", publishTF_ );
    ROS_INFO("\tpublish_tf: %s", (publishTF_?"true":"false") );


    n_param_.getParam ( "sync", sync_with_pub_ );
    ROS_INFO("\tsync: %s", (sync_with_pub_?"true":"false") );

    if (sync_with_pub_) {
        sub_ = n_.subscribe("camera_info", 1000, &StaticPoseNode::callbackSync, this);
    }

    readFile(poseFile);
    readFileFolder(poseFileFolder, poseFileFolderRegex);

    initService();
}
예제 #8
0
int main(int argc, char* argv[])
{
	char *arg;

    if (!initService())
	{
		logMessage("ERROR: Failed to initialise service.\n");
		return 1;
	}

	if (argc == 1)
	{
		/* Service table entry to start service. */
		SERVICE_TABLE_ENTRY lpServiceTable[] = 
		{
			{SERVICE_NAME, (LPSERVICE_MAIN_FUNCTION)ServiceMain},
			{0, 0}
		};

		/* Start the service. */
		if (!StartServiceCtrlDispatcher(lpServiceTable))
		{
			DWORD err = GetLastError();
			if (err == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)
			{
				logMessage("ERROR: Can't run service as a command line program, it must be installed as a service and the '%s' service started.\n", SERVICE_NAME);
				printf("Can't run service as a command line program, it must be installed as a service and the '%s' service started.\n\n", SERVICE_NAME);
			}
			else if (err == ERROR_INVALID_DATA)
			{
				logMessage("BUG: Invalid service dispatch table information.\n");
			}
			else if (err == ERROR_SERVICE_ALREADY_RUNNING)
			{
				logMessage("ERROR: Failed to start service %s because it is already running.\n", SERVICE_NAME);
			}
			else
			{
				logMessage("ERROR: Failed to start service %s because it is already running.\n", SERVICE_NAME);
			}
		}
	}
	else
	{
		arg = argv[1];
		while (*arg != '\0' && *arg == '-') arg++;
		if (_stricmp("install", arg) == 0)
		{
			/* Install the service. */
			return installService();
		}
		else if (_stricmp("uninstall", arg)  == 0)
		{
			/* Remove the service. */
			return uninstallService();
		}
		else if (_stricmp("help", arg) == 0 || *arg == 'h')
		{		
			/* Print help. */
			printf("Usage: %s [install]|[uninstall]\n\n", argv[0]);
			printf("\t- install   - Installs the %s service. For installation to\n", SERVICE_NAME);
			printf("\t              succeed the service must not be currently install.\n");
			printf("\t- uninstall - Removes the service %s.\n\n", SERVICE_NAME);
			printf("Once the service is installed the following Windows commands allow\n");
			printf("the %s service to started and stopped\n\n", SERVICE_NAME);
			printf("\t- Start %s: net start \"%s\"\n", SERVICE_NAME, SERVICE_NAME);
			printf("\t- Stop %s:  net stop \"%s\"\n\n", SERVICE_NAME, SERVICE_NAME);
			printf("Alternatively, the %s service may be started or stopped using the\n", SERVICE_NAME);
			printf("Windows Services Administrative Tool, located in:\n\n");
			printf("\tControl Panel -> Administrative Tools -> Services\n\n");
		}
	}

	return 0;
}
예제 #9
0
struct Service *newService(const char *arg) {
  struct Service *service;
  check(service = malloc(sizeof(struct Service)));
  initService(service, arg);
  return service;
}
예제 #10
0
void main(int argc, char **argv)
{
	// Statup wx
	wxInitialize();

	wxFileName file = wxString::FromAscii(*argv++);
	file.MakeAbsolute();
	wxString executable = file.GetFullPath();

	if (argc < 3)
	{
		usage(executable);
		return;
	}

	wxString command;
	command = wxString::FromAscii(*argv++);

	if (command != wxT("DEBUG"))
	{
		serviceName = wxString::FromAscii(*argv++);
		argc -= 3;
	}
	else
		argc -= 2;

	if (command == wxT("INSTALL"))
	{
		wxString displayname = _("PostgreSQL Scheduling Agent - ") + serviceName;
		wxString args = wxT("RUN ") + serviceName;

		while (argc-- > 0)
		{
			if (argv[0][0] == '-')
			{
				switch (argv[0][1])
				{
					case 'u':
					{
						user = getArg(argc, argv);
						break;
					}
					case 'p':
					{
						password = getArg(argc, argv);
						break;
					}
					case 'd':
					{
						displayname = getArg(argc, argv);
						break;
					}
					default:
					{
						args += wxT(" ") + wxString::FromAscii(*argv);
						break;
					}
				}
			}
			else
			{
				args += wxT(" ") + wxString::FromAscii(*argv);
			}

			argv++;
		}

		bool rc = installService(serviceName, executable, args, displayname, user, password);
	}
	else if (command == wxT("REMOVE"))
	{
		bool rc = removeService(serviceName);
	}
	else if (command == wxT("DEBUG"))
	{
		setupForRun(argc, argv, true, executable);

		initService();
#if START_SUSPENDED
		continueService();
#endif

		WaitForSingleObject(threadHandle, INFINITE);
	}
	else if (command == wxT("RUN"))
	{
		wxString app = _("pgAgent Service");

		SERVICE_TABLE_ENTRY serviceTable[] =
		{ (LPWSTR)app.wc_str(), serviceMain, 0, 0};

		setupForRun(argc, argv, false, executable);

		if (!StartServiceCtrlDispatcher(serviceTable))
		{
			DWORD rc = GetLastError();
			if (rc)
			{
			}
		}
	}
	else
	{
		usage(executable);
	}

	return;
}
예제 #11
0
파일: angel.c 프로젝트: doghell/appweb-3
int APIENTRY WinMain(HINSTANCE inst, HINSTANCE junk, char *args, int junk2)
{
    char    **argv, *argp, *serviceArgs, *homeDir;
    int     argc, err, nextArg, installFlag;

    mpr = mprCreate(0, NULL, NULL);

    appInst = inst;
    serviceArgs = 0;
    err = 0;
    exiting = 0;
    installFlag = 0;
    homeDir = 0;
    heartBeatPeriod = HEART_BEAT_PERIOD;

    initService();

    mprSetAppName(mpr, BLD_PRODUCT "Angel", BLD_NAME "Angel", BLD_VERSION);
    appName = mprGetAppName(mpr);
    appTitle = mprGetAppTitle(mpr);

    mprSetLogHandler(mpr, logHandler, NULL);

    /*
     *  Create the window 
     */
    if (initWindow() < 0) {
        mprError(mpr, "Can't initialize application Window");
        return FALSE;
    }

    /*
     *  Parse command line arguments
     */
    if (mprMakeArgv(mpr, "", args, &argc, &argv) < 0) {
        return FALSE;
    }
    for (nextArg = 1; nextArg < argc; nextArg++) {
        argp = argv[nextArg];
        if (*argp != '-' || strcmp(argp, "--") == 0) {
            break;
        }

        if (strcmp(argp, "--args") == 0) {
            /*
             *  Args to pass to service when it starts
             */
            if (nextArg >= argc) {
                err++;
            } else {
                serviceArgs = argv[++nextArg];
            }

        } else if (strcmp(argp, "--console") == 0) {
            /*
             *  Allow the service to interact with the console
             */
            createConsole++;

        } else if (strcmp(argp, "--daemon") == 0) {
            /* Ignored on windows */

        } else if (strcmp(argp, "--heartBeat") == 0) {
            /*
             *  Set the heart beat period
             */
            if (nextArg >= argc) {
                err++;
            } else {
                heartBeatPeriod = atoi(argv[++nextArg]) * 1000;
            }

        } else if (strcmp(argp, "--home") == 0) {
            /*
             *  Change to this directory before starting the service
             */
            if (nextArg >= argc) {
                err++;
            } else {
                homeDir = argv[++nextArg];
            }

        } else if (strcmp(argp, "--program") == 0) {
            if (nextArg >= argc) {
                err++;
            } else {
                serviceProgram = argv[++nextArg];
            }

        } else if (strcmp(argp, "--install") == 0) {
            installFlag++;

        } else if (strcmp(argp, "--start") == 0) {
            /*
             *  Start the angel
             */
            if (startService() < 0) {
                return FALSE;
            }
            mprSleep(mpr, 2000);    /* Time for service to really start */

        } else if (strcmp(argp, "--stop") == 0) {
            /*
             *  Stop the  angel
             */
            if (removeService(0) < 0) {
                return FALSE;
            }

        } else if (strcmp(argp, "--uninstall") == 0) {
            /*
             *  Remove the  angel
             */
            if (removeService(1) < 0) {
                return FALSE;
            }

        } else if (strcmp(argp, "--verbose") == 0 || strcmp(argp, "-v") == 0) {
            verbose++;

        } else {
            err++;
        }

        if (err) {
            mprUserError(mpr, 
                "Bad command line: %s\n"
                "  Usage: %s [options] [program args]\n"
                "  Switches:\n"
                "    --args               # Args to pass to service\n"
                "    --console            # Display the service console\n"
                "    --heartBeat interval # Heart beat interval period (secs)\n"
                "    --home path          # Home directory for service\n"
                "    --install            # Install the service\n"
                "    --program            # Service program to start\n"
                "    --start              # Start the service\n"
                "    --stop               # Stop the service\n"
                "    --uninstall          # Uninstall the service",
                args, appName);
            return -1;
        }
    }

    if (installFlag) {
        /*
         *  Install the angel
         */
        if (installService(homeDir, serviceArgs) < 0) {
            return FALSE;
        }
    }

    if (argc <= 1) {
        /*
         *  This will block if we are a service and are being started by the
         *  service control manager. While blocked, the svcMain will be called
         *  which becomes the effective main program. 
         */
        startDispatcher(serviceMain);
    }
    return 0;
}
예제 #12
0
 /**
  * @brief Sets the name of the ROS Service serve to connect to. Use initService to create a Service client to a service with this name.
  */
 virtual void setServiceName(const std::string& service_name) { service_name_ = service_name; initService();};
예제 #13
0
 /**
  * @brief Creates a ROS Service client for the Service server with the given name.
  * 
  * @param service_name Name of the ROS Service server to connect to.
  * @param verbose If true some ROS_INFO messages will be printed out during service calls.
  */
 iiwaServices(const std::string& service_name, const bool verbose = true) : service_name_(service_name), verbose_(verbose), service_ready_(false) {
   initService();
 }
예제 #14
0
	integer ServiceApp::startCommand(ConstStrA command, const Args & args, SeqFileOutput &serr) {
		if (command == ConstStrA(startCmd)) {
			integer x = validateService(args,serr);
			if (x) return x;
			createInstanceFile();
			x = onMessage(command,args,serr);
			if (x) return x;
			x = initService(args,serr);
			if (x) return x;
			serr = nil;
			instance->enterDaemonMode(restartDelaySec);
			return startService();
		} else if (command == ConstStrA(startForeCmd)) {
			integer x = validateService(args,serr);
			if (x) return x;
			createInstanceFile();
			x = onMessage(command,args,serr);
			if (x) return x;
			x = initService(args,serr);
			if (x) return x;
			return startService();
		} else if (command == ConstStrA(restartCmd)){
			integer x = validateService(args,serr);
			if (x) return x;
			try {
				instance->open();
				postMessage(stopCmd,Args(), serr);
				instance->waitForTerminate(timeout);
			} catch (ProgInstance::NotRunningException &) {
			} catch (ProgInstance::TimeoutException &) {
				instance->terminate();
				instance->waitForTerminate(timeout);
			}
			createInstanceFile();
			x = onMessage(command,args,serr);
			if (x) return x;
			x = initService(args,serr);
			if (x) return x;
			serr = nil;
			instance->enterDaemonMode(restartDelaySec);
			return startService();
		} else if (command == ConstStrA(stopCmd)) {
			try {
				instance->open();
				integer res = postMessage(command,args, serr);
				if (res == 0) instance->waitForTerminate(timeout);
				return res;
			} catch (ProgInstance::TimeoutException &) {
				instance->terminate();
				return 0;
			}
		} else if (command == ConstStrA(waitCmd)) {
			natural timeout = naturalNull;
			if (!args.empty()) {
				TextParser<wchar_t> parser;
				if (parser(L" %u1 ",args[0])) timeout = parser[1];
			}
			instance->open();
			instance->waitForTerminate(timeout);
		}
		else if (command == ConstStrA(testCmd)) {
			integer x = validateService(args, serr);
			return x;
		} else if (command == ConstStrA(runTestsCmd)) {
			if (args.empty())
				return Singleton<TestCollector>::getInstance().runTests(ConstStrA(), serr);
			else if (args[0] == ConstStrW(L"list")) {
				SeqTextOutA out(serr);
				TextOut<SeqTextOutA> print(out);
				print("%1\n")<<(Singleton<TestCollector>::getInstance().listTests());
				return 0;
			}
			else
				return Singleton<TestCollector>::getInstance().runTests(args[1], serr);
		
		} else {
			instance->open();
			return postMessage(command,args, serr);
		}
		return 0;
	}