コード例 #1
0
ファイル: mongrel2.c プロジェクト: daogangtang/monserver
int clear_pid_file(Server *srv)
{
    bstring pid_file = bformat("%s%s", bdata(srv->chroot), bdata(srv->pid_file));

    int rc = Unixy_remove_dead_pidfile(pid_file);
    check(rc == 0, "Failed to remove the dead PID file: %s", bdata(pid_file));
    bdestroy(pid_file);

    return 0;
error:
    return -1;
}
コード例 #2
0
ファイル: procer.c プロジェクト: 304471720/mongrel2
void Action_task(void *v)
{
    Action *action = (Action *)v;
    int rc = 0;
    pid_t child = 0;
    Profile *prof = Profile_load(action->profile_dir);

    taskname(bdata(action->name));

    taskstate("depends");
    rc = Rampart_wait(action->before);
    check(rc != -1, "A dependency failed to start, we can't start.");

    Rampart_running(&action->after);

    taskstate("ready");
    debug("STARTED %s", bdata(action->name));

    while(RUNNING) {
        taskstate("starting");

        if(Unixy_still_running(prof->pid_file, &child)) {
            debug("Looks like %s is already running, we'll just leave it alone.", bdata(action->name));
        } else {
            Unixy_remove_dead_pidfile(prof->pid_file);
            Action_exec(action, prof);
        }

        if(access(bdatae(prof->pid_file, ""), R_OK) != 0) {
            log_warn("%s didn't make pidfile %s. Waiting then trying again.", 
                bdata(action->name), bdata(prof->pid_file));
            Action_sleep(2);
        }

        taskstate("waiting");
        while(Unixy_still_running(prof->pid_file, &child) && RUNNING) {
            Action_sleep(1);
        }

        if(!prof->restart) {
            break;
        }

        taskstate("restarting");
        Action_sleep(1);
    }

    debug("ACTION %s exited.", bdata(action->name));

error:
    Rampart_failed(&action->after);
    return;
}
コード例 #3
0
ファイル: procer.c プロジェクト: mattknox/Mongrel2
void taskmain(int argc, char *argv[])
{
    LOG_FILE = stderr;
    glob_t profile_glob;
    int rc = 0;
    int i = 0;
    Action *action = NULL;
    tst_t *targets = NULL;
    bstring pid_file = NULL;

    check(argc == 3, "USAGE: procer <profile_dir> <procer_pid_file>");
    pid_file = bfromcstr(argv[2]);

    rc = Unixy_remove_dead_pidfile(pid_file);
    check(rc == 0, "Failed to remove %s, procer is probably already running.", bdata(pid_file));

    rc = Unixy_daemonize();
    check(rc == 0, "Couldn't daemonize, that's not good.");

    rc = chdir(argv[1]);
    check(rc == 0, "Couldn't change to %s profile dir.", argv[1]);

    rc = Unixy_pid_file(pid_file);
    check(rc == 0, "Failed to make the PID file: %s", bdata(pid_file));

    FILE *log = fopen("error.log", "a+");
    check(log, "Couldn't open error.log");
    setbuf(log, NULL);
    LOG_FILE = log;

    bstring dir_glob = bformat("%s/[A-Za-z0-9]*", argv[1]);
    check(dir_glob, "Couldn't make the directory glob.");

    rc = glob(bdata(dir_glob), GLOB_ERR | GLOB_ONLYDIR, NULL, &profile_glob);
    check(rc == 0, "Failed to find directories in the profiles.");

    debug("Loading %zu actions.", profile_glob.gl_pathc);
    for(i = 0; i < profile_glob.gl_pathc; i++) {
        action = Action_create(profile_glob.gl_pathv[i]);
        targets = tst_insert(targets, bdata(action->name), blength(action->name), action);
    }

    // now we setup the dependencies from the settings they've got
    tst_traverse(targets, Action_dependency_assign, targets);
    tst_traverse(targets, Action_start_all, NULL);

    taskexit(0);

error:
    taskexitall(1);
}
コード例 #4
0
ファイル: procer.c プロジェクト: 304471720/mongrel2
void taskmain(int argc, char *argv[])
{
    dbg_set_log(stderr);
    glob_t profile_glob;
    int rc = 0;
    int i = 0;
    Action *action = NULL;
    tst_t *targets = NULL;
    bstring pid_file = NULL;
    char *procer_error_log = NULL;

    m2program = procer_program;

    check(argc == 3, "USAGE: %s <profile_dir> <procer_pid_file>", m2program);
    pid_file = bfromcstr(argv[2]);

    srand(time(NULL)); // simple randomness

    rc = Unixy_remove_dead_pidfile(pid_file);
    check(rc == 0, "Failed to remove %s, %s is probably already running.", bdata(pid_file), m2program);

    rc = Unixy_daemonize(1);
    check(rc == 0, "Couldn't daemonize, that's not good.");

    rc = chdir(argv[1]);
    check(rc == 0, "Couldn't change to %s profile dir.", argv[1]);

    rc = Unixy_pid_file(pid_file);
    check(rc == 0, "Failed to make the PID file: %s", bdata(pid_file));

    if( (procer_error_log = getenv("PROCER_ERROR_LOG")) == NULL)
        procer_error_log = "error.log";
    FILE *log = fopen(procer_error_log, "a+");
    check(log, "Couldn't open error.log");
    setbuf(log, NULL);
    dbg_set_log(log);

    bstring dir_glob = bformat("%s/[A-Za-z0-9]*", argv[1]);
    check(dir_glob, "Couldn't make the directory glob.");

    rc = glob(bdata(dir_glob), GLOB_ERR, NULL, &profile_glob);
    check(rc == 0, "Failed to find directories in the profiles.");

    struct stat sb;
    debug("Loading %zu actions.", profile_glob.gl_pathc);

    start_terminator();

    while(RUNNING) {
        for(i = 0; i < profile_glob.gl_pathc; i++) {
            rc = lstat(profile_glob.gl_pathv[i], &sb);
            check(rc == 0, "Failed to stat file or directory: %s", profile_glob.gl_pathv[i]);

            if (sb.st_mode & S_IFDIR) {
                action = Action_create(profile_glob.gl_pathv[i]);
                targets = tst_insert(targets, bdata(action->name), blength(action->name), action);
            }
        }

        // now we setup the dependencies from the settings they've got
        tst_traverse(targets, Action_dependency_assign, targets);
        tst_traverse(targets, Action_start_all, NULL);

        while(RUNNING) {
            Action_sleep(1);
        }
    }

    log_warn("Exiting as requested from procer.");

    taskexit(0);

error:
    taskexitall(1);
}