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/>.
27 #include "load-fragment.h"
28 #include "load-dropin.h"
31 static const UnitActiveState state_translation_table[_SERVICE_STATE_MAX] = {
32 [SERVICE_DEAD] = UNIT_INACTIVE,
33 [SERVICE_START_PRE] = UNIT_ACTIVATING,
34 [SERVICE_START] = UNIT_ACTIVATING,
35 [SERVICE_START_POST] = UNIT_ACTIVATING,
36 [SERVICE_RUNNING] = UNIT_ACTIVE,
37 [SERVICE_RELOAD] = UNIT_ACTIVE_RELOADING,
38 [SERVICE_STOP] = UNIT_DEACTIVATING,
39 [SERVICE_STOP_SIGTERM] = UNIT_DEACTIVATING,
40 [SERVICE_STOP_SIGKILL] = UNIT_DEACTIVATING,
41 [SERVICE_STOP_POST] = UNIT_DEACTIVATING,
42 [SERVICE_FINAL_SIGTERM] = UNIT_DEACTIVATING,
43 [SERVICE_FINAL_SIGKILL] = UNIT_DEACTIVATING,
44 [SERVICE_MAINTAINANCE] = UNIT_INACTIVE,
45 [SERVICE_AUTO_RESTART] = UNIT_ACTIVATING,
48 static void service_done(Unit *u) {
49 Service *s = SERVICE(u);
56 exec_context_done(&s->exec_context);
57 exec_command_free_array(s->exec_command, _SERVICE_EXEC_MAX);
58 s->control_command = NULL;
60 /* This will leak a process, but at least no memory or any of
62 if (s->main_pid > 0) {
63 unit_unwatch_pid(u, s->main_pid);
67 if (s->control_pid > 0) {
68 unit_unwatch_pid(u, s->control_pid);
72 unit_unwatch_timer(u, &s->timer_watch);
75 static int service_load_sysv(Service *s) {
78 /* Load service data from SysV init scripts, preferably with
84 static int service_init(Unit *u) {
86 Service *s = SERVICE(u);
90 /* First, reset everything to the defaults, in case this is a
96 s->timeout_usec = DEFAULT_TIMEOUT_USEC;
97 s->restart_usec = DEFAULT_RESTART_USEC;
99 exec_context_init(&s->exec_context);
101 s->timer_watch.type = WATCH_INVALID;
103 s->state = SERVICE_DEAD;
105 RATELIMIT_INIT(s->ratelimit, 10*USEC_PER_SEC, 5);
107 /* Load a .service file */
108 if ((r = unit_load_fragment(u)) < 0) {
113 /* Load a classic init script as a fallback, if we couldn*t find anything */
115 if ((r = service_load_sysv(s)) <= 0) {
117 return r < 0 ? r : -ENOENT;
120 /* Load dropin directory data */
121 if ((r = unit_load_dropin(u)) < 0) {
129 static void service_dump(Unit *u, FILE *f, const char *prefix) {
131 ServiceExecCommand c;
132 Service *s = SERVICE(u);
138 p2 = strappend(prefix, "\t");
139 prefix2 = p2 ? p2 : prefix;
142 "%sService State: %s\n",
143 prefix, service_state_to_string(s->state));
148 prefix, s->pid_file);
151 exec_context_dump(&s->exec_context, f, prefix);
153 for (c = 0; c < _SERVICE_EXEC_MAX; c++) {
155 if (!s->exec_command[c])
158 fprintf(f, "%s→ %s:\n",
159 prefix, service_exec_command_to_string(c));
161 exec_command_dump_list(s->exec_command[c], f, prefix2);
167 static int service_load_pid_file(Service *s) {
174 if (s->main_pid_known)
180 if ((r = read_one_line_file(s->pid_file, &k)) < 0)
183 if ((r = safe_atolu(k, &p)) < 0) {
188 if ((unsigned long) (pid_t) p != p)
192 s->main_pid_known = true;
197 static int service_get_sockets(Service *s, Set **_set) {
206 /* Collects all Socket objects that belong to this
207 * service. Note that a service might have multiple sockets
208 * via multiple names. */
210 if (!(set = set_new(NULL, NULL)))
213 SET_FOREACH(t, UNIT(s)->meta.names, i) {
217 /* Look for all socket objects that go by any of our
218 * units and collect their fds */
220 if (!(k = unit_name_change_suffix(t, ".socket"))) {
225 p = manager_get_unit(UNIT(s)->meta.manager, k);
230 if ((r = set_put(set, p)) < 0)
243 static int service_notify_sockets(Service *s) {
251 /* Notifies all our sockets when we die */
253 if ((r = service_get_sockets(s, &set)) < 0)
256 SET_FOREACH(sock, set, i)
257 socket_notify_service_dead(sock);
264 static void service_set_state(Service *s, ServiceState state) {
265 ServiceState old_state;
268 old_state = s->state;
271 if (state != SERVICE_START_PRE &&
272 state != SERVICE_START &&
273 state != SERVICE_START_POST &&
274 state != SERVICE_RELOAD &&
275 state != SERVICE_STOP &&
276 state != SERVICE_STOP_SIGTERM &&
277 state != SERVICE_STOP_SIGKILL &&
278 state != SERVICE_STOP_POST &&
279 state != SERVICE_FINAL_SIGTERM &&
280 state != SERVICE_FINAL_SIGKILL &&
281 state != SERVICE_AUTO_RESTART)
282 unit_unwatch_timer(UNIT(s), &s->timer_watch);
284 if (state != SERVICE_START &&
285 state != SERVICE_START_POST &&
286 state != SERVICE_RUNNING &&
287 state != SERVICE_RELOAD &&
288 state != SERVICE_STOP &&
289 state != SERVICE_STOP_SIGTERM &&
290 state != SERVICE_STOP_SIGKILL)
291 if (s->main_pid > 0) {
292 unit_unwatch_pid(UNIT(s), s->main_pid);
296 if (state != SERVICE_START_PRE &&
297 state != SERVICE_START &&
298 state != SERVICE_START_POST &&
299 state != SERVICE_RELOAD &&
300 state != SERVICE_STOP &&
301 state != SERVICE_STOP_SIGTERM &&
302 state != SERVICE_STOP_SIGKILL &&
303 state != SERVICE_STOP_POST &&
304 state != SERVICE_FINAL_SIGTERM &&
305 state != SERVICE_FINAL_SIGKILL)
306 if (s->control_pid > 0) {
307 unit_unwatch_pid(UNIT(s), s->control_pid);
311 if (state != SERVICE_START_PRE &&
312 state != SERVICE_START &&
313 state != SERVICE_START_POST &&
314 state != SERVICE_RELOAD &&
315 state != SERVICE_STOP &&
316 state != SERVICE_STOP_POST)
317 s->control_command = NULL;
319 if (state == SERVICE_DEAD ||
320 state == SERVICE_STOP ||
321 state == SERVICE_STOP_SIGTERM ||
322 state == SERVICE_STOP_SIGKILL ||
323 state == SERVICE_STOP_POST ||
324 state == SERVICE_FINAL_SIGTERM ||
325 state == SERVICE_FINAL_SIGKILL ||
326 state == SERVICE_MAINTAINANCE ||
327 state == SERVICE_AUTO_RESTART)
328 service_notify_sockets(s);
330 log_debug("%s changed %s → %s", unit_id(UNIT(s)), service_state_to_string(old_state), service_state_to_string(state));
332 unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state]);
335 static int service_collect_fds(Service *s, int **fds, unsigned *n_fds) {
347 if ((r = service_get_sockets(s, &set)) < 0)
350 SET_FOREACH(sock, set, i) {
354 if ((r = socket_collect_fds(sock, &cfds, &cn_fds)) < 0)
366 if (!(t = new(int, rn_fds+cn_fds))) {
372 memcpy(t, rfds, rn_fds);
373 memcpy(t+rn_fds, cfds, cn_fds);
378 rn_fds = rn_fds+cn_fds;
396 static int service_spawn(Service *s, ExecCommand *c, bool timeout, bool pass_fds, pid_t *_pid) {
407 if ((r = service_collect_fds(s, &fds, &n_fds)) < 0)
411 if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0)
414 unit_unwatch_timer(UNIT(s), &s->timer_watch);
416 if ((r = exec_spawn(c, &s->exec_context, fds, n_fds, &pid)) < 0)
419 if ((r = unit_watch_pid(UNIT(s), pid)) < 0)
420 /* FIXME: we need to do something here */
432 unit_unwatch_timer(UNIT(s), &s->timer_watch);
437 static void service_enter_dead(Service *s, bool success, bool allow_restart) {
445 (s->restart == SERVICE_RESTART_ALWAYS ||
446 (s->restart == SERVICE_RESTART_ON_SUCCESS && !s->failure))) {
448 if ((r = unit_watch_timer(UNIT(s), s->restart_usec, &s->timer_watch)) < 0)
451 service_set_state(s, SERVICE_AUTO_RESTART);
453 service_set_state(s, s->failure ? SERVICE_MAINTAINANCE : SERVICE_DEAD);
458 log_warning("%s failed to run install restart timer: %s", unit_id(UNIT(s)), strerror(-r));
459 service_enter_dead(s, false, false);
462 static void service_enter_signal(Service *s, ServiceState state, bool success);
464 static void service_enter_stop_post(Service *s, bool success) {
471 if ((s->control_command = s->exec_command[SERVICE_EXEC_STOP_POST]))
472 if ((r = service_spawn(s, s->control_command, true, false, &s->control_pid)) < 0)
476 service_set_state(s, SERVICE_STOP_POST);
478 if (!s->control_command)
479 service_enter_dead(s, true, true);
484 log_warning("%s failed to run stop executable: %s", unit_id(UNIT(s)), strerror(-r));
485 service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
488 static void service_enter_signal(Service *s, ServiceState state, bool success) {
497 if (s->main_pid > 0 || s->control_pid > 0) {
500 sig = (state == SERVICE_STOP_SIGTERM || state == SERVICE_FINAL_SIGTERM) ? SIGTERM : SIGKILL;
503 if (s->main_pid > 0) {
504 if (kill(s->main_pid, sig) < 0 && errno != ESRCH)
510 if (s->control_pid > 0) {
511 if (kill(s->control_pid, sig) < 0 && errno != ESRCH)
521 service_set_state(s, state);
523 if (s->main_pid <= 0 && s->control_pid <= 0)
524 service_enter_dead(s, true, true);
529 log_warning("%s failed to kill processes: %s", unit_id(UNIT(s)), strerror(-r));
533 service_set_state(s, state);
534 } else if (state == SERVICE_STOP_SIGTERM || state == SERVICE_STOP_SIGKILL)
535 service_enter_stop_post(s, false);
537 service_enter_dead(s, false, true);
540 static void service_enter_stop(Service *s, bool success) {
547 if ((s->control_command = s->exec_command[SERVICE_EXEC_STOP]))
548 if ((r = service_spawn(s, s->control_command, true, false, &s->control_pid)) < 0)
551 service_set_state(s, SERVICE_STOP);
553 if (!s->control_command)
554 service_enter_signal(s, SERVICE_STOP_SIGTERM, true);
559 log_warning("%s failed to run stop executable: %s", unit_id(UNIT(s)), strerror(-r));
560 service_enter_signal(s, SERVICE_STOP_SIGTERM, false);
563 static void service_enter_start_post(Service *s) {
567 if ((s->control_command = s->exec_command[SERVICE_EXEC_START_POST]))
568 if ((r = service_spawn(s, s->control_command, true, false, &s->control_pid)) < 0)
572 service_set_state(s, SERVICE_START_POST);
574 if (!s->control_command)
575 service_set_state(s, SERVICE_RUNNING);
580 log_warning("%s failed to run start-post executable: %s", unit_id(UNIT(s)), strerror(-r));
581 service_enter_stop(s, false);
584 static void service_enter_start(Service *s) {
590 assert(s->exec_command[SERVICE_EXEC_START]);
591 assert(!s->exec_command[SERVICE_EXEC_START]->command_next);
593 if ((r = service_spawn(s, s->exec_command[SERVICE_EXEC_START], s->type == SERVICE_FORKING, true, &pid)) < 0)
596 service_set_state(s, SERVICE_START);
598 if (s->type == SERVICE_SIMPLE) {
599 /* For simple services we immediately start
600 * the START_POST binaries. */
603 s->main_pid_known = true;
604 service_enter_start_post(s);
606 } else if (s->type == SERVICE_FORKING) {
608 /* For forking services we wait until the start
611 s->control_pid = pid;
612 s->control_command = s->exec_command[SERVICE_EXEC_START];
613 } else if (s->type == SERVICE_FINISH) {
615 /* For finishing services we wait until the start
616 * process exited, too, but it is our main process. */
619 s->control_command = s->exec_command[SERVICE_EXEC_START];
621 assert_not_reached("Unknown service type");
626 log_warning("%s failed to run start exectuable: %s", unit_id(UNIT(s)), strerror(-r));
627 service_enter_stop(s, false);
630 static void service_enter_start_pre(Service *s) {
635 if ((s->control_command = s->exec_command[SERVICE_EXEC_START_PRE]))
636 if ((r = service_spawn(s, s->control_command, true, false, &s->control_pid)) < 0)
639 service_set_state(s, SERVICE_START_PRE);
641 if (!s->control_command)
642 service_enter_start(s);
647 log_warning("%s failed to run start-pre executable: %s", unit_id(UNIT(s)), strerror(-r));
648 service_enter_dead(s, false, true);
651 static void service_enter_restart(Service *s) {
655 if ((r = manager_add_job(UNIT(s)->meta.manager, JOB_START, UNIT(s), JOB_FAIL, false, NULL)) < 0)
658 log_debug("%s scheduled restart job.", unit_id(UNIT(s)));
659 service_enter_dead(s, true, false);
664 log_warning("%s failed to schedule restart job: %s", unit_id(UNIT(s)), strerror(-r));
665 service_enter_dead(s, false, false);
668 static void service_enter_reload(Service *s) {
673 if ((s->control_command = s->exec_command[SERVICE_EXEC_RELOAD]))
674 if ((r = service_spawn(s, s->control_command, true, false, &s->control_pid)) < 0)
677 service_set_state(s, SERVICE_RELOAD);
679 if (!s->control_command)
680 service_set_state(s, SERVICE_RUNNING);
685 log_warning("%s failed to run reload executable: %s", unit_id(UNIT(s)), strerror(-r));
686 service_enter_stop(s, false);
689 static void service_run_next(Service *s, bool success) {
693 assert(s->control_command);
694 assert(s->control_command->command_next);
699 s->control_command = s->control_command->command_next;
701 if ((r = service_spawn(s, s->control_command, true, false, &s->control_pid)) < 0)
707 log_warning("%s failed to run spawn next executable: %s", unit_id(UNIT(s)), strerror(-r));
709 if (s->state == SERVICE_STOP)
710 service_enter_stop_post(s, false);
711 else if (s->state == SERVICE_STOP_POST)
712 service_enter_dead(s, false, true);
714 service_enter_stop(s, false);
717 static int service_start(Unit *u) {
718 Service *s = SERVICE(u);
722 /* We cannot fulfill this request right now, try again later
724 if (s->state == SERVICE_STOP ||
725 s->state == SERVICE_STOP_SIGTERM ||
726 s->state == SERVICE_STOP_SIGKILL ||
727 s->state == SERVICE_STOP_POST ||
728 s->state == SERVICE_FINAL_SIGTERM ||
729 s->state == SERVICE_FINAL_SIGKILL)
733 if (s->state == SERVICE_START_PRE ||
734 s->state == SERVICE_START ||
735 s->state == SERVICE_START_POST)
738 assert(s->state == SERVICE_DEAD || s->state == SERVICE_MAINTAINANCE || s->state == SERVICE_AUTO_RESTART);
740 /* Make sure we don't enter a busy loop of some kind. */
741 if (!ratelimit_test(&s->ratelimit)) {
742 log_warning("%s start request repeated too quickly, refusing to start.", unit_id(u));
747 s->main_pid_known = false;
749 service_enter_start_pre(s);
753 static int service_stop(Unit *u) {
754 Service *s = SERVICE(u);
758 if (s->state == SERVICE_START_PRE ||
759 s->state == SERVICE_START ||
760 s->state == SERVICE_START_POST ||
761 s->state == SERVICE_RELOAD)
764 if (s->state == SERVICE_AUTO_RESTART) {
765 service_set_state(s, SERVICE_DEAD);
769 assert(s->state == SERVICE_RUNNING);
771 service_enter_stop(s, true);
775 static int service_reload(Unit *u) {
776 Service *s = SERVICE(u);
780 assert(s->state == SERVICE_RUNNING);
782 service_enter_reload(s);
786 static bool service_can_reload(Unit *u) {
787 Service *s = SERVICE(u);
791 return !!s->exec_command[SERVICE_EXEC_RELOAD];
794 static UnitActiveState service_active_state(Unit *u) {
797 return state_translation_table[SERVICE(u)->state];
800 static int main_pid_good(Service *s) {
803 /* Returns 0 if the pid is dead, 1 if it is good, -1 if we
806 /* If we know the pid file, then lets just check if it is
808 if (s->main_pid_known)
809 return s->main_pid > 0;
811 /* We don't know the pid */
815 static bool control_pid_good(Service *s) {
818 return s->control_pid > 0;
821 static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
822 Service *s = SERVICE(u);
828 success = code == CLD_EXITED && status == 0;
829 s->failure = s->failure || !success;
831 if (s->main_pid == pid) {
833 exec_status_fill(&s->main_exec_status, pid, code, status);
836 if (s->type == SERVICE_SIMPLE || s->type == SERVICE_FINISH) {
837 assert(s->exec_command[SERVICE_EXEC_START]);
838 s->exec_command[SERVICE_EXEC_START]->exec_status = s->main_exec_status;
841 log_debug("%s: main process exited, code=%s status=%i", unit_id(u), sigchld_code_to_string(code), status);
843 /* The service exited, so the service is officially
848 case SERVICE_START_POST:
851 /* Need to wait until the operation is
856 assert(s->type == SERVICE_FINISH);
858 /* This was our main goal, so let's go on */
860 service_enter_start_post(s);
862 service_enter_stop(s, false);
865 case SERVICE_RUNNING:
866 service_enter_stop(s, success);
869 case SERVICE_STOP_SIGTERM:
870 case SERVICE_STOP_SIGKILL:
872 if (!control_pid_good(s))
873 service_enter_stop_post(s, success);
875 /* If there is still a control process, wait for that first */
879 assert_not_reached("Uh, main process died at wrong time.");
882 } else if (s->control_pid == pid) {
883 assert(s->control_command);
885 exec_status_fill(&s->control_command->exec_status, pid, code, status);
888 log_debug("%s: control process exited, code=%s status=%i", unit_id(u), sigchld_code_to_string(code), status);
890 /* If we are shutting things down anyway we
891 * don't care about failing commands. */
893 if (s->control_command->command_next &&
894 (success || (s->state == SERVICE_EXEC_STOP || s->state == SERVICE_EXEC_STOP_POST)))
896 /* There is another command to *
897 * execute, so let's do that. */
899 service_run_next(s, success);
902 /* No further commands for this step, so let's
903 * figure out what to do next */
905 log_debug("%s got final SIGCHLD for state %s", unit_id(u), service_state_to_string(s->state));
909 case SERVICE_START_PRE:
911 service_enter_start(s);
913 service_enter_stop(s, false);
917 assert(s->type == SERVICE_FORKING);
919 /* Let's try to load the pid
920 * file here if we can. We
921 * ignore the return value,
922 * since the PID file might
923 * actually be created by a
924 * START_POST script */
928 service_load_pid_file(s);
930 service_enter_start_post(s);
932 service_enter_stop(s, false);
936 case SERVICE_START_POST:
937 if (success && s->pid_file && !s->main_pid_known) {
940 /* Hmm, let's see if we can
941 * load the pid now after the
942 * start-post scripts got
945 if ((r = service_load_pid_file(s)) < 0)
946 log_warning("%s: failed to load PID file %s: %s", unit_id(UNIT(s)), s->pid_file, strerror(-r));
953 if (main_pid_good(s) != 0)
954 service_set_state(s, SERVICE_RUNNING);
956 service_enter_stop(s, true);
958 service_enter_stop(s, false);
963 if (main_pid_good(s) > 0)
964 /* Still not dead and we know the PID? Let's go hunting. */
965 service_enter_signal(s, SERVICE_STOP_SIGTERM, success);
967 service_enter_stop_post(s, success);
970 case SERVICE_STOP_SIGTERM:
971 case SERVICE_STOP_SIGKILL:
972 if (main_pid_good(s) <= 0)
973 service_enter_stop_post(s, success);
975 /* If there is still a service
976 * process around, wait until
977 * that one quit, too */
980 case SERVICE_STOP_POST:
981 case SERVICE_FINAL_SIGTERM:
982 case SERVICE_FINAL_SIGKILL:
983 service_enter_dead(s, success, true);
987 assert_not_reached("Uh, control process died at wrong time.");
991 assert_not_reached("Got SIGCHLD for unkown PID");
994 static void service_timer_event(Unit *u, uint64_t elapsed, Watch* w) {
995 Service *s = SERVICE(u);
998 assert(elapsed == 1);
1000 assert(w == &s->timer_watch);
1004 case SERVICE_START_PRE:
1006 case SERVICE_START_POST:
1007 case SERVICE_RELOAD:
1008 log_warning("%s operation timed out. Stopping.", unit_id(u));
1009 service_enter_stop(s, false);
1013 log_warning("%s stopping timed out. Terminating.", unit_id(u));
1014 service_enter_signal(s, SERVICE_STOP_SIGTERM, false);
1017 case SERVICE_STOP_SIGTERM:
1018 log_warning("%s stopping timed out. Killing.", unit_id(u));
1019 service_enter_signal(s, SERVICE_STOP_SIGKILL, false);
1022 case SERVICE_STOP_SIGKILL:
1023 /* Uh, wie sent a SIGKILL and it is still not gone?
1024 * Must be something we cannot kill, so let's just be
1025 * weirded out and continue */
1027 log_warning("%s still around after SIGKILL. Ignoring.", unit_id(u));
1028 service_enter_stop_post(s, false);
1031 case SERVICE_STOP_POST:
1032 log_warning("%s stopping timed out (2). Terminating.", unit_id(u));
1033 service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
1036 case SERVICE_FINAL_SIGTERM:
1037 log_warning("%s stopping timed out (2). Killing.", unit_id(u));
1038 service_enter_signal(s, SERVICE_FINAL_SIGKILL, false);
1041 case SERVICE_FINAL_SIGKILL:
1042 log_warning("%s still around after SIGKILL (2). Entering maintainance mode.", unit_id(u));
1043 service_enter_dead(s, false, true);
1046 case SERVICE_AUTO_RESTART:
1047 log_debug("%s holdoff time over, scheduling restart.", unit_id(u));
1048 service_enter_restart(s);
1052 assert_not_reached("Timeout at wrong time.");
1056 static const char* const service_state_table[_SERVICE_STATE_MAX] = {
1057 [SERVICE_DEAD] = "dead",
1058 [SERVICE_START_PRE] = "start-pre",
1059 [SERVICE_START] = "start",
1060 [SERVICE_START_POST] = "start-post",
1061 [SERVICE_RUNNING] = "running",
1062 [SERVICE_RELOAD] = "reload",
1063 [SERVICE_STOP] = "stop",
1064 [SERVICE_STOP_SIGTERM] = "stop-sigterm",
1065 [SERVICE_STOP_SIGKILL] = "stop-sigkill",
1066 [SERVICE_STOP_POST] = "stop-post",
1067 [SERVICE_FINAL_SIGTERM] = "final-sigterm",
1068 [SERVICE_FINAL_SIGKILL] = "final-sigkill",
1069 [SERVICE_MAINTAINANCE] = "maintainance",
1070 [SERVICE_AUTO_RESTART] = "auto-restart",
1073 DEFINE_STRING_TABLE_LOOKUP(service_state, ServiceState);
1075 static const char* const service_restart_table[_SERVICE_RESTART_MAX] = {
1076 [SERVICE_ONCE] = "once",
1077 [SERVICE_RESTART_ON_SUCCESS] = "restart-on-success",
1078 [SERVICE_RESTART_ALWAYS] = "restart-on-failure",
1081 DEFINE_STRING_TABLE_LOOKUP(service_restart, ServiceRestart);
1083 static const char* const service_type_table[_SERVICE_TYPE_MAX] = {
1084 [SERVICE_FORKING] = "forking",
1085 [SERVICE_SIMPLE] = "simple",
1086 [SERVICE_FINISH] = "finish"
1089 DEFINE_STRING_TABLE_LOOKUP(service_type, ServiceType);
1091 static const char* const service_exec_command_table[_SERVICE_EXEC_MAX] = {
1092 [SERVICE_EXEC_START_PRE] = "ExecStartPre",
1093 [SERVICE_EXEC_START] = "ExecStart",
1094 [SERVICE_EXEC_START_POST] = "ExecStartPost",
1095 [SERVICE_EXEC_RELOAD] = "ExecReload",
1096 [SERVICE_EXEC_STOP] = "ExecStop",
1097 [SERVICE_EXEC_STOP_POST] = "ExecStopPost",
1100 DEFINE_STRING_TABLE_LOOKUP(service_exec_command, ServiceExecCommand);
1102 const UnitVTable service_vtable = {
1103 .suffix = ".service",
1105 .init = service_init,
1106 .done = service_done,
1108 .dump = service_dump,
1110 .start = service_start,
1111 .stop = service_stop,
1112 .reload = service_reload,
1114 .can_reload = service_can_reload,
1116 .active_state = service_active_state,
1118 .sigchld_event = service_sigchld_event,
1119 .timer_event = service_timer_event,