1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
29 #include "load-fragment.h"
30 #include "load-dropin.h"
33 #include "unit-name.h"
35 #define COMMENTS "#;\n"
36 #define NEWLINES "\n\r"
39 static const char * const rcnd_table[] = {
40 "/rc0.d", SPECIAL_RUNLEVEL0_TARGET,
41 "/rc1.d", SPECIAL_RUNLEVEL1_TARGET,
42 "/rc2.d", SPECIAL_RUNLEVEL2_TARGET,
43 "/rc3.d", SPECIAL_RUNLEVEL3_TARGET,
44 "/rc4.d", SPECIAL_RUNLEVEL4_TARGET,
45 "/rc5.d", SPECIAL_RUNLEVEL5_TARGET,
46 "/rc6.d", SPECIAL_RUNLEVEL6_TARGET,
47 "/boot.d", SPECIAL_BASIC_TARGET
50 static const UnitActiveState state_translation_table[_SERVICE_STATE_MAX] = {
51 [SERVICE_DEAD] = UNIT_INACTIVE,
52 [SERVICE_START_PRE] = UNIT_ACTIVATING,
53 [SERVICE_START] = UNIT_ACTIVATING,
54 [SERVICE_START_POST] = UNIT_ACTIVATING,
55 [SERVICE_RUNNING] = UNIT_ACTIVE,
56 [SERVICE_EXITED] = UNIT_ACTIVE,
57 [SERVICE_RELOAD] = UNIT_ACTIVE_RELOADING,
58 [SERVICE_STOP] = UNIT_DEACTIVATING,
59 [SERVICE_STOP_SIGTERM] = UNIT_DEACTIVATING,
60 [SERVICE_STOP_SIGKILL] = UNIT_DEACTIVATING,
61 [SERVICE_STOP_POST] = UNIT_DEACTIVATING,
62 [SERVICE_FINAL_SIGTERM] = UNIT_DEACTIVATING,
63 [SERVICE_FINAL_SIGKILL] = UNIT_DEACTIVATING,
64 [SERVICE_MAINTAINANCE] = UNIT_INACTIVE,
65 [SERVICE_AUTO_RESTART] = UNIT_ACTIVATING,
68 static void service_unwatch_control_pid(Service *s) {
71 if (s->control_pid <= 0)
74 unit_unwatch_pid(UNIT(s), s->control_pid);
78 static void service_unwatch_main_pid(Service *s) {
84 unit_unwatch_pid(UNIT(s), s->main_pid);
88 static void service_close_socket_fd(Service *s) {
94 close_nointr_nofail(s->socket_fd);
98 static void service_done(Unit *u) {
99 Service *s = SERVICE(u);
109 free(s->sysv_runlevels);
110 s->sysv_runlevels = NULL;
112 exec_context_done(&s->exec_context);
113 exec_command_free_array(s->exec_command, _SERVICE_EXEC_COMMAND_MAX);
114 s->control_command = NULL;
116 /* This will leak a process, but at least no memory or any of
118 service_unwatch_main_pid(s);
119 service_unwatch_control_pid(s);
122 unit_unwatch_bus_name(UNIT(u), s->bus_name);
127 service_close_socket_fd(s);
129 unit_unwatch_timer(u, &s->timer_watch);
132 static int sysv_translate_name(const char *name, char **_r) {
134 static const char * const table[] = {
135 "$local_fs", SPECIAL_LOCAL_FS_TARGET,
136 "$network", SPECIAL_NETWORK_TARGET,
137 "$named", SPECIAL_NSS_LOOKUP_TARGET,
138 "$portmap", SPECIAL_RPCBIND_TARGET,
139 "$remote_fs", SPECIAL_REMOTE_FS_TARGET,
140 "$syslog", SPECIAL_SYSLOG_TARGET,
141 "$time", SPECIAL_RTC_SET_TARGET
147 for (i = 0; i < ELEMENTSOF(table); i += 2)
148 if (streq(table[i], name)) {
149 if (!(r = strdup(table[i+1])))
158 if (asprintf(&r, "%s.service", name) < 0)
169 static int sysv_chkconfig_order(Service *s) {
175 if (s->sysv_start_priority < 0)
178 /* For each pair of services where at least one lacks a LSB
179 * header, we use the start priority value to order things. */
181 LIST_FOREACH(units_per_type, other, UNIT(s)->meta.manager->units_per_type[UNIT_SERVICE]) {
185 t = (Service*) other;
190 if (t->sysv_start_priority < 0)
193 /* If both units have modern headers we don't care
194 * about the priorities */
195 if ((!s->sysv_path || s->sysv_has_lsb) &&
196 (!t->sysv_path || t->sysv_has_lsb))
199 if (t->sysv_start_priority < s->sysv_start_priority)
201 else if (t->sysv_start_priority > s->sysv_start_priority)
206 /* FIXME: Maybe we should compare the name here lexicographically? */
208 if (!(r = unit_add_dependency(UNIT(s), d, UNIT(t))) < 0)
215 static ExecCommand *exec_command_new(const char *path, const char *arg1) {
218 if (!(c = new0(ExecCommand, 1)))
221 if (!(c->path = strdup(path))) {
226 if (!(c->argv = strv_new(path, arg1, NULL))) {
235 static int sysv_exec_commands(Service *s) {
239 assert(s->sysv_path);
241 if (!(c = exec_command_new(s->sysv_path, "start")))
243 exec_command_append_list(s->exec_command+SERVICE_EXEC_START, c);
245 if (!(c = exec_command_new(s->sysv_path, "stop")))
247 exec_command_append_list(s->exec_command+SERVICE_EXEC_STOP, c);
249 if (!(c = exec_command_new(s->sysv_path, "reload")))
251 exec_command_append_list(s->exec_command+SERVICE_EXEC_RELOAD, c);
256 static int priority_from_rcd(Service *s, const char *init_script) {
260 STRV_FOREACH(p, UNIT(s)->meta.manager->sysvrcnd_path)
261 for (i = 0; i < ELEMENTSOF(rcnd_table); i += 2) {
266 if (asprintf(&path, "%s/%s", *p, rcnd_table[i]) < 0)
274 log_warning("opendir() failed on %s: %s", path, strerror(errno));
279 while ((de = readdir(d))) {
282 if (ignore_file(de->d_name))
285 if (de->d_name[0] != 'S')
288 if (strlen(de->d_name) < 4)
291 if (!streq(de->d_name + 3, init_script))
294 /* Yay, we found it! Now decode the priority */
296 a = undecchar(de->d_name[1]);
297 b = undecchar(de->d_name[2]);
302 s->sysv_start_priority = a*10 + b;
304 log_debug("Determined priority %i from link farm for %s", s->sysv_start_priority, UNIT(s)->meta.id);
316 static int service_load_sysv_path(Service *s, const char *path) {
333 if (!(f = fopen(path, "re"))) {
334 r = errno == ENOENT ? 0 : -errno;
338 s->type = SERVICE_FORKING;
339 s->restart = SERVICE_ONCE;
342 if (!(s->sysv_path = strdup(path))) {
348 char l[LINE_MAX], *t;
350 if (!fgets(l, sizeof(l), f)) {
355 log_error("Failed to read configuration file '%s': %s", path, strerror(-r));
365 if (state == NORMAL && streq(t, "### BEGIN INIT INFO")) {
367 s->sysv_has_lsb = true;
371 if ((state == LSB_DESCRIPTION || state == LSB) && streq(t, "### END INIT INFO")) {
377 t += strspn(t, WHITESPACE);
379 if (state == NORMAL) {
381 /* Try to parse Red Hat style chkconfig headers */
383 if (startswith(t, "chkconfig:")) {
385 char runlevels[16], *k;
389 if (sscanf(t+10, "%15s %i %*i",
391 &start_priority) != 2) {
393 log_warning("[%s:%u] Failed to parse chkconfig line. Ignoring.", path, line);
397 if (start_priority < 0 || start_priority > 99)
398 log_warning("[%s:%u] Start priority out of range. Ignoring.", path, line);
400 s->sysv_start_priority = start_priority;
402 char_array_0(runlevels);
403 k = delete_chars(runlevels, WHITESPACE "-");
408 if (!(d = strdup(k))) {
413 free(s->sysv_runlevels);
414 s->sysv_runlevels = d;
418 } else if (startswith(t, "description:")) {
420 size_t k = strlen(t);
423 if (t[k-1] == '\\') {
428 if (!(d = strdup(strstrip(t+12)))) {
433 free(u->meta.description);
434 u->meta.description = d;
436 } else if (startswith(t, "pidfile:")) {
443 if (!path_is_absolute(fn)) {
444 log_warning("[%s:%u] PID file not absolute. Ignoring.", path, line);
448 if (!(fn = strdup(fn))) {
457 } else if (state == DESCRIPTION) {
459 /* Try to parse Red Hat style description
462 size_t k = strlen(t);
470 assert(u->meta.description);
471 if (asprintf(&d, "%s %s", u->meta.description, strstrip(t)) < 0) {
476 free(u->meta.description);
477 u->meta.description = d;
479 } else if (state == LSB || state == LSB_DESCRIPTION) {
481 if (startswith(t, "Provides:")) {
487 FOREACH_WORD(w, z, t+9, i) {
490 if (!(n = strndup(w, z))) {
495 r = sysv_translate_name(n, &m);
504 if (unit_name_to_type(m) == UNIT_SERVICE)
505 r = unit_add_name(u, m);
507 if ((r = unit_add_dependency_by_name_inverse(u, UNIT_REQUIRES, m, NULL)) >= 0)
508 r = unit_add_dependency_by_name(u, UNIT_BEFORE, m, NULL);
517 } else if (startswith(t, "Required-Start:") ||
518 startswith(t, "Should-Start:")) {
524 FOREACH_WORD(w, z, strchr(t, ':')+1, i) {
527 if (!(n = strndup(w, z))) {
532 r = sysv_translate_name(n, &m);
541 r = unit_add_dependency_by_name(u, UNIT_AFTER, m, NULL);
547 } else if (startswith(t, "Default-Start:")) {
552 k = delete_chars(t+14, WHITESPACE "-");
555 if (!(d = strdup(k))) {
560 free(s->sysv_runlevels);
561 s->sysv_runlevels = d;
564 } else if (startswith(t, "Description:")) {
567 state = LSB_DESCRIPTION;
569 if (!(d = strdup(strstrip(t+12)))) {
574 free(u->meta.description);
575 u->meta.description = d;
577 } else if (startswith(t, "Short-Description:") &&
578 !u->meta.description) {
581 /* We use the short description only
582 * if no long description is set. */
586 if (!(d = strdup(strstrip(t+18)))) {
591 u->meta.description = d;
593 } else if (state == LSB_DESCRIPTION) {
595 if (startswith(l, "#\t") || startswith(l, "# ")) {
598 assert(u->meta.description);
599 if (asprintf(&d, "%s %s", u->meta.description, t) < 0) {
604 free(u->meta.description);
605 u->meta.description = d;
612 /* If init scripts have no LSB header, then we enforce the
613 * ordering via the chkconfig priorities. We try to determine
614 * a priority for *all* init scripts here, since they are
615 * needed as soon as at least one non-LSB script is used. */
617 if (s->sysv_start_priority < 0) {
618 log_debug("%s has no chkconfig header, trying to determine SysV priority from link farm.", u->meta.id);
620 if ((r = priority_from_rcd(s, file_name_from_path(path))) < 0)
623 if (s->sysv_start_priority < 0)
624 log_warning("%s has neither a chkconfig header nor a directory link, cannot order unit!", u->meta.id);
627 if ((r = sysv_exec_commands(s)) < 0)
630 if (!s->sysv_runlevels || chars_intersect("12345", s->sysv_runlevels)) {
631 /* If there a runlevels configured for this service
632 * but none of the standard ones, then we assume this
633 * is some special kind of service (which might be
634 * needed for early boot) and don't create any links
637 if ((r = unit_add_dependency_by_name(u, UNIT_REQUIRES, SPECIAL_BASIC_TARGET, NULL)) < 0 ||
638 (r = unit_add_dependency_by_name(u, UNIT_AFTER, SPECIAL_BASIC_TARGET, NULL)) < 0)
642 /* Special setting for all SysV services */
643 s->valid_no_process = true;
645 /* Don't timeout special services during boot (like fsck) */
646 if (s->sysv_runlevels && !chars_intersect("12345", s->sysv_runlevels))
647 s->timeout_usec = -1;
649 u->meta.load_state = UNIT_LOADED;
660 static int service_load_sysv_name(Service *s, const char *name) {
666 STRV_FOREACH(p, UNIT(s)->meta.manager->sysvinit_path) {
670 if (asprintf(&path, "%s/%s", *p, name) < 0)
673 assert(endswith(path, ".service"));
674 path[strlen(path)-8] = 0;
676 r = service_load_sysv_path(s, path);
682 if ((UNIT(s)->meta.load_state != UNIT_STUB))
689 static int service_load_sysv(Service *s) {
696 /* Load service data from SysV init scripts, preferably with
699 if (strv_isempty(UNIT(s)->meta.manager->sysvinit_path))
702 if ((t = UNIT(s)->meta.id))
703 if ((r = service_load_sysv_name(s, t)) < 0)
706 if (UNIT(s)->meta.load_state == UNIT_STUB)
707 SET_FOREACH(t, UNIT(s)->meta.names, i) {
708 if (t == UNIT(s)->meta.id)
711 if ((r == service_load_sysv_name(s, t)) < 0)
714 if (UNIT(s)->meta.load_state != UNIT_STUB)
721 static int service_add_bus_name(Service *s) {
728 if (asprintf(&n, "dbus-%s.service", s->bus_name) < 0)
731 r = unit_merge_by_name(UNIT(s), n);
737 static void service_init(Unit *u) {
738 Service *s = SERVICE(u);
741 assert(u->meta.load_state == UNIT_STUB);
746 s->timeout_usec = DEFAULT_TIMEOUT_USEC;
747 s->restart_usec = DEFAULT_RESTART_USEC;
749 exec_context_init(&s->exec_context);
751 s->timer_watch.type = WATCH_INVALID;
753 s->state = SERVICE_DEAD;
755 s->sysv_start_priority = -1;
756 s->permissions_start_only = false;
757 s->root_directory_start_only = false;
758 s->valid_no_process = false;
760 s->sysv_has_lsb = false;
761 s->main_pid = s->control_pid = 0;
762 s->main_pid_known = false;
766 s->bus_name_good = false;
768 RATELIMIT_INIT(s->ratelimit, 10*USEC_PER_SEC, 5);
771 static int service_verify(Service *s) {
774 if (UNIT(s)->meta.load_state != UNIT_LOADED)
777 if (!s->exec_command[SERVICE_EXEC_START]) {
778 log_error("%s lacks ExecStart setting. Refusing.", UNIT(s)->meta.id);
782 if (s->type == SERVICE_DBUS && !s->bus_name) {
783 log_error("%s is of type D-Bus but no D-Bus service name has been specified. Refusing.", UNIT(s)->meta.id);
790 static int service_load(Unit *u) {
792 Service *s = SERVICE(u);
796 /* Load a .service file */
797 if ((r = unit_load_fragment(u)) < 0)
800 /* Load a classic init script as a fallback, if we couldn't find anything */
801 if (u->meta.load_state == UNIT_STUB)
802 if ((r = service_load_sysv(s)) < 0)
805 /* Still nothing found? Then let's give up */
806 if (u->meta.load_state == UNIT_STUB)
809 /* We were able to load something, then let's add in the
810 * dropin directories. */
811 if ((r = unit_load_dropin(unit_follow_merge(u))) < 0)
814 /* This is a new unit? Then let's add in some extras */
815 if (u->meta.load_state == UNIT_LOADED) {
816 if ((r = unit_add_exec_dependencies(u, &s->exec_context)) < 0)
819 if ((r = unit_add_default_cgroup(u)) < 0)
822 if ((r = sysv_chkconfig_order(s)) < 0)
826 if ((r = service_add_bus_name(s)) < 0)
829 if ((r = unit_watch_bus_name(u, s->bus_name)) < 0)
834 return service_verify(s);
837 static void service_dump(Unit *u, FILE *f, const char *prefix) {
839 ServiceExecCommand c;
840 Service *s = SERVICE(u);
846 p2 = strappend(prefix, "\t");
847 prefix2 = p2 ? p2 : prefix;
850 "%sService State: %s\n"
851 "%sPermissionsStartOnly: %s\n"
852 "%sRootDirectoryStartOnly: %s\n"
853 "%sValidNoProcess: %s\n"
856 prefix, service_state_to_string(s->state),
857 prefix, yes_no(s->permissions_start_only),
858 prefix, yes_no(s->root_directory_start_only),
859 prefix, yes_no(s->valid_no_process),
860 prefix, kill_mode_to_string(s->kill_mode),
861 prefix, service_type_to_string(s->type));
863 if (s->control_pid > 0)
865 "%sControl PID: %llu\n",
866 prefix, (unsigned long long) s->control_pid);
870 "%sMain PID: %llu\n",
871 prefix, (unsigned long long) s->main_pid);
876 prefix, s->pid_file);
881 "%sBus Name Good: %s\n",
883 prefix, yes_no(s->bus_name_good));
885 exec_context_dump(&s->exec_context, f, prefix);
887 for (c = 0; c < _SERVICE_EXEC_COMMAND_MAX; c++) {
889 if (!s->exec_command[c])
892 fprintf(f, "%s→ %s:\n",
893 prefix, service_exec_command_to_string(c));
895 exec_command_dump_list(s->exec_command[c], f, prefix2);
900 "%sSysV Init Script Path: %s\n"
901 "%sSysV Init Script has LSB Header: %s\n",
902 prefix, s->sysv_path,
903 prefix, yes_no(s->sysv_has_lsb));
905 if (s->sysv_start_priority >= 0)
907 "%sSysVStartPriority: %i\n",
908 prefix, s->sysv_start_priority);
910 if (s->sysv_runlevels)
911 fprintf(f, "%sSysVRunLevels: %s\n",
912 prefix, s->sysv_runlevels);
917 static int service_load_pid_file(Service *s) {
924 if (s->main_pid_known)
927 assert(s->main_pid <= 0);
932 if ((r = read_one_line_file(s->pid_file, &k)) < 0)
935 if ((r = safe_atolu(k, &p)) < 0) {
940 if ((unsigned long) (pid_t) p != p)
943 if (kill((pid_t) p, 0) < 0 && errno != EPERM) {
944 log_warning("PID %llu read from file %s does not exist. Your service or init script might be broken.",
945 (unsigned long long) p, s->pid_file);
949 if ((r = unit_watch_pid(UNIT(s), (pid_t) p)) < 0)
950 /* FIXME: we need to do something here */
953 s->main_pid = (pid_t) p;
954 s->main_pid_known = true;
959 static int service_get_sockets(Service *s, Set **_set) {
968 /* Collects all Socket objects that belong to this
969 * service. Note that a service might have multiple sockets
970 * via multiple names. */
972 if (!(set = set_new(NULL, NULL)))
975 SET_FOREACH(t, UNIT(s)->meta.names, i) {
979 /* Look for all socket objects that go by any of our
980 * units and collect their fds */
982 if (!(k = unit_name_change_suffix(t, ".socket"))) {
987 p = manager_get_unit(UNIT(s)->meta.manager, k);
992 if ((r = set_put(set, p)) < 0)
1004 static int service_notify_sockets_dead(Service *s) {
1012 /* Notifies all our sockets when we die */
1013 if ((r = service_get_sockets(s, &set)) < 0)
1016 SET_FOREACH(sock, set, i)
1017 socket_notify_service_dead(sock);
1024 static void service_set_state(Service *s, ServiceState state) {
1025 ServiceState old_state;
1028 old_state = s->state;
1031 if (state != SERVICE_START_PRE &&
1032 state != SERVICE_START &&
1033 state != SERVICE_START_POST &&
1034 state != SERVICE_RELOAD &&
1035 state != SERVICE_STOP &&
1036 state != SERVICE_STOP_SIGTERM &&
1037 state != SERVICE_STOP_SIGKILL &&
1038 state != SERVICE_STOP_POST &&
1039 state != SERVICE_FINAL_SIGTERM &&
1040 state != SERVICE_FINAL_SIGKILL &&
1041 state != SERVICE_AUTO_RESTART)
1042 unit_unwatch_timer(UNIT(s), &s->timer_watch);
1044 if (state != SERVICE_START &&
1045 state != SERVICE_START_POST &&
1046 state != SERVICE_RUNNING &&
1047 state != SERVICE_RELOAD &&
1048 state != SERVICE_STOP &&
1049 state != SERVICE_STOP_SIGTERM &&
1050 state != SERVICE_STOP_SIGKILL)
1051 service_unwatch_main_pid(s);
1053 if (state != SERVICE_START_PRE &&
1054 state != SERVICE_START &&
1055 state != SERVICE_START_POST &&
1056 state != SERVICE_RELOAD &&
1057 state != SERVICE_STOP &&
1058 state != SERVICE_STOP_SIGTERM &&
1059 state != SERVICE_STOP_SIGKILL &&
1060 state != SERVICE_STOP_POST &&
1061 state != SERVICE_FINAL_SIGTERM &&
1062 state != SERVICE_FINAL_SIGKILL) {
1063 service_unwatch_control_pid(s);
1064 s->control_command = NULL;
1067 if (state == SERVICE_DEAD ||
1068 state == SERVICE_STOP ||
1069 state == SERVICE_STOP_SIGTERM ||
1070 state == SERVICE_STOP_SIGKILL ||
1071 state == SERVICE_STOP_POST ||
1072 state == SERVICE_FINAL_SIGTERM ||
1073 state == SERVICE_FINAL_SIGKILL ||
1074 state == SERVICE_MAINTAINANCE ||
1075 state == SERVICE_AUTO_RESTART)
1076 service_notify_sockets_dead(s);
1078 if (state != SERVICE_START_PRE &&
1079 state != SERVICE_START &&
1080 !(state == SERVICE_DEAD && UNIT(s)->meta.job))
1081 service_close_socket_fd(s);
1083 if (old_state != state)
1084 log_debug("%s changed %s → %s", UNIT(s)->meta.id, service_state_to_string(old_state), service_state_to_string(state));
1086 unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state]);
1089 static int service_collect_fds(Service *s, int **fds, unsigned *n_fds) {
1093 unsigned rn_fds = 0;
1101 if ((r = service_get_sockets(s, &set)) < 0)
1104 SET_FOREACH(sock, set, i) {
1108 if ((r = socket_collect_fds(sock, &cfds, &cn_fds)) < 0)
1120 if (!(t = new(int, rn_fds+cn_fds))) {
1126 memcpy(t, rfds, rn_fds);
1127 memcpy(t+rn_fds, cfds, cn_fds);
1132 rn_fds = rn_fds+cn_fds;
1150 static int service_spawn(
1155 bool apply_permissions,
1170 if (s->socket_fd >= 0) {
1171 fds = &s->socket_fd;
1173 } else if ((r = service_collect_fds(s, &fds, &n_fds)) < 0)
1178 if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0)
1181 unit_unwatch_timer(UNIT(s), &s->timer_watch);
1183 if (!(argv = unit_full_printf_strv(UNIT(s), c->argv))) {
1194 UNIT(s)->meta.manager->confirm_spawn,
1195 UNIT(s)->meta.cgroup_bondings,
1203 if (s->socket_fd >= 0)
1204 service_close_socket_fd(s);
1209 if ((r = unit_watch_pid(UNIT(s), pid)) < 0)
1210 /* FIXME: we need to do something here */
1221 unit_unwatch_timer(UNIT(s), &s->timer_watch);
1226 static int main_pid_good(Service *s) {
1229 /* Returns 0 if the pid is dead, 1 if it is good, -1 if we
1232 /* If we know the pid file, then lets just check if it is
1234 if (s->main_pid_known)
1235 return s->main_pid > 0;
1237 /* We don't know the pid */
1241 static int control_pid_good(Service *s) {
1244 return s->control_pid > 0;
1247 static int cgroup_good(Service *s) {
1252 if (s->valid_no_process)
1255 if ((r = cgroup_bonding_is_empty_list(UNIT(s)->meta.cgroup_bondings)) < 0)
1261 static void service_enter_dead(Service *s, bool success, bool allow_restart) {
1268 if (allow_restart &&
1269 (s->restart == SERVICE_RESTART_ALWAYS ||
1270 (s->restart == SERVICE_RESTART_ON_SUCCESS && !s->failure))) {
1272 if ((r = unit_watch_timer(UNIT(s), s->restart_usec, &s->timer_watch)) < 0)
1275 service_set_state(s, SERVICE_AUTO_RESTART);
1277 service_set_state(s, s->failure ? SERVICE_MAINTAINANCE : SERVICE_DEAD);
1282 log_warning("%s failed to run install restart timer: %s", UNIT(s)->meta.id, strerror(-r));
1283 service_enter_dead(s, false, false);
1286 static void service_enter_signal(Service *s, ServiceState state, bool success);
1288 static void service_enter_stop_post(Service *s, bool success) {
1295 service_unwatch_control_pid(s);
1297 if ((s->control_command = s->exec_command[SERVICE_EXEC_STOP_POST])) {
1298 if ((r = service_spawn(s,
1302 !s->permissions_start_only,
1303 !s->root_directory_start_only,
1304 &s->control_pid)) < 0)
1308 service_set_state(s, SERVICE_STOP_POST);
1310 service_enter_signal(s, SERVICE_FINAL_SIGTERM, true);
1315 log_warning("%s failed to run stop-post executable: %s", UNIT(s)->meta.id, strerror(-r));
1316 service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
1319 static void service_enter_signal(Service *s, ServiceState state, bool success) {
1328 if (s->kill_mode != KILL_NONE) {
1329 int sig = (state == SERVICE_STOP_SIGTERM || state == SERVICE_FINAL_SIGTERM) ? SIGTERM : SIGKILL;
1331 if (s->kill_mode == KILL_CONTROL_GROUP) {
1333 if ((r = cgroup_bonding_kill_list(UNIT(s)->meta.cgroup_bondings, sig)) < 0) {
1334 if (r != -EAGAIN && r != -ESRCH)
1343 if (s->main_pid > 0) {
1344 if (kill(s->kill_mode == KILL_PROCESS ? s->main_pid : -s->main_pid, sig) < 0 && errno != ESRCH)
1350 if (s->control_pid > 0) {
1351 if (kill(s->kill_mode == KILL_PROCESS ? s->control_pid : -s->control_pid, sig) < 0 && errno != ESRCH)
1363 if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0)
1366 service_set_state(s, state);
1367 } else if (state == SERVICE_STOP_SIGTERM || state == SERVICE_STOP_SIGKILL)
1368 service_enter_stop_post(s, true);
1370 service_enter_dead(s, true, true);
1375 log_warning("%s failed to kill processes: %s", UNIT(s)->meta.id, strerror(-r));
1377 if (state == SERVICE_STOP_SIGTERM || state == SERVICE_STOP_SIGKILL)
1378 service_enter_stop_post(s, false);
1380 service_enter_dead(s, false, true);
1383 static void service_enter_stop(Service *s, bool success) {
1390 service_unwatch_control_pid(s);
1392 if ((s->control_command = s->exec_command[SERVICE_EXEC_STOP])) {
1393 if ((r = service_spawn(s,
1397 !s->permissions_start_only,
1398 !s->root_directory_start_only,
1399 &s->control_pid)) < 0)
1402 service_set_state(s, SERVICE_STOP);
1404 service_enter_signal(s, SERVICE_STOP_SIGTERM, true);
1409 log_warning("%s failed to run stop executable: %s", UNIT(s)->meta.id, strerror(-r));
1410 service_enter_signal(s, SERVICE_STOP_SIGTERM, false);
1413 static void service_enter_running(Service *s, bool success) {
1419 if (main_pid_good(s) != 0 &&
1420 cgroup_good(s) != 0 &&
1421 (s->bus_name_good || s->type != SERVICE_DBUS))
1422 service_set_state(s, SERVICE_RUNNING);
1423 else if (s->valid_no_process)
1424 service_set_state(s, SERVICE_EXITED);
1426 service_enter_stop(s, true);
1429 static void service_enter_start_post(Service *s) {
1433 service_unwatch_control_pid(s);
1435 if ((s->control_command = s->exec_command[SERVICE_EXEC_START_POST])) {
1436 if ((r = service_spawn(s,
1440 !s->permissions_start_only,
1441 !s->root_directory_start_only,
1442 &s->control_pid)) < 0)
1446 service_set_state(s, SERVICE_START_POST);
1448 service_enter_running(s, true);
1453 log_warning("%s failed to run start-post executable: %s", UNIT(s)->meta.id, strerror(-r));
1454 service_enter_stop(s, false);
1457 static void service_enter_start(Service *s) {
1463 assert(s->exec_command[SERVICE_EXEC_START]);
1464 assert(!s->exec_command[SERVICE_EXEC_START]->command_next);
1466 if (s->type == SERVICE_FORKING)
1467 service_unwatch_control_pid(s);
1469 service_unwatch_main_pid(s);
1471 if ((r = service_spawn(s,
1472 s->exec_command[SERVICE_EXEC_START],
1473 s->type == SERVICE_FORKING || s->type == SERVICE_DBUS,
1480 if (s->type == SERVICE_SIMPLE) {
1481 /* For simple services we immediately start
1482 * the START_POST binaries. */
1485 s->main_pid_known = true;
1487 service_enter_start_post(s);
1489 } else if (s->type == SERVICE_FORKING) {
1491 /* For forking services we wait until the start
1492 * process exited. */
1494 s->control_pid = pid;
1496 s->control_command = s->exec_command[SERVICE_EXEC_START];
1497 service_set_state(s, SERVICE_START);
1499 } else if (s->type == SERVICE_FINISH ||
1500 s->type == SERVICE_DBUS) {
1502 /* For finishing services we wait until the start
1503 * process exited, too, but it is our main process. */
1505 /* For D-Bus services we know the main pid right away,
1506 * but wait for the bus name to appear on the bus. */
1509 s->main_pid_known = true;
1511 service_set_state(s, SERVICE_START);
1513 assert_not_reached("Unknown service type");
1518 log_warning("%s failed to run start exectuable: %s", UNIT(s)->meta.id, strerror(-r));
1519 service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
1522 static void service_enter_start_pre(Service *s) {
1527 service_unwatch_control_pid(s);
1529 if ((s->control_command = s->exec_command[SERVICE_EXEC_START_PRE])) {
1530 if ((r = service_spawn(s,
1534 !s->permissions_start_only,
1535 !s->root_directory_start_only,
1536 &s->control_pid)) < 0)
1539 service_set_state(s, SERVICE_START_PRE);
1541 service_enter_start(s);
1546 log_warning("%s failed to run start-pre executable: %s", UNIT(s)->meta.id, strerror(-r));
1547 service_enter_dead(s, false, true);
1550 static void service_enter_restart(Service *s) {
1554 service_enter_dead(s, true, false);
1556 if ((r = manager_add_job(UNIT(s)->meta.manager, JOB_START, UNIT(s), JOB_FAIL, false, NULL)) < 0)
1559 log_debug("%s scheduled restart job.", UNIT(s)->meta.id);
1564 log_warning("%s failed to schedule restart job: %s", UNIT(s)->meta.id, strerror(-r));
1565 service_enter_dead(s, false, false);
1568 static void service_enter_reload(Service *s) {
1573 service_unwatch_control_pid(s);
1575 if ((s->control_command = s->exec_command[SERVICE_EXEC_RELOAD])) {
1576 if ((r = service_spawn(s,
1580 !s->permissions_start_only,
1581 !s->root_directory_start_only,
1582 &s->control_pid)) < 0)
1585 service_set_state(s, SERVICE_RELOAD);
1587 service_enter_running(s, true);
1592 log_warning("%s failed to run reload executable: %s", UNIT(s)->meta.id, strerror(-r));
1593 service_enter_stop(s, false);
1596 static void service_run_next(Service *s, bool success) {
1600 assert(s->control_command);
1601 assert(s->control_command->command_next);
1606 s->control_command = s->control_command->command_next;
1608 service_unwatch_control_pid(s);
1610 if ((r = service_spawn(s,
1614 !s->permissions_start_only,
1615 !s->root_directory_start_only,
1616 &s->control_pid)) < 0)
1622 log_warning("%s failed to run spawn next executable: %s", UNIT(s)->meta.id, strerror(-r));
1624 if (s->state == SERVICE_START_PRE)
1625 service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
1626 else if (s->state == SERVICE_STOP)
1627 service_enter_signal(s, SERVICE_STOP_SIGTERM, false);
1628 else if (s->state == SERVICE_STOP_POST)
1629 service_enter_dead(s, false, true);
1631 service_enter_stop(s, false);
1634 static int service_start(Unit *u) {
1635 Service *s = SERVICE(u);
1639 /* We cannot fulfill this request right now, try again later
1641 if (s->state == SERVICE_STOP ||
1642 s->state == SERVICE_STOP_SIGTERM ||
1643 s->state == SERVICE_STOP_SIGKILL ||
1644 s->state == SERVICE_STOP_POST ||
1645 s->state == SERVICE_FINAL_SIGTERM ||
1646 s->state == SERVICE_FINAL_SIGKILL)
1649 /* Already on it! */
1650 if (s->state == SERVICE_START_PRE ||
1651 s->state == SERVICE_START ||
1652 s->state == SERVICE_START_POST)
1655 assert(s->state == SERVICE_DEAD || s->state == SERVICE_MAINTAINANCE || s->state == SERVICE_AUTO_RESTART);
1657 /* Make sure we don't enter a busy loop of some kind. */
1658 if (!ratelimit_test(&s->ratelimit)) {
1659 log_warning("%s start request repeated too quickly, refusing to start.", u->meta.id);
1664 s->main_pid_known = false;
1666 service_enter_start_pre(s);
1670 static int service_stop(Unit *u) {
1671 Service *s = SERVICE(u);
1675 /* Cannot do this now */
1676 if (s->state == SERVICE_START_PRE ||
1677 s->state == SERVICE_START ||
1678 s->state == SERVICE_START_POST ||
1679 s->state == SERVICE_RELOAD)
1683 if (s->state == SERVICE_STOP ||
1684 s->state == SERVICE_STOP_SIGTERM ||
1685 s->state == SERVICE_STOP_SIGKILL ||
1686 s->state == SERVICE_STOP_POST ||
1687 s->state == SERVICE_FINAL_SIGTERM ||
1688 s->state == SERVICE_FINAL_SIGKILL)
1691 if (s->state == SERVICE_AUTO_RESTART) {
1692 service_set_state(s, SERVICE_DEAD);
1696 assert(s->state == SERVICE_RUNNING || s->state == SERVICE_EXITED);
1698 service_enter_stop(s, true);
1702 static int service_reload(Unit *u) {
1703 Service *s = SERVICE(u);
1707 assert(s->state == SERVICE_RUNNING || s->state == SERVICE_EXITED);
1709 service_enter_reload(s);
1713 static bool service_can_reload(Unit *u) {
1714 Service *s = SERVICE(u);
1718 return !!s->exec_command[SERVICE_EXEC_RELOAD];
1721 static UnitActiveState service_active_state(Unit *u) {
1724 return state_translation_table[SERVICE(u)->state];
1727 static const char *service_sub_state_to_string(Unit *u) {
1730 return service_state_to_string(SERVICE(u)->state);
1733 static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
1734 Service *s = SERVICE(u);
1740 success = code == CLD_EXITED && status == 0;
1741 s->failure = s->failure || !success;
1743 if (s->main_pid == pid) {
1745 exec_status_fill(&s->main_exec_status, pid, code, status);
1748 if (s->type == SERVICE_SIMPLE || s->type == SERVICE_FINISH) {
1749 assert(s->exec_command[SERVICE_EXEC_START]);
1750 s->exec_command[SERVICE_EXEC_START]->exec_status = s->main_exec_status;
1753 log_debug("%s: main process exited, code=%s, status=%i", u->meta.id, sigchld_code_to_string(code), status);
1755 /* The service exited, so the service is officially
1760 case SERVICE_START_POST:
1761 case SERVICE_RELOAD:
1763 /* Need to wait until the operation is
1768 assert(s->type == SERVICE_FINISH);
1770 /* This was our main goal, so let's go on */
1772 service_enter_start_post(s);
1774 service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
1777 case SERVICE_RUNNING:
1778 service_enter_running(s, success);
1781 case SERVICE_STOP_SIGTERM:
1782 case SERVICE_STOP_SIGKILL:
1784 if (!control_pid_good(s))
1785 service_enter_stop_post(s, success);
1787 /* If there is still a control process, wait for that first */
1791 assert_not_reached("Uh, main process died at wrong time.");
1794 } else if (s->control_pid == pid) {
1795 assert(s->control_command);
1797 exec_status_fill(&s->control_command->exec_status, pid, code, status);
1800 log_debug("%s: control process exited, code=%s status=%i", u->meta.id, sigchld_code_to_string(code), status);
1802 /* If we are shutting things down anyway we
1803 * don't care about failing commands. */
1805 if (s->control_command->command_next && success) {
1807 /* There is another command to *
1808 * execute, so let's do that. */
1810 log_debug("%s running next command for state %s", u->meta.id, service_state_to_string(s->state));
1811 service_run_next(s, success);
1814 /* No further commands for this step, so let's
1815 * figure out what to do next */
1817 log_debug("%s got final SIGCHLD for state %s", u->meta.id, service_state_to_string(s->state));
1821 case SERVICE_START_PRE:
1823 service_enter_start(s);
1825 service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
1829 assert(s->type == SERVICE_FORKING);
1831 /* Let's try to load the pid
1832 * file here if we can. We
1833 * ignore the return value,
1834 * since the PID file might
1835 * actually be created by a
1836 * START_POST script */
1840 service_load_pid_file(s);
1842 service_enter_start_post(s);
1844 service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
1848 case SERVICE_START_POST:
1849 if (success && s->pid_file && !s->main_pid_known) {
1852 /* Hmm, let's see if we can
1853 * load the pid now after the
1854 * start-post scripts got
1857 if ((r = service_load_pid_file(s)) < 0)
1858 log_warning("%s: failed to load PID file %s: %s", UNIT(s)->meta.id, s->pid_file, strerror(-r));
1863 case SERVICE_RELOAD:
1865 service_enter_running(s, true);
1867 service_enter_stop(s, false);
1872 service_enter_signal(s, SERVICE_STOP_SIGTERM, success);
1875 case SERVICE_STOP_SIGTERM:
1876 case SERVICE_STOP_SIGKILL:
1877 if (main_pid_good(s) <= 0)
1878 service_enter_stop_post(s, success);
1880 /* If there is still a service
1881 * process around, wait until
1882 * that one quit, too */
1885 case SERVICE_STOP_POST:
1886 case SERVICE_FINAL_SIGTERM:
1887 case SERVICE_FINAL_SIGKILL:
1888 service_enter_dead(s, success, true);
1892 assert_not_reached("Uh, control process died at wrong time.");
1896 assert_not_reached("Got SIGCHLD for unkown PID");
1899 static void service_timer_event(Unit *u, uint64_t elapsed, Watch* w) {
1900 Service *s = SERVICE(u);
1903 assert(elapsed == 1);
1905 assert(w == &s->timer_watch);
1909 case SERVICE_START_PRE:
1911 log_warning("%s operation timed out. Terminating.", u->meta.id);
1912 service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
1915 case SERVICE_START_POST:
1916 case SERVICE_RELOAD:
1917 log_warning("%s operation timed out. Stopping.", u->meta.id);
1918 service_enter_stop(s, false);
1922 log_warning("%s stopping timed out. Terminating.", u->meta.id);
1923 service_enter_signal(s, SERVICE_STOP_SIGTERM, false);
1926 case SERVICE_STOP_SIGTERM:
1927 log_warning("%s stopping timed out. Killing.", u->meta.id);
1928 service_enter_signal(s, SERVICE_STOP_SIGKILL, false);
1931 case SERVICE_STOP_SIGKILL:
1932 /* Uh, wie sent a SIGKILL and it is still not gone?
1933 * Must be something we cannot kill, so let's just be
1934 * weirded out and continue */
1936 log_warning("%s still around after SIGKILL. Ignoring.", u->meta.id);
1937 service_enter_stop_post(s, false);
1940 case SERVICE_STOP_POST:
1941 log_warning("%s stopping timed out (2). Terminating.", u->meta.id);
1942 service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
1945 case SERVICE_FINAL_SIGTERM:
1946 log_warning("%s stopping timed out (2). Killing.", u->meta.id);
1947 service_enter_signal(s, SERVICE_FINAL_SIGKILL, false);
1950 case SERVICE_FINAL_SIGKILL:
1951 log_warning("%s still around after SIGKILL (2). Entering maintainance mode.", u->meta.id);
1952 service_enter_dead(s, false, true);
1955 case SERVICE_AUTO_RESTART:
1956 log_debug("%s holdoff time over, scheduling restart.", u->meta.id);
1957 service_enter_restart(s);
1961 assert_not_reached("Timeout at wrong time.");
1965 static void service_cgroup_notify_event(Unit *u) {
1966 Service *s = SERVICE(u);
1970 log_debug("%s: cgroup is empty", u->meta.id);
1974 /* Waiting for SIGCHLD is usually more interesting,
1975 * because it includes return codes/signals. Which is
1976 * why we ignore the cgroup events for most cases,
1977 * except when we don't know pid which to expect the
1980 case SERVICE_RUNNING:
1981 service_enter_running(s, true);
1989 static int service_enumerate(Manager *m) {
1993 char *path = NULL, *fpath = NULL, *name = NULL;
1998 STRV_FOREACH(p, m->sysvrcnd_path)
1999 for (i = 0; i < ELEMENTSOF(rcnd_table); i += 2) {
2004 if (asprintf(&path, "%s/%s", *p, rcnd_table[i]) < 0) {
2012 if (!(d = opendir(path))) {
2013 if (errno != ENOENT)
2014 log_warning("opendir() failed on %s: %s", path, strerror(errno));
2019 while ((de = readdir(d))) {
2020 Unit *runlevel, *service;
2022 if (ignore_file(de->d_name))
2025 if (de->d_name[0] != 'S' && de->d_name[0] != 'K')
2028 if (strlen(de->d_name) < 4)
2033 if (asprintf(&fpath, "%s/%s/%s", *p, rcnd_table[i], de->d_name) < 0) {
2038 if (access(fpath, X_OK) < 0) {
2040 if (errno != ENOENT)
2041 log_warning("access() failed on %s: %s", fpath, strerror(errno));
2048 if (asprintf(&name, "%s.service", de->d_name+3) < 0) {
2053 if ((r = manager_load_unit(m, name, NULL, &service)) < 0)
2056 if ((r = manager_load_unit(m, rcnd_table[i+1], NULL, &runlevel)) < 0)
2059 if (de->d_name[0] == 'S') {
2060 if ((r = unit_add_dependency(runlevel, UNIT_WANTS, service)) < 0)
2063 if ((r = unit_add_dependency(runlevel, UNIT_AFTER, service)) < 0)
2066 } else if (de->d_name[0] == 'K' &&
2067 (streq(rcnd_table[i+1], SPECIAL_RUNLEVEL0_TARGET) ||
2068 streq(rcnd_table[i+1], SPECIAL_RUNLEVEL6_TARGET))) {
2070 /* We honour K links only for
2071 * halt/reboot. For the normal
2072 * runlevels we assume the
2074 * implicitly added by the
2077 if ((r = unit_add_dependency(runlevel, UNIT_CONFLICTS, service)) < 0)
2080 if ((r = unit_add_dependency(runlevel, UNIT_BEFORE, service)) < 0)
2097 static void service_bus_name_owner_change(
2100 const char *old_owner,
2101 const char *new_owner) {
2103 Service *s = SERVICE(u);
2108 assert(streq(s->bus_name, name));
2109 assert(old_owner || new_owner);
2111 if (old_owner && new_owner)
2112 log_debug("%s's D-Bus name %s changed owner from %s to %s", u->meta.id, name, old_owner, new_owner);
2114 log_debug("%s's D-Bus name %s no longer registered by %s", u->meta.id, name, old_owner);
2116 log_debug("%s's D-Bus name %s now registered by %s", u->meta.id, name, new_owner);
2118 s->bus_name_good = !!new_owner;
2120 if (s->type == SERVICE_DBUS) {
2122 /* service_enter_running() will figure out what to
2124 if (s->state == SERVICE_RUNNING)
2125 service_enter_running(s, true);
2126 else if (s->state == SERVICE_START && new_owner)
2127 service_enter_start_post(s);
2129 } else if (new_owner &&
2131 (s->state == SERVICE_START ||
2132 s->state == SERVICE_START_POST ||
2133 s->state == SERVICE_RUNNING ||
2134 s->state == SERVICE_RELOAD)) {
2136 /* Try to acquire PID from bus service */
2137 log_debug("Trying to acquire PID from D-Bus name...");
2139 bus_query_pid(u->meta.manager, name);
2143 static void service_bus_query_pid_done(
2148 Service *s = SERVICE(u);
2153 log_debug("%s's D-Bus name %s is now owned by process %u", u->meta.id, name, (unsigned) pid);
2155 if (s->main_pid <= 0 &&
2156 (s->state == SERVICE_START ||
2157 s->state == SERVICE_START_POST ||
2158 s->state == SERVICE_RUNNING ||
2159 s->state == SERVICE_RELOAD))
2163 int service_set_socket_fd(Service *s, int fd) {
2167 /* This is called by the socket code when instantiating a new
2168 * service for a stream socket and the socket needs to be
2171 if (UNIT(s)->meta.load_state != UNIT_LOADED)
2174 if (s->socket_fd >= 0)
2177 if (s->state != SERVICE_DEAD)
2184 static const char* const service_state_table[_SERVICE_STATE_MAX] = {
2185 [SERVICE_DEAD] = "dead",
2186 [SERVICE_START_PRE] = "start-pre",
2187 [SERVICE_START] = "start",
2188 [SERVICE_START_POST] = "start-post",
2189 [SERVICE_RUNNING] = "running",
2190 [SERVICE_EXITED] = "exited",
2191 [SERVICE_RELOAD] = "reload",
2192 [SERVICE_STOP] = "stop",
2193 [SERVICE_STOP_SIGTERM] = "stop-sigterm",
2194 [SERVICE_STOP_SIGKILL] = "stop-sigkill",
2195 [SERVICE_STOP_POST] = "stop-post",
2196 [SERVICE_FINAL_SIGTERM] = "final-sigterm",
2197 [SERVICE_FINAL_SIGKILL] = "final-sigkill",
2198 [SERVICE_MAINTAINANCE] = "maintainance",
2199 [SERVICE_AUTO_RESTART] = "auto-restart",
2202 DEFINE_STRING_TABLE_LOOKUP(service_state, ServiceState);
2204 static const char* const service_restart_table[_SERVICE_RESTART_MAX] = {
2205 [SERVICE_ONCE] = "once",
2206 [SERVICE_RESTART_ON_SUCCESS] = "restart-on-success",
2207 [SERVICE_RESTART_ALWAYS] = "restart-always",
2210 DEFINE_STRING_TABLE_LOOKUP(service_restart, ServiceRestart);
2212 static const char* const service_type_table[_SERVICE_TYPE_MAX] = {
2213 [SERVICE_FORKING] = "forking",
2214 [SERVICE_SIMPLE] = "simple",
2215 [SERVICE_FINISH] = "finish",
2216 [SERVICE_DBUS] = "dbus"
2219 DEFINE_STRING_TABLE_LOOKUP(service_type, ServiceType);
2221 static const char* const service_exec_command_table[_SERVICE_EXEC_COMMAND_MAX] = {
2222 [SERVICE_EXEC_START_PRE] = "ExecStartPre",
2223 [SERVICE_EXEC_START] = "ExecStart",
2224 [SERVICE_EXEC_START_POST] = "ExecStartPost",
2225 [SERVICE_EXEC_RELOAD] = "ExecReload",
2226 [SERVICE_EXEC_STOP] = "ExecStop",
2227 [SERVICE_EXEC_STOP_POST] = "ExecStopPost",
2230 DEFINE_STRING_TABLE_LOOKUP(service_exec_command, ServiceExecCommand);
2232 const UnitVTable service_vtable = {
2233 .suffix = ".service",
2235 .init = service_init,
2236 .load = service_load,
2237 .done = service_done,
2239 .dump = service_dump,
2241 .start = service_start,
2242 .stop = service_stop,
2243 .reload = service_reload,
2245 .can_reload = service_can_reload,
2247 .active_state = service_active_state,
2248 .sub_state_to_string = service_sub_state_to_string,
2250 .sigchld_event = service_sigchld_event,
2251 .timer_event = service_timer_event,
2253 .cgroup_notify_empty = service_cgroup_notify_event,
2255 .bus_name_owner_change = service_bus_name_owner_change,
2256 .bus_query_pid_done = service_bus_query_pid_done,
2258 .enumerate = service_enumerate