From 81eae49a1b5dfeadb9aac5974ec87cd01aed9ffd Mon Sep 17 00:00:00 2001 From: "Nathan S. Evans" Date: Tue, 26 Jul 2011 18:22:54 +0000 Subject: start service --- src/testing/testing.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 7 deletions(-) (limited to 'src/testing/testing.c') diff --git a/src/testing/testing.c b/src/testing/testing.c index 79c67e89c..a079390ad 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -1043,12 +1043,12 @@ GNUNET_TESTING_daemon_running (struct GNUNET_TESTING_Daemon *daemon) /** - * Stops a GNUnet daemon. + * Starts a GNUnet daemon service which has been previously stopped. * * @param d the daemon for which the service should be started * @param service the name of the service to start * @param timeout how long to wait for process for shutdown to complete - * @param cb function called once the daemon was stopped + * @param cb function called once the service starts * @param cb_cls closure for cb */ void @@ -1069,13 +1069,9 @@ GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d, d->phase = SP_START_DONE; } -#if DEBUG_TESTING - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id)); -#endif if (d->churned_services == NULL) { - d->dead_cb(d->dead_cb_cls, "No service has been churned off yet!!"); + d->cb(d->cb_cls, &d->id, d->cfg, d, "No service has been churned off yet!!"); return; } d->phase = SP_SERVICE_START; @@ -1131,6 +1127,85 @@ GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d, d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d); } +/** + * Starts a GNUnet daemon's service. + * + * @param d the daemon for which the service should be started + * @param service the name of the service to start + * @param timeout how long to wait for process for startup + * @param cb function called once gnunet-arm returns + * @param cb_cls closure for cb + */ +void +GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d, + char *service, + struct GNUNET_TIME_Relative timeout, + GNUNET_TESTING_NotifyDaemonRunning cb, void *cb_cls) +{ + char *arg; + d->cb = cb; + d->cb_cls = cb_cls; + + GNUNET_assert(service != NULL); + GNUNET_assert(d->running == GNUNET_YES); + GNUNET_assert(d->phase == SP_START_DONE); + +#if DEBUG_TESTING + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + _("Starting service %s for peer `%4s'\n"), service, GNUNET_i2s (&d->id)); +#endif + + d->phase = SP_SERVICE_START; + + /* Check if this is a local or remote process */ + if (NULL != d->hostname) + { +#if DEBUG_TESTING + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Starting gnunet-arm with config `%s' on host `%s'.\n", + d->cfgfile, d->hostname); +#endif + + if (d->username != NULL) + GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); + else + arg = GNUNET_strdup (d->hostname); + + d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", +#if !DEBUG_TESTING + "-q", +#endif + arg, "gnunet-arm", +#if DEBUG_TESTING + "-L", "DEBUG", +#endif + "-c", d->cfgfile, "-i", service, "-q", + NULL); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i %s -q\n", + arg, "gnunet-arm", d->cfgfile, service); + GNUNET_free (arg); + } + else + { +#if DEBUG_TESTING + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Starting gnunet-arm with config `%s' locally.\n", + d->cfgfile); +#endif + d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", + "gnunet-arm", +#if DEBUG_TESTING + "-L", "DEBUG", +#endif + "-c", d->cfgfile, "-i", service, "-q", + NULL); + } + + d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); + d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d); +} + /** * Start a peer that has previously been stopped using the daemon_stop * call (and files weren't deleted and the allow restart flag) -- cgit v1.2.3