Beispiel #1
0
static gboolean
escalate_shutdown(gpointer data)
{

    pcmk_child_t *child = data;

    if (child->pid) {
        /* Use SIGSEGV instead of SIGKILL to create a core so we can see what it was up to */
        crm_err("Child %s not terminating in a timely manner, forcing", child->name);
        stop_child(child, SIGSEGV);
    }
    return FALSE;
}
int main( int argc, char *argv[ ] ) {
	euca_opts euca_args;
	euca_opts *args = &euca_args;
	java_home_t *data = NULL;
	int status = 0;
	pid_t pid = 0;
	uid_t uid = 0;
	gid_t gid = 0;
	if( arguments( argc, argv, args ) != 0 ) exit( 1 );
	debug = args->verbose_flag || args->debug_flag;
	if( args->stop_flag == 1 ) return stop_child( args );
	if( checkuser( GETARG( args, user ), &uid, &gid ) == 0 ) return 1;
	char* java_home_user = GETARG(args,java_home);
	char* java_home_env = getenv( "JAVA_HOME" );
	if( java_home_user != NULL ) {
		__debug("Trying user supplied java home: %s", java_home_user);
		data = get_java_home(java_home_user);
	}
	if( data == NULL && java_home_env != NULL ) {
		__debug("Trying environment JAVA_HOME: %s", java_home_env);
		data = get_java_home(java_home_env);
	}
	__debug("TODO: loop through common locations for JVMs here.");
	if( data == NULL ) {
		__error( "Cannot locate Java Home" );
		return 1;
	}
	int x;
	if( debug == 1 ) {
		__debug( "+-- DUMPING JAVA HOME STRUCTURE ------------------------" );
		__debug( "| Java Home:       \"%s\"", PRINT_NULL( data->path ) );
		__debug( "| Found JVMs:      %d", data->jnum );
		for( x = 0; x < data->jnum; x++ ) {
			jvm_info_t *jvm = data->jvms[ x ];
			__debug( "| JVM Name:        \"%s\"", PRINT_NULL( jvm->name ) );
			__debug( "|                  \"%s\"", PRINT_NULL( jvm->libjvm_path ) );
		}
		__debug( "+-------------------------------------------------------" );
	}
	if( strcmp( argv[ 0 ], "eucalyptus-cloud" ) != 0 ) {
		char *oldpath = getenv( "LD_LIBRARY_PATH" ),*libf = java_library( args, data );
		char *old = argv[ 0 ],buf[ 32768 ],*tmp = NULL,*p1 = NULL,*p2 = NULL;
		p1 = strdup( libf );
		tmp = strrchr( p1, '/' );
		if( tmp != NULL ) tmp[ 0 ] = '\0';
		p2 = strdup( p1 );
		tmp = strrchr( p2, '/' );
		if( tmp != NULL ) tmp[ 0 ] = '\0';
		if( oldpath == NULL ) snprintf( buf, 32768, "%s:%s:%s/bin/linux-x64", p1, p2, GETARG(args,profiler_home) );
		else snprintf( buf, 32768, "%s:%s:%s:%s/bin/linux-x64", oldpath, p1, p2, GETARG(args,profiler_home) );
		tmp = strdup( buf );

		setenv( "LD_LIBRARY_PATH", tmp, 1 );
		__debug( "Invoking w/ LD_LIBRARY_PATH=%s", getenv( "LD_LIBRARY_PATH" ) );
		argv[ 0 ] = "eucalyptus-cloud";
		execve( old, argv, environ );
		__error( "Cannot execute process" );
		return 1;
	}
	__debug( "Running w/ LD_LIBRARY_PATH=%s", getenv( "LD_LIBRARY_PATH" ) );
	if(args->fork_flag) {
		pid = fork( );
		__die(( pid == -1 ),"Cannot detach from parent process" );
		if( pid != 0 ) return wait_child( args, pid );
		setsid( );
	}
	set_output(GETARG(args,out), GETARG(args,err));
	while( ( pid = fork( ) ) != -1 ) {
		if( pid == 0 ) exit( child( args, data, uid, gid ) );
		child_pid = pid;
		signal( SIGHUP, controller );
		signal( SIGTERM, controller );
		signal( SIGINT, controller );
		while( waitpid( pid, &status, 0 ) != pid );
		if( WIFEXITED( status ) ) {
			status = WEXITSTATUS( status );
			__debug( "Eucalyptus exited with status: %d", status );
			if( status != 122 ) unlink( GETARG( args, pidfile ) );
			if( status == 123 ) {
				__debug( "Reloading service" );
				continue;
			}
			if( status == 0 ) {
				__debug( "Service shut down" );
				return 0;
			}
			__error( "Service exit with a return value of %d", status );
			return 1;
		} else {
			__error( "Service did not exit cleanly exit value %d", status );
			return 1;
		}
	}
	__error( "Cannot decouple controller/child processes" );
	return 1;
}
Beispiel #3
0
int main(int argc, char *argv[]) {
	euca_opts euca_args;
	euca_opts *args = &euca_args;
	java_home_t *data = NULL;
	int status = 0;
	pid_t pid = 0;
	uid_t uid = 0;
	gid_t gid = 0;
	int i;
	if (arguments(argc, argv, args) != 0)
		exit(1);
	debug = args->debug_flag;
	set_output(GETARG(args, out), GETARG(args, err));
	if (args->kill_flag == 1)
		return stop_child(args);
	if (checkuser(GETARG(args, user), &uid, &gid) == 0)
		return 1;
	for (i = 0; i < args->java_home_given; ++i) {
		__debug("Trying user supplied java home: %s", args->java_home_arg[i]);
		data = get_java_home(args->java_home_arg[i]);
		if (data != NULL) {
			break;
		}
	}
	char* java_home_env = getenv("JAVA_HOME");
	if (data == NULL && java_home_env != NULL) {
		__debug("Trying environment JAVA_HOME: %s", java_home_env);
		data = get_java_home(java_home_env);
	}
	if (data == NULL && !args->java_home_given && 
            args->java_home_arg[0] != NULL && CHECK_ISDIR(args->java_home_arg[0])) {
		__debug("Trying built-in java home: %s", args->java_home_arg[0]);
		data = get_java_home(args->java_home_arg[0]);
	}
	if (data == NULL && CHECK_ISREG("/usr/bin/java")) {
		char * javapath = (char *) calloc(PATH_MAX, sizeof(char));
		javapath = realpath("/usr/bin/java", javapath);
		if (javapath != NULL) {
			javapath[strlen(javapath)-strlen("jre/bin/java")] = '\0';
			__debug("Trying system java home: %s", javapath);
			data = get_java_home(javapath);
		}
	}
	if (data == NULL) {
		__error("Cannot locate Java Home");
		return 1;
	}
	int x;
	if (debug == 1) {
		__debug("+-- DUMPING JAVA HOME STRUCTURE ------------------------");
		__debug("| Java Home:       \"%s\"", PRINT_NULL(data->path));
		__debug("| Found JVMs:      %d", data->jnum);
		for (x = 0; x < data->jnum; x++) {
			jvm_info_t *jvm = data->jvms[x];
			__debug("| JVM Name:        \"%s\"", PRINT_NULL(jvm->name));
			__debug("|                  \"%s\"", PRINT_NULL(jvm->libjvm_path));
		}
		__debug("+-------------------------------------------------------");
	}
	if (strcmp(argv[0], "eucalyptus-cloud") != 0) {
		char *oldpath = getenv("LD_LIBRARY_PATH"), *libf = java_library(args,
				data);
		char *old = argv[0], buf[32768], *tmp = NULL, *p1 = NULL, *p2 = NULL;
		p1 = strdup(libf);
		tmp = strrchr(p1, '/');
		if (tmp != NULL)
			tmp[0] = '\0';
		p2 = strdup(p1);
		tmp = strrchr(p2, '/');
		if (tmp != NULL)
			tmp[0] = '\0';
		if (oldpath == NULL)
			snprintf(buf, 32768, "%s:%s:%s/bin/linux-x64", p1, p2, GETARG(args,
					profiler_home));
		else
			snprintf(buf, 32768, "%s:%s:%s:%s/bin/linux-x64", oldpath, p1, p2,
					GETARG(args, profiler_home));
		tmp = strdup(buf);

		setenv("LD_LIBRARY_PATH", tmp, 1);
		__debug("Invoking w/ LD_LIBRARY_PATH=%s", getenv("LD_LIBRARY_PATH"));
		argv[0] = "eucalyptus-cloud";
		execve(old, argv, environ);
		__error("Cannot execute process");
		return 1;
	}
	__debug("Running w/ LD_LIBRARY_PATH=%s", getenv("LD_LIBRARY_PATH"));
	if (args->fork_flag) {
		pid = fork();
		__die((pid == -1), "Cannot detach from parent process");
		if (pid != 0)
			return wait_child(args, pid);
		setsid();
	}
	while ((pid = fork()) != -1) {
		if (pid == 0)
			exit(child(args, data, uid, gid));
		child_pid = pid;
		signal(SIGHUP, controller);
		signal(SIGTERM, controller);
		signal(SIGINT, controller);

		while (waitpid(-1, &status, 0) != pid)
			;
		if (WIFEXITED(status)) {
			status = WEXITSTATUS(status);
			__debug("Eucalyptus exited with status: %d", status);
			unlink(GETARG(args, pidfile));
			if (status == EUCA_RET_RELOAD) {
				__debug("Reloading service.");
				continue;
			} else if (status == 0) {
				__debug("Service shut down cleanly.");
				return 0;
			}
			__error("Service exit with a return value of %d.", status);
			return 1;
		} else {
			perror("Service did not exit cleanly.");
			__error("Service did not exit cleanly: exit value=%d.", status);
			return 1;
		}
	}
	__error("Cannot decouple controller/child processes");
	return 1;
}
Beispiel #4
0
int main(int argc, char *argv[])
{
    arg_data *args  = NULL;
    home_data *data = NULL;
    pid_t pid  = 0;
    uid_t uid  = 0;
    gid_t gid  = 0;
    int res;

    /* Parse command line arguments */
    args = arguments(argc, argv);
    if (args == NULL)
        return 1;

    /* Stop running jsvc if required */
    if (args->stop == true)
        return (stop_child(args));

    /* Let's check if we can switch user/group IDs */
    if (checkuser(args->user, &uid, &gid) == false)
        return 1;

    /* Retrieve JAVA_HOME layout */
    data = home(args->home);
    if (data == NULL)
        return 1;

    /* Check for help */
    if (args->help == true) {
        help(data);
        return 0;
    }

#ifdef OS_LINUX
    /* On some UNIX operating systems, we need to REPLACE this current
       process image with another one (thru execve) to allow the correct
       loading of VMs (notably this is for Linux). Set, replace, and go. */
    if (strcmp(argv[0], args->procname) != 0) {
        char *oldpath = getenv("LD_LIBRARY_PATH");
        char *libf    = java_library(args, data);
        char *filename;
        char  buf[2048];
        int   ret;
        char *tmp = NULL;
        char *p1  = NULL;
        char *p2  = NULL;

        /*
         * There is no need to change LD_LIBRARY_PATH
         * if we were not able to find a path to libjvm.so
         * (additionaly a strdup(NULL) cores dump on my machine).
         */
        if (libf != NULL) {
            p1  = strdup(libf);
            tmp = strrchr(p1, '/');
            if (tmp != NULL)
                tmp[0] = '\0';

            p2  = strdup(p1);
            tmp = strrchr(p2, '/');
            if (tmp != NULL)
                tmp[0] = '\0';

            if (oldpath == NULL)
                snprintf(buf, 2048, "%s:%s", p1, p2);
            else
                snprintf(buf, 2048, "%s:%s:%s", oldpath, p1, p2);

            tmp = strdup(buf);
            setenv("LD_LIBRARY_PATH", tmp, 1);

            log_debug("Invoking w/ LD_LIBRARY_PATH=%s",
                      getenv("LD_LIBRARY_PATH"));
        }

        /* execve needs a full path */
        ret = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
        if (ret <= 0)
            strcpy(buf, argv[0]);
        else
            buf[ret] = '\0';

        filename = buf;

        argv[0] = args->procname;
        execve(filename, argv, environ);
        log_error("Cannot execute JSVC executor process (%s)", filename);
        return 1;
    }
    log_debug("Running w/ LD_LIBRARY_PATH=%s", getenv("LD_LIBRARY_PATH"));
#endif /* ifdef OS_LINUX */

    /* If we have to detach, let's do it now */
    if (args->dtch == true) {
        pid = fork();
        if (pid == -1) {
            log_error("Cannot detach from parent process");
            return 1;
        }
        /* If we're in the parent process */
        if (pid != 0) {
            if (args->wait >= 10)
                return wait_child(args, pid);
            else
                return 0;
        }
#ifndef NO_SETSID
        setsid();
#endif
    }

    /*
     * umask() uses inverse logic; bits are CLEAR for allowed access.
     */
    if (~args->umask & 0022) {
        log_error("NOTICE: jsvc umask of %03o allows "
                  "write permission to group and/or other", args->umask);
    }
    envmask = umask(args->umask);
    set_output(args->outfile, args->errfile, args->redirectstdin, args->procname);
    log_debug("Switching umask back to %03o from %03o", envmask, args->umask);
    res = run_controller(args, data, uid, gid);
    if (logger_pid != 0) {
        kill(logger_pid, SIGTERM);
    }

    return res;
}
Beispiel #5
0
static gboolean
pcmk_shutdown_worker(gpointer user_data)
{
    static int phase = 0;
    static time_t next_log = 0;
    static int max = SIZEOF(pcmk_children);

    int lpc = 0;

    if (phase == 0) {
        crm_notice("Shuting down Pacemaker");
        phase = max;

        /* Add a second, more frequent, check to speed up shutdown */
        g_timeout_add_seconds(5, check_active_before_startup_processes, NULL);
    }

    for (; phase > 0; phase--) {
        /* dont stop anything with start_seq < 1 */

        for (lpc = max - 1; lpc >= 0; lpc--) {
            pcmk_child_t *child = &(pcmk_children[lpc]);

            if (phase != child->start_seq) {
                continue;
            }

            if (child->pid) {
                time_t now = time(NULL);

                if (child->respawn) {
                    next_log = now + 30;
                    child->respawn = FALSE;
                    stop_child(child, SIGTERM);
                    if (phase < pcmk_children[pcmk_child_crmd].start_seq) {
                        g_timeout_add(180000 /* 3m */ , escalate_shutdown, child);
                    }

                } else if (now >= next_log) {
                    next_log = now + 30;
                    crm_notice("Still waiting for %s (pid=%d, seq=%d) to terminate...",
                               child->name, child->pid, child->start_seq);
                }
                return TRUE;
            }

            /* cleanup */
            crm_debug("%s confirmed stopped", child->name);
            child->pid = 0;
        }
    }

    /* send_cluster_id(); */
    crm_notice("Shutdown complete");

    {
        const char *delay = daemon_option("shutdown_delay");
        if(delay) {
            sync();
            sleep(crm_get_msec(delay) / 1000);
        }
    }

    g_main_loop_quit(mainloop);

    if (fatal_error) {
        crm_notice("Attempting to inhibit respawning after fatal error");
        crm_exit(DAEMON_RESPAWN_STOP);
    }

    return TRUE;
}