+/**
+ * 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 service starts
+ * @param cb_cls closure for cb
+ */
+void
+GNUNET_TESTING_daemon_start_stopped_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 (d->running == GNUNET_YES);
+
+ if (d->phase == SP_CONFIG_UPDATE)
+ {
+ GNUNET_SCHEDULER_cancel (d->task);
+ d->phase = SP_START_DONE;
+ }
+
+ if (d->churned_services == NULL)
+ {
+ d->cb (d->cb_cls, &d->id, d->cfg, d,
+ "No service has been churned off yet!!");
+ return;
+ }
+ d->phase = SP_SERVICE_START;
+ GNUNET_free (d->churned_services);
+ d->churned_services = NULL;
+ d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
+ /* Check if this is a local or remote process */
+ if (NULL != d->hostname)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting gnunet-arm with config `%s' on host `%s'.\n",
+ d->cfgfile, d->hostname);
+ if (d->username != NULL)
+ GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname);
+ else
+ arg = GNUNET_strdup (d->hostname);
+
+ d->proc_arm_srv_start = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh",
+ "-q",
+ arg, "gnunet-arm",
+ "-c", d->cfgfile, "-i", service, "-q",
+ "-T",
+ GNUNET_TIME_relative_to_string (timeout),
+ 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
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting gnunet-arm with config `%s' locally.\n", d->cfgfile);
+ d->proc_arm_srv_start = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-arm", "gnunet-arm",
+ "-c", d->cfgfile, "-i", service, "-q",
+ "-T",
+ GNUNET_TIME_relative_to_string (timeout),
+ NULL);
+ }
+
+ d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
+ 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,
+ const 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);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Starting service %s for peer `%4s'\n"), service,
+ GNUNET_i2s (&d->id));
+ d->phase = SP_SERVICE_START;
+ d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
+ /* Check if this is a local or remote process */
+ if (NULL != d->hostname)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting gnunet-arm with config `%s' on host `%s'.\n",
+ d->cfgfile, d->hostname);
+ if (d->username != NULL)
+ GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname);
+ else
+ arg = GNUNET_strdup (d->hostname);
+
+ d->proc_arm_srv_start = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh",
+ "-q",
+ arg, "gnunet-arm",
+ "-c", d->cfgfile, "-i", service, "-q",
+ "-T",
+ GNUNET_TIME_relative_to_string (timeout),
+ NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i %s -q -T %s\n",
+ arg, "gnunet-arm", d->cfgfile, service,
+ GNUNET_TIME_relative_to_string (timeout));
+ GNUNET_free (arg);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting gnunet-arm with config `%s' locally.\n", d->cfgfile);
+ d->proc_arm_srv_start = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-arm", "gnunet-arm",
+ "-c", d->cfgfile, "-i", service, "-q",
+ "-T",
+ GNUNET_TIME_relative_to_string (timeout),
+ NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting gnunet-arm with command %s -c %s -i %s -q -T %s\n",
+ "gnunet-arm", d->cfgfile, service,
+ GNUNET_TIME_relative_to_string (timeout));
+ }
+
+ d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
+ d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d);
+}
+