Exemple #1
0
gboolean
upstart_job_running(const gchar * name)
{
    bool running = FALSE;
    char *job = NULL;

    if(upstart_job_by_name(name, &job)) {
        char *path = get_first_instance(job);

        if (path) {
            char *state = pcmk_dbus_get_property(
                upstart_proxy, BUS_NAME, path, UPSTART_06_API ".Instance", "state");

            crm_info("State of %s: %s", name, state);
            if (state) {
                running = !g_strcmp0(state, "running");
            }
            free(state);
        }
        free(path);
    }

    free(job);
    crm_info("%s is%s running", name, running ? "" : " not");
    return running;
}
Exemple #2
0
/* For a synchronous 'op', returns FALSE if 'op' fails */
gboolean
upstart_job_exec(svc_action_t * op, gboolean synchronous)
{
    char *job = NULL;
    int arg_wait = TRUE;
    const char *arg_env = "pacemaker=1";
    const char *action = op->action;

    DBusError error;
    DBusMessage *msg = NULL;
    DBusMessage *reply = NULL;
    DBusMessageIter iter, array_iter;

    op->rc = PCMK_OCF_UNKNOWN_ERROR;
    CRM_ASSERT(upstart_init());

    if (safe_str_eq(op->action, "meta-data")) {
        op->stdout_data = upstart_job_metadata(op->agent);
        op->rc = PCMK_OCF_OK;
        goto cleanup;
    }

    if(!upstart_job_by_name(op->agent, &job, op->timeout)) {
        crm_debug("Could not obtain job named '%s' to %s", op->agent, action);
        if (!g_strcmp0(action, "stop")) {
            op->rc = PCMK_OCF_OK;

        } else {
            op->rc = PCMK_OCF_NOT_INSTALLED;
            op->status = PCMK_LRM_OP_NOT_INSTALLED;
        }
        goto cleanup;
    }

    if (safe_str_eq(op->action, "monitor") || safe_str_eq(action, "status")) {

        char *path = get_first_instance(job, op->timeout);

        op->rc = PCMK_OCF_NOT_RUNNING;
        if(path) {
            DBusPendingCall *pending = NULL;
            char *state = pcmk_dbus_get_property(
                upstart_proxy, BUS_NAME, path, UPSTART_06_API ".Instance", "state",
                op->synchronous?NULL:upstart_job_check, op,
                op->synchronous?NULL:&pending, op->timeout);

            free(job);
            free(path);

            if(op->synchronous) {
                upstart_job_check("state", state, op);
                free(state);
                return op->rc == PCMK_OCF_OK;
            } else if (pending) {
                services_set_op_pending(op, pending);
                services_add_inflight_op(op);
                return TRUE;
            }
            return FALSE;
        }
        goto cleanup;

    } else if (!g_strcmp0(action, "start")) {
        action = "Start";
    } else if (!g_strcmp0(action, "stop")) {
        action = "Stop";
    } else if (!g_strcmp0(action, "restart")) {
        action = "Restart";
    } else {
        op->rc = PCMK_OCF_UNIMPLEMENT_FEATURE;
        goto cleanup;
    }

    crm_debug("Calling %s for %s on %s", action, op->rsc, job);

    msg = dbus_message_new_method_call(BUS_NAME, // target for the method call
                                       job, // object to call on
                                       UPSTART_JOB_IFACE, // interface to call on
                                       action); // method name
    CRM_ASSERT(msg != NULL);

    dbus_message_iter_init_append (msg, &iter);

    CRM_LOG_ASSERT(dbus_message_iter_open_container (&iter,
                                                     DBUS_TYPE_ARRAY,
                                                     DBUS_TYPE_STRING_AS_STRING,
                                                     &array_iter));

    CRM_LOG_ASSERT(dbus_message_iter_append_basic (&array_iter, DBUS_TYPE_STRING, &arg_env));
    CRM_LOG_ASSERT(dbus_message_iter_close_container (&iter, &array_iter));

    CRM_LOG_ASSERT(dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &arg_wait, DBUS_TYPE_INVALID));

    if (op->synchronous == FALSE) {
        DBusPendingCall* pending = pcmk_dbus_send(msg, upstart_proxy, upstart_async_dispatch, op, op->timeout);
        free(job);

        if(pending) {
            services_set_op_pending(op, pending);
            services_add_inflight_op(op);
            return TRUE;
        }
        return FALSE;
    }

    dbus_error_init(&error);
    reply = pcmk_dbus_send_recv(msg, upstart_proxy, &error, op->timeout);

    if(error.name) {
        if(!upstart_mask_error(op, error.name)) {
            crm_err("Could not issue %s for %s: %s (%s)", action, op->rsc, error.name, job);
        }

    } else if (!g_strcmp0(op->action, "stop")) {
        /* No return vaue */
        op->rc = PCMK_OCF_OK;

    } else if(!pcmk_dbus_type_check(reply, NULL, DBUS_TYPE_OBJECT_PATH, __FUNCTION__, __LINE__)) {
        crm_warn("Call to %s passed but return type was unexpected", op->action);
        op->rc = PCMK_OCF_OK;

    } else {
        const char *path = NULL;

        dbus_message_get_args (reply, NULL,
                               DBUS_TYPE_OBJECT_PATH, &path,
                               DBUS_TYPE_INVALID);
        crm_info("Call to %s passed: %s", op->action, path);
        op->rc = PCMK_OCF_OK;
    }


  cleanup:
    free(job);
    if(msg) {
        dbus_message_unref(msg);
    }

    if(reply) {
        dbus_message_unref(reply);
    }

    if (op->synchronous == FALSE) {
        return operation_finalize(op);
    }
    return op->rc == PCMK_OCF_OK;
}
Exemple #3
0
gboolean
upstart_job_exists(const char *name)
{
    return upstart_job_by_name(name, NULL, DBUS_TIMEOUT_USE_DEFAULT);
}
Exemple #4
0
gboolean
upstart_job_exists(const char *name)
{
    return upstart_job_by_name(name, NULL);
}