Don't re-start or re-stop failed services if runlevel is changing.

This commit is contained in:
Roy Marples 2008-04-27 21:04:37 +00:00
parent b08b6cd91b
commit e499e58310

View File

@ -740,43 +740,52 @@ static void svc_start(bool deps)
runlevel, depoptions); runlevel, depoptions);
if (! rc_runlevel_starting() && use_services) if (! rc_runlevel_starting() && use_services)
TAILQ_FOREACH(svc, use_services, entries) TAILQ_FOREACH(svc, use_services, entries) {
if (rc_service_state(svc->value) & RC_SERVICE_STOPPED) { state = rc_service_state(svc->value);
/* Don't stop failed services again.
* If you remove this check, ensure that the
* exclusive file isn't created. */
if (state & RC_SERVICE_FAILED &&
rc_runlevel_starting())
continue;
if (state & RC_SERVICE_STOPPED) {
pid_t pid = service_start(svc->value); pid_t pid = service_start(svc->value);
if (! rc_conf_yesno("rc_parallel")) if (! rc_conf_yesno("rc_parallel"))
rc_waitpid(pid); rc_waitpid(pid);
} }
}
/* Now wait for them to start */ /* Now wait for them to start */
services = rc_deptree_depends(deptree, types_nua, applet_list, services = rc_deptree_depends(deptree, types_nua, applet_list,
runlevel, depoptions); runlevel, depoptions);
if (services) { if (services) {
/* We use tmplist to hold our scheduled by list */ /* We use tmplist to hold our scheduled by list */
tmplist = NULL; tmplist = NULL;
TAILQ_FOREACH(svc, services, entries) { TAILQ_FOREACH(svc, services, entries) {
RC_SERVICE svcs = rc_service_state(svc->value); state = rc_service_state(svc->value);
if (svcs & RC_SERVICE_STARTED) if (state & RC_SERVICE_STARTED)
continue; continue;
/* Don't wait for services which went inactive but are now in /* Don't wait for services which went inactive but are now in
* starting state which we are after */ * starting state which we are after */
if (svcs & RC_SERVICE_STARTING && if (state & RC_SERVICE_STARTING &&
svcs & RC_SERVICE_WASINACTIVE) state & RC_SERVICE_WASINACTIVE)
{ {
if (!in_list(need_services, svc->value) && if (!in_list(need_services, svc->value) &&
!in_list(use_services, svc->value)) !in_list(use_services, svc->value))
continue; continue;
} }
if (! svc_wait(svc->value)) if (!svc_wait(svc->value))
eerror ("%s: timed out waiting for %s", eerror ("%s: timed out waiting for %s",
applet, svc->value); applet, svc->value);
if ((svcs = rc_service_state(svc->value)) & RC_SERVICE_STARTED) state = rc_service_state(svc->value);
if (state & RC_SERVICE_STARTED)
continue; continue;
if (in_list(need_services, svc->value)) { if (in_list(need_services, svc->value)) {
if (svcs & RC_SERVICE_INACTIVE || if (state & RC_SERVICE_INACTIVE ||
svcs & RC_SERVICE_WASINACTIVE) state & RC_SERVICE_WASINACTIVE)
{ {
if (! tmplist) if (! tmplist)
tmplist = rc_stringlist_new(); tmplist = rc_stringlist_new();
@ -939,14 +948,20 @@ static void svc_stop(bool deps)
runlevel, depoptions); runlevel, depoptions);
if (services) { if (services) {
TAILQ_FOREACH_REVERSE(svc, services, rc_stringlist, entries) { TAILQ_FOREACH_REVERSE(svc, services, rc_stringlist, entries) {
RC_SERVICE svcs = rc_service_state(svc->value); state = rc_service_state(svc->value);
if (svcs & RC_SERVICE_STARTED || /* Don't stop failed services again.
svcs & RC_SERVICE_INACTIVE) * If you remove this check, ensure that the
* exclusive file isn't created. */
if (state & RC_SERVICE_FAILED &&
rc_runlevel_stopping())
continue;
if (state & RC_SERVICE_STARTED ||
state & RC_SERVICE_INACTIVE)
{ {
svc_wait(svc->value); svc_wait(svc->value);
svcs = rc_service_state(svc->value); state = rc_service_state(svc->value);
if (svcs & RC_SERVICE_STARTED || if (state & RC_SERVICE_STARTED ||
svcs & RC_SERVICE_INACTIVE) state & RC_SERVICE_INACTIVE)
{ {
pid_t pid = service_stop(svc->value); pid_t pid = service_stop(svc->value);
if (! rc_conf_yesno("rc_parallel")) if (! rc_conf_yesno("rc_parallel"))
@ -965,8 +980,6 @@ static void svc_stop(bool deps)
TAILQ_FOREACH(svc, tmplist, entries) { TAILQ_FOREACH(svc, tmplist, entries) {
if (rc_service_state(svc->value) & RC_SERVICE_STOPPED) if (rc_service_state(svc->value) & RC_SERVICE_STOPPED)
continue; continue;
/* We used to loop 3 times here - maybe re-do this if needed */
svc_wait(svc->value); svc_wait(svc->value);
if (! (rc_service_state(svc->value) & RC_SERVICE_STOPPED)) { if (! (rc_service_state(svc->value) & RC_SERVICE_STOPPED)) {
if (rc_runlevel_stopping()) { if (rc_runlevel_stopping()) {
@ -979,7 +992,6 @@ static void svc_stop(bool deps)
continue; continue;
rc_service_mark(service, RC_SERVICE_FAILED); rc_service_mark(service, RC_SERVICE_FAILED);
} }
eerrorx("ERROR: cannot stop %s as %s is still up", eerrorx("ERROR: cannot stop %s as %s is still up",
applet, svc->value); applet, svc->value);
} }