const char *target;
const RunlevelType type;
} rcnd_table[] = {
- /* Standard SysV runlevels */
- { "rc0.d", SPECIAL_POWEROFF_TARGET, RUNLEVEL_DOWN },
+ /* Standard SysV runlevels for start-up */
{ "rc1.d", SPECIAL_RESCUE_TARGET, RUNLEVEL_UP },
{ "rc2.d", SPECIAL_RUNLEVEL2_TARGET, RUNLEVEL_UP },
{ "rc3.d", SPECIAL_RUNLEVEL3_TARGET, RUNLEVEL_UP },
{ "rc4.d", SPECIAL_RUNLEVEL4_TARGET, RUNLEVEL_UP },
{ "rc5.d", SPECIAL_RUNLEVEL5_TARGET, RUNLEVEL_UP },
- { "rc6.d", SPECIAL_REBOOT_TARGET, RUNLEVEL_DOWN },
+#ifdef TARGET_SUSE
/* SUSE style boot.d */
{ "boot.d", SPECIAL_SYSINIT_TARGET, RUNLEVEL_SYSINIT },
+#endif
+#ifdef TARGET_DEBIAN
/* Debian style rcS.d */
{ "rcS.d", SPECIAL_SYSINIT_TARGET, RUNLEVEL_SYSINIT },
+#endif
+
+ /* Standard SysV runlevels for shutdown */
+ { "rc0.d", SPECIAL_POWEROFF_TARGET, RUNLEVEL_DOWN },
+ { "rc6.d", SPECIAL_REBOOT_TARGET, RUNLEVEL_DOWN }
+
+ /* Note that the order here matters, as we read the
+ directories in this order, and we want to make sure that
+ sysv_start_priority is known when we first load the
+ unit. And that value we only know from S links. Hence
+ UP/SYSINIT must be read before DOWN */
};
#define RUNLEVELS_UP "12345"
LIST_FOREACH(units_per_type, other, s->meta.manager->units_per_type[UNIT_SERVICE]) {
Service *t;
UnitDependency d;
+ bool special_s, special_t;
t = (Service*) other;
(!t->sysv_path || t->sysv_has_lsb))
continue;
- if (t->sysv_start_priority < s->sysv_start_priority)
+ special_s = s->sysv_runlevels && !chars_intersect(RUNLEVELS_UP, s->sysv_runlevels);
+ special_t = t->sysv_runlevels && !chars_intersect(RUNLEVELS_UP, t->sysv_runlevels);
+
+ if (special_t && !special_s)
+ d = UNIT_AFTER;
+ else if (special_s && !special_t)
+ d = UNIT_BEFORE;
+ else if (t->sysv_start_priority < s->sysv_start_priority)
d = UNIT_AFTER;
else if (t->sysv_start_priority > s->sysv_start_priority)
d = UNIT_BEFORE;
if (unit_name_to_type(m) == UNIT_SERVICE)
r = unit_add_name(u, m);
+ else if (s->sysv_enabled)
+ r = unit_add_two_dependencies_by_name_inverse(u, UNIT_AFTER, UNIT_WANTS, m, NULL, true);
else
- r = unit_add_two_dependencies_by_name_inverse(u, UNIT_AFTER, UNIT_REQUIRES, m, NULL, true);
+ r = unit_add_dependency_by_name_inverse(u, UNIT_AFTER, m, NULL, true);
free(m);
s->type = SERVICE_FORKING;
s->valid_no_process = true;
s->restart = SERVICE_ONCE;
- s->exec_context.std_output = EXEC_OUTPUT_TTY;
+ s->exec_context.std_output = s->meta.manager->sysv_console ? EXEC_OUTPUT_TTY : EXEC_OUTPUT_NULL;
s->exec_context.kill_mode = KILL_PROCESS_GROUP;
u->meta.load_state = UNIT_LOADED;
}
/* Second, activate normal shutdown */
- return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true);
+ return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTED_BY, SPECIAL_SHUTDOWN_TARGET, NULL, true);
}
static int service_load(Unit *u) {
"%sRootDirectoryStartOnly: %s\n"
"%sValidNoProcess: %s\n"
"%sType: %s\n"
+ "%sRestart: %s\n"
"%sNotifyAccess: %s\n",
prefix, service_state_to_string(s->state),
prefix, yes_no(s->permissions_start_only),
prefix, yes_no(s->root_directory_start_only),
prefix, yes_no(s->valid_no_process),
prefix, service_type_to_string(s->type),
+ prefix, service_restart_to_string(s->restart),
prefix, notify_access_to_string(s->notify_access));
if (s->control_pid > 0)
if (s->sysv_start_priority >= 0)
fprintf(f,
- "%sSysVStartPriority: %i\n",
- prefix, s->sysv_start_priority);
+ "%sSysVStartPriority: %i\n"
+ "%sSysVEnabled: %s\n",
+ prefix, s->sysv_start_priority,
+ prefix, yes_no(s->sysv_enabled));
if (s->sysv_runlevels)
fprintf(f, "%sSysVRunLevels: %s\n",
s->failure = true;
if (allow_restart &&
- s->allow_restart &&
+ !s->forbid_restart &&
(s->restart == SERVICE_RESTART_ALWAYS ||
(s->restart == SERVICE_RESTART_ON_SUCCESS && !s->failure))) {
} else
service_set_state(s, s->failure ? SERVICE_MAINTENANCE : SERVICE_DEAD);
+ s->forbid_restart = false;
+
return;
fail:
s->failure = false;
s->main_pid_known = false;
- s->allow_restart = true;
+ s->forbid_restart = false;
service_enter_start_pre(s);
return 0;
/* This is a user request, so don't do restarts on this
* shutdown. */
- s->allow_restart = false;
+ s->forbid_restart = true;
/* Already on it */
if (s->state == SERVICE_STOP ||
unit_serialize_item(u, f, "main-pid-known", yes_no(s->main_pid_known));
+ if (s->status_text)
+ unit_serialize_item(u, f, "status-text", s->status_text);
+
/* There's a minor uncleanliness here: if there are multiple
* commands attached here, we will start from the first one
* again */
log_debug("Failed to parse main-pid-known value %s", value);
else
s->main_pid_known = b;
+ } else if (streq(key, "status-text")) {
+ char *t;
+
+ if ((t = strdup(value))) {
+ free(s->status_text);
+ s->status_text = t;
+ }
+
} else if (streq(key, "control-command")) {
ServiceExecCommand id;
if ((e = strv_find_prefix(tags, "STATUS="))) {
char *t;
- if (!(t = strdup(e+7))) {
- log_error("Failed to allocate string.");
- return;
- }
+ if (e[7]) {
+ if (!(t = strdup(e+7))) {
+ log_error("Failed to allocate string.");
+ return;
+ }
- log_debug("%s: got %s", u->meta.id, e);
+ log_debug("%s: got %s", u->meta.id, e);
+
+ free(s->status_text);
+ s->status_text = t;
+ } else {
+ free(s->status_text);
+ s->status_text = NULL;
+ }
- free(s->status_text);
- s->status_text = t;
}
}
}
if (de->d_name[0] == 'S' &&
- (rcnd_table[i].type == RUNLEVEL_UP || rcnd_table[i].type == RUNLEVEL_SYSINIT))
+ (rcnd_table[i].type == RUNLEVEL_UP || rcnd_table[i].type == RUNLEVEL_SYSINIT)) {
SERVICE(service)->sysv_start_priority =
MAX(a*10 + b, SERVICE(service)->sysv_start_priority);
+ SERVICE(service)->sysv_enabled = true;
+ }
manager_dispatch_load_queue(m);
service = unit_follow_merge(service);