1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
8 #include "load-fragment.h"
9 #include "load-dropin.h"
12 static const UnitActiveState state_translation_table
[_SERVICE_STATE_MAX
] = {
13 [SERVICE_DEAD
] = UNIT_INACTIVE
,
14 [SERVICE_START_PRE
] = UNIT_ACTIVATING
,
15 [SERVICE_START
] = UNIT_ACTIVATING
,
16 [SERVICE_START_POST
] = UNIT_ACTIVATING
,
17 [SERVICE_RUNNING
] = UNIT_ACTIVE
,
18 [SERVICE_RELOAD
] = UNIT_ACTIVE_RELOADING
,
19 [SERVICE_STOP
] = UNIT_DEACTIVATING
,
20 [SERVICE_STOP_SIGTERM
] = UNIT_DEACTIVATING
,
21 [SERVICE_STOP_SIGKILL
] = UNIT_DEACTIVATING
,
22 [SERVICE_STOP_POST
] = UNIT_DEACTIVATING
,
23 [SERVICE_FINAL_SIGTERM
] = UNIT_DEACTIVATING
,
24 [SERVICE_FINAL_SIGKILL
] = UNIT_DEACTIVATING
,
25 [SERVICE_MAINTAINANCE
] = UNIT_INACTIVE
,
26 [SERVICE_AUTO_RESTART
] = UNIT_ACTIVATING
,
29 static void service_done(Unit
*u
) {
30 Service
*s
= SERVICE(u
);
37 exec_context_done(&s
->exec_context
);
38 exec_command_free_array(s
->exec_command
, _SERVICE_EXEC_MAX
);
39 s
->control_command
= NULL
;
41 /* This will leak a process, but at least no memory or any of
43 if (s
->main_pid
> 0) {
44 unit_unwatch_pid(u
, s
->main_pid
);
48 if (s
->control_pid
> 0) {
49 unit_unwatch_pid(u
, s
->control_pid
);
53 unit_unwatch_timer(u
, &s
->timer_watch
);
56 static int service_load_sysv(Service
*s
) {
59 /* Load service data from SysV init scripts, preferably with
65 static int service_init(Unit
*u
) {
67 Service
*s
= SERVICE(u
);
71 /* First, reset everything to the defaults, in case this is a
77 s
->timeout_usec
= DEFAULT_TIMEOUT_USEC
;
78 s
->restart_usec
= DEFAULT_RESTART_USEC
;
80 exec_context_init(&s
->exec_context
);
82 s
->timer_watch
.type
= WATCH_INVALID
;
84 s
->state
= SERVICE_DEAD
;
86 RATELIMIT_INIT(s
->ratelimit
, 10*USEC_PER_SEC
, 5);
88 /* Load a .service file */
89 if ((r
= unit_load_fragment(u
)) < 0) {
94 /* Load a classic init script as a fallback, if we couldn*t find anything */
96 if ((r
= service_load_sysv(s
)) <= 0) {
98 return r
< 0 ? r
: -ENOENT
;
101 /* Load dropin directory data */
102 if ((r
= unit_load_dropin(u
)) < 0) {
110 static void service_dump(Unit
*u
, FILE *f
, const char *prefix
) {
112 ServiceExecCommand c
;
113 Service
*s
= SERVICE(u
);
118 prefix2
= strappend(prefix
, "\t");
123 "%sService State: %s\n",
124 prefix
, service_state_to_string(s
->state
));
129 prefix
, s
->pid_file
);
132 exec_context_dump(&s
->exec_context
, f
, prefix
);
134 for (c
= 0; c
< _SERVICE_EXEC_MAX
; c
++) {
136 if (!s
->exec_command
[c
])
139 fprintf(f
, "%s→ %s:\n",
140 prefix
, service_exec_command_to_string(c
));
142 exec_command_dump_list(s
->exec_command
[c
], f
, prefix2
);
148 static int service_load_pid_file(Service
*s
) {
155 if (s
->main_pid_known
)
161 if ((r
= read_one_line_file(s
->pid_file
, &k
)) < 0)
164 if ((r
= safe_atolu(k
, &p
)) < 0) {
169 if ((unsigned long) (pid_t
) p
!= p
)
173 s
->main_pid_known
= true;
178 static int service_get_sockets(Service
*s
, Set
**_set
) {
187 /* Collects all Socket objects that belong to this
188 * service. Note that a service might have multiple sockets
189 * via multiple names. */
191 if (!(set
= set_new(NULL
, NULL
)))
194 SET_FOREACH(t
, UNIT(s
)->meta
.names
, i
) {
198 /* Look for all socket objects that go by any of our
199 * units and collect their fds */
201 if (!(k
= unit_name_change_suffix(t
, ".socket"))) {
206 p
= manager_get_unit(UNIT(s
)->meta
.manager
, k
);
211 if ((r
= set_put(set
, p
)) < 0)
224 static int service_notify_sockets(Service
*s
) {
232 /* Notifies all our sockets when we die */
234 if ((r
= service_get_sockets(s
, &set
)) < 0)
237 SET_FOREACH(socket
, set
, i
)
238 socket_notify_service_dead(socket
);
245 static void service_set_state(Service
*s
, ServiceState state
) {
246 ServiceState old_state
;
249 old_state
= s
->state
;
252 if (state
!= SERVICE_START_PRE
&&
253 state
!= SERVICE_START
&&
254 state
!= SERVICE_START_POST
&&
255 state
!= SERVICE_RELOAD
&&
256 state
!= SERVICE_STOP
&&
257 state
!= SERVICE_STOP_SIGTERM
&&
258 state
!= SERVICE_STOP_SIGKILL
&&
259 state
!= SERVICE_STOP_POST
&&
260 state
!= SERVICE_FINAL_SIGTERM
&&
261 state
!= SERVICE_FINAL_SIGKILL
&&
262 state
!= SERVICE_AUTO_RESTART
)
263 unit_unwatch_timer(UNIT(s
), &s
->timer_watch
);
265 if (state
!= SERVICE_START_POST
&&
266 state
!= SERVICE_RUNNING
&&
267 state
!= SERVICE_RELOAD
&&
268 state
!= SERVICE_STOP
&&
269 state
!= SERVICE_STOP_SIGTERM
&&
270 state
!= SERVICE_STOP_SIGKILL
)
271 if (s
->main_pid
> 0) {
272 unit_unwatch_pid(UNIT(s
), s
->main_pid
);
276 if (state
!= SERVICE_START_PRE
&&
277 state
!= SERVICE_START
&&
278 state
!= SERVICE_START_POST
&&
279 state
!= SERVICE_RELOAD
&&
280 state
!= SERVICE_STOP
&&
281 state
!= SERVICE_STOP_SIGTERM
&&
282 state
!= SERVICE_STOP_SIGKILL
&&
283 state
!= SERVICE_STOP_POST
&&
284 state
!= SERVICE_FINAL_SIGTERM
&&
285 state
!= SERVICE_FINAL_SIGKILL
)
286 if (s
->control_pid
> 0) {
287 unit_unwatch_pid(UNIT(s
), s
->control_pid
);
291 if (state
!= SERVICE_START_PRE
&&
292 state
!= SERVICE_START
&&
293 state
!= SERVICE_START_POST
&&
294 state
!= SERVICE_RELOAD
&&
295 state
!= SERVICE_STOP
&&
296 state
!= SERVICE_STOP_POST
)
297 s
->control_command
= NULL
;
299 if (state
== SERVICE_DEAD
||
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 state
== SERVICE_MAINTAINANCE
||
307 state
== SERVICE_AUTO_RESTART
)
308 service_notify_sockets(s
);
310 log_debug("%s changed %s → %s", unit_id(UNIT(s
)), service_state_to_string(old_state
), service_state_to_string(state
));
312 unit_notify(UNIT(s
), state_translation_table
[old_state
], state_translation_table
[state
]);
315 static int service_collect_fds(Service
*s
, int **fds
, unsigned *n_fds
) {
327 if ((r
= service_get_sockets(s
, &set
)) < 0)
330 SET_FOREACH(socket
, set
, i
) {
334 if ((r
= socket_collect_fds(socket
, &cfds
, &cn_fds
)) < 0)
346 if (!(t
= new(int, rn_fds
+cn_fds
))) {
352 memcpy(t
, rfds
, rn_fds
);
353 memcpy(t
+rn_fds
, cfds
, cn_fds
);
358 rn_fds
= rn_fds
+cn_fds
;
376 static int service_spawn(Service
*s
, ExecCommand
*c
, bool timeout
, bool pass_fds
, pid_t
*_pid
) {
387 if ((r
= service_collect_fds(s
, &fds
, &n_fds
)) < 0)
391 if ((r
= unit_watch_timer(UNIT(s
), s
->timeout_usec
, &s
->timer_watch
)) < 0)
394 unit_unwatch_timer(UNIT(s
), &s
->timer_watch
);
396 if ((r
= exec_spawn(c
, &s
->exec_context
, fds
, n_fds
, &pid
)) < 0)
399 if ((r
= unit_watch_pid(UNIT(s
), pid
)) < 0)
400 /* FIXME: we need to do something here */
412 unit_unwatch_timer(UNIT(s
), &s
->timer_watch
);
417 static void service_enter_dead(Service
*s
, bool success
, bool allow_restart
) {
425 (s
->restart
== SERVICE_RESTART_ALWAYS
||
426 (s
->restart
== SERVICE_RESTART_ON_SUCCESS
&& !s
->failure
))) {
428 if ((r
= unit_watch_timer(UNIT(s
), s
->restart_usec
, &s
->timer_watch
)) < 0)
431 service_set_state(s
, SERVICE_AUTO_RESTART
);
433 service_set_state(s
, s
->failure
? SERVICE_MAINTAINANCE
: SERVICE_DEAD
);
438 log_warning("%s failed to run install restart timer: %s", unit_id(UNIT(s
)), strerror(-r
));
439 service_enter_dead(s
, false, false);
442 static void service_enter_signal(Service
*s
, ServiceState state
, bool success
);
444 static void service_enter_stop_post(Service
*s
, bool success
) {
451 if ((s
->control_command
= s
->exec_command
[SERVICE_EXEC_STOP_POST
]))
452 if ((r
= service_spawn(s
, s
->control_command
, true, false, &s
->control_pid
)) < 0)
456 service_set_state(s
, SERVICE_STOP_POST
);
458 if (!s
->control_command
)
459 service_enter_dead(s
, true, true);
464 log_warning("%s failed to run stop executable: %s", unit_id(UNIT(s
)), strerror(-r
));
465 service_enter_signal(s
, SERVICE_FINAL_SIGTERM
, false);
468 static void service_enter_signal(Service
*s
, ServiceState state
, bool success
) {
477 if (s
->main_pid
> 0 || s
->control_pid
> 0) {
480 sig
= (state
== SERVICE_STOP_SIGTERM
|| state
== SERVICE_FINAL_SIGTERM
) ? SIGTERM
: SIGKILL
;
483 if (s
->main_pid
> 0) {
484 if (kill(s
->main_pid
, sig
) < 0 && errno
!= ESRCH
)
490 if (s
->control_pid
> 0) {
491 if (kill(s
->control_pid
, sig
) < 0 && errno
!= ESRCH
)
501 service_set_state(s
, state
);
503 if (s
->main_pid
<= 0 && s
->control_pid
<= 0)
504 service_enter_dead(s
, true, true);
509 log_warning("%s failed to kill processes: %s", unit_id(UNIT(s
)), strerror(-r
));
513 service_set_state(s
, state
);
514 } else if (state
== SERVICE_STOP_SIGTERM
|| state
== SERVICE_STOP_SIGKILL
)
515 service_enter_stop_post(s
, false);
517 service_enter_dead(s
, false, true);
520 static void service_enter_stop(Service
*s
, bool success
) {
527 if ((s
->control_command
= s
->exec_command
[SERVICE_EXEC_STOP
]))
528 if ((r
= service_spawn(s
, s
->control_command
, true, false, &s
->control_pid
)) < 0)
531 service_set_state(s
, SERVICE_STOP
);
533 if (!s
->control_command
)
534 service_enter_signal(s
, SERVICE_STOP_SIGTERM
, true);
539 log_warning("%s failed to run stop executable: %s", unit_id(UNIT(s
)), strerror(-r
));
540 service_enter_signal(s
, SERVICE_STOP_SIGTERM
, false);
543 static void service_enter_start_post(Service
*s
) {
547 if ((s
->control_command
= s
->exec_command
[SERVICE_EXEC_START_POST
]))
548 if ((r
= service_spawn(s
, s
->control_command
, true, false, &s
->control_pid
)) < 0)
552 service_set_state(s
, SERVICE_START_POST
);
554 if (!s
->control_command
)
555 service_set_state(s
, SERVICE_RUNNING
);
560 log_warning("%s failed to run start-post executable: %s", unit_id(UNIT(s
)), strerror(-r
));
561 service_enter_stop(s
, false);
564 static void service_enter_start(Service
*s
) {
570 assert(s
->exec_command
[SERVICE_EXEC_START
]);
571 assert(!s
->exec_command
[SERVICE_EXEC_START
]->command_next
);
573 if ((r
= service_spawn(s
, s
->exec_command
[SERVICE_EXEC_START
], s
->type
== SERVICE_FORKING
, true, &pid
)) < 0)
576 service_set_state(s
, SERVICE_START
);
578 if (s
->type
== SERVICE_SIMPLE
) {
579 /* For simple services we immediately start
580 * the START_POST binaries. */
583 s
->main_pid_known
= true;
584 service_enter_start_post(s
);
586 } else if (s
->type
== SERVICE_FORKING
) {
588 /* For forking services we wait until the start
591 s
->control_pid
= pid
;
592 s
->control_command
= s
->exec_command
[SERVICE_EXEC_START
];
594 assert_not_reached("Unknown service type");
599 log_warning("%s failed to run start exectuable: %s", unit_id(UNIT(s
)), strerror(-r
));
600 service_enter_stop(s
, false);
603 static void service_enter_start_pre(Service
*s
) {
608 if ((s
->control_command
= s
->exec_command
[SERVICE_EXEC_START_PRE
]))
609 if ((r
= service_spawn(s
, s
->control_command
, true, false, &s
->control_pid
)) < 0)
612 service_set_state(s
, SERVICE_START_PRE
);
614 if (!s
->control_command
)
615 service_enter_start(s
);
620 log_warning("%s failed to run start-pre executable: %s", unit_id(UNIT(s
)), strerror(-r
));
621 service_enter_dead(s
, false, true);
624 static void service_enter_restart(Service
*s
) {
628 if ((r
= manager_add_job(UNIT(s
)->meta
.manager
, JOB_START
, UNIT(s
), JOB_FAIL
, false, NULL
)) < 0)
631 log_debug("%s scheduled restart job.", unit_id(UNIT(s
)));
632 service_enter_dead(s
, true, false);
637 log_warning("%s failed to schedule restart job: %s", unit_id(UNIT(s
)), strerror(-r
));
638 service_enter_dead(s
, false, false);
641 static void service_enter_reload(Service
*s
) {
646 if ((s
->control_command
= s
->exec_command
[SERVICE_EXEC_RELOAD
]))
647 if ((r
= service_spawn(s
, s
->control_command
, true, false, &s
->control_pid
)) < 0)
650 service_set_state(s
, SERVICE_RELOAD
);
652 if (!s
->control_command
)
653 service_set_state(s
, SERVICE_RUNNING
);
658 log_warning("%s failed to run reload executable: %s", unit_id(UNIT(s
)), strerror(-r
));
659 service_enter_stop(s
, false);
662 static void service_run_next(Service
*s
, bool success
) {
666 assert(s
->control_command
);
667 assert(s
->control_command
->command_next
);
672 s
->control_command
= s
->control_command
->command_next
;
674 if ((r
= service_spawn(s
, s
->control_command
, true, false, &s
->control_pid
)) < 0)
680 log_warning("%s failed to run spawn next executable: %s", unit_id(UNIT(s
)), strerror(-r
));
682 if (s
->state
== SERVICE_STOP
)
683 service_enter_stop_post(s
, false);
684 else if (s
->state
== SERVICE_STOP_POST
)
685 service_enter_dead(s
, false, true);
687 service_enter_stop(s
, false);
690 static int service_start(Unit
*u
) {
691 Service
*s
= SERVICE(u
);
695 /* We cannot fulfill this request right now, try again later
697 if (s
->state
== SERVICE_STOP
||
698 s
->state
== SERVICE_STOP_SIGTERM
||
699 s
->state
== SERVICE_STOP_SIGKILL
||
700 s
->state
== SERVICE_STOP_POST
||
701 s
->state
== SERVICE_FINAL_SIGTERM
||
702 s
->state
== SERVICE_FINAL_SIGKILL
)
706 if (s
->state
== SERVICE_START_PRE
||
707 s
->state
== SERVICE_START
||
708 s
->state
== SERVICE_START_POST
)
711 assert(s
->state
== SERVICE_DEAD
|| s
->state
== SERVICE_MAINTAINANCE
|| s
->state
== SERVICE_AUTO_RESTART
);
713 /* Make sure we don't enter a busy loop of some kind. */
714 if (!ratelimit_test(&s
->ratelimit
)) {
715 log_warning("%s start request repeated too quickly, refusing to start.", unit_id(u
));
720 s
->main_pid_known
= false;
722 service_enter_start_pre(s
);
726 static int service_stop(Unit
*u
) {
727 Service
*s
= SERVICE(u
);
731 if (s
->state
== SERVICE_START_PRE
||
732 s
->state
== SERVICE_START
||
733 s
->state
== SERVICE_START_POST
||
734 s
->state
== SERVICE_RELOAD
)
737 if (s
->state
== SERVICE_AUTO_RESTART
) {
738 service_set_state(s
, SERVICE_DEAD
);
742 assert(s
->state
== SERVICE_RUNNING
);
744 service_enter_stop(s
, true);
748 static int service_reload(Unit
*u
) {
749 Service
*s
= SERVICE(u
);
753 assert(s
->state
== SERVICE_RUNNING
);
755 service_enter_reload(s
);
759 static bool service_can_reload(Unit
*u
) {
760 Service
*s
= SERVICE(u
);
764 return !!s
->exec_command
[SERVICE_EXEC_RELOAD
];
767 static UnitActiveState
service_active_state(Unit
*u
) {
770 return state_translation_table
[SERVICE(u
)->state
];
773 static int main_pid_good(Service
*s
) {
776 /* Returns 0 if the pid is dead, 1 if it is good, -1 if we
779 /* If we know the pid file, then lets just check if it is
781 if (s
->main_pid_known
)
782 return s
->main_pid
> 0;
784 /* We don't know the pid */
788 static bool control_pid_good(Service
*s
) {
791 return s
->control_pid
> 0;
794 static void service_sigchld_event(Unit
*u
, pid_t pid
, int code
, int status
) {
795 Service
*s
= SERVICE(u
);
801 success
= code
== CLD_EXITED
&& status
== 0;
802 s
->failure
= s
->failure
|| !success
;
804 if (s
->main_pid
== pid
) {
806 exec_status_fill(&s
->main_exec_status
, pid
, code
, status
);
809 if (s
->type
== SERVICE_SIMPLE
) {
810 assert(s
->exec_command
[SERVICE_EXEC_START
]);
811 s
->exec_command
[SERVICE_EXEC_START
]->exec_status
= s
->main_exec_status
;
814 log_debug("%s: main process exited, code=%s status=%i", unit_id(u
), sigchld_code_to_string(code
), status
);
816 /* The service exited, so the service is officially
821 case SERVICE_START_POST
:
824 /* Need to wait until the operation is
828 case SERVICE_RUNNING
:
829 service_enter_stop(s
, success
);
832 case SERVICE_STOP_SIGTERM
:
833 case SERVICE_STOP_SIGKILL
:
835 if (!control_pid_good(s
))
836 service_enter_stop_post(s
, success
);
838 /* If there is still a control process, wait for that first */
842 assert_not_reached("Uh, main process died at wrong time.");
845 } else if (s
->control_pid
== pid
) {
846 assert(s
->control_command
);
848 exec_status_fill(&s
->control_command
->exec_status
, pid
, code
, status
);
851 log_debug("%s: control process exited, code=%s status=%i", unit_id(u
), sigchld_code_to_string(code
), status
);
853 /* If we are shutting things down anyway we
854 * don't care about failing commands. */
856 if (s
->control_command
->command_next
&&
857 (success
|| (s
->state
== SERVICE_EXEC_STOP
|| s
->state
== SERVICE_EXEC_STOP_POST
)))
859 /* There is another command to *
860 * execute, so let's do that. */
862 service_run_next(s
, success
);
865 /* No further commands for this step, so let's
866 * figure out what to do next */
868 log_debug("%s got final SIGCHLD for state %s", unit_id(u
), service_state_to_string(s
->state
));
872 case SERVICE_START_PRE
:
874 service_enter_start(s
);
876 service_enter_stop(s
, false);
880 assert(s
->type
== SERVICE_FORKING
);
882 /* Let's try to load the pid
883 * file here if we can. We
884 * ignore the return value,
885 * since the PID file might
886 * actually be created by a
887 * START_POST script */
891 service_load_pid_file(s
);
893 service_enter_start_post(s
);
895 service_enter_stop(s
, false);
899 case SERVICE_START_POST
:
900 if (success
&& s
->pid_file
&& !s
->main_pid_known
) {
903 /* Hmm, let's see if we can
904 * load the pid now after the
905 * start-post scripts got
908 if ((r
= service_load_pid_file(s
)) < 0)
909 log_warning("%s: failed to load PID file %s: %s", unit_id(UNIT(s
)), s
->pid_file
, strerror(-r
));
916 if (main_pid_good(s
) != 0)
917 service_set_state(s
, SERVICE_RUNNING
);
919 service_enter_stop(s
, true);
921 service_enter_stop(s
, false);
926 if (main_pid_good(s
) > 0)
927 /* Still not dead and we know the PID? Let's go hunting. */
928 service_enter_signal(s
, SERVICE_STOP_SIGTERM
, success
);
930 service_enter_stop_post(s
, success
);
933 case SERVICE_STOP_SIGTERM
:
934 case SERVICE_STOP_SIGKILL
:
935 if (main_pid_good(s
) <= 0)
936 service_enter_stop_post(s
, success
);
938 /* If there is still a service
939 * process around, wait until
940 * that one quit, too */
943 case SERVICE_STOP_POST
:
944 case SERVICE_FINAL_SIGTERM
:
945 case SERVICE_FINAL_SIGKILL
:
946 service_enter_dead(s
, success
, true);
950 assert_not_reached("Uh, control process died at wrong time.");
954 assert_not_reached("Got SIGCHLD for unkown PID");
957 static void service_timer_event(Unit
*u
, uint64_t elapsed
, Watch
* w
) {
958 Service
*s
= SERVICE(u
);
961 assert(elapsed
== 1);
963 assert(w
== &s
->timer_watch
);
967 case SERVICE_START_PRE
:
969 case SERVICE_START_POST
:
971 log_warning("%s operation timed out. Stopping.", unit_id(u
));
972 service_enter_stop(s
, false);
976 log_warning("%s stopping timed out. Terminating.", unit_id(u
));
977 service_enter_signal(s
, SERVICE_STOP_SIGTERM
, false);
980 case SERVICE_STOP_SIGTERM
:
981 log_warning("%s stopping timed out. Killing.", unit_id(u
));
982 service_enter_signal(s
, SERVICE_STOP_SIGKILL
, false);
985 case SERVICE_STOP_SIGKILL
:
986 /* Uh, wie sent a SIGKILL and it is still not gone?
987 * Must be something we cannot kill, so let's just be
988 * weirded out and continue */
990 log_warning("%s still around after SIGKILL. Ignoring.", unit_id(u
));
991 service_enter_stop_post(s
, false);
994 case SERVICE_STOP_POST
:
995 log_warning("%s stopping timed out (2). Terminating.", unit_id(u
));
996 service_enter_signal(s
, SERVICE_FINAL_SIGTERM
, false);
999 case SERVICE_FINAL_SIGTERM
:
1000 log_warning("%s stopping timed out (2). Killing.", unit_id(u
));
1001 service_enter_signal(s
, SERVICE_FINAL_SIGKILL
, false);
1004 case SERVICE_FINAL_SIGKILL
:
1005 log_warning("%s still around after SIGKILL (2). Entering maintainance mode.", unit_id(u
));
1006 service_enter_dead(s
, false, true);
1009 case SERVICE_AUTO_RESTART
:
1010 log_debug("%s holdoff time over, scheduling restart.", unit_id(u
));
1011 service_enter_restart(s
);
1015 assert_not_reached("Timeout at wrong time.");
1019 static const char* const service_state_table
[_SERVICE_STATE_MAX
] = {
1020 [SERVICE_DEAD
] = "dead",
1021 [SERVICE_START_PRE
] = "start-pre",
1022 [SERVICE_START
] = "start",
1023 [SERVICE_START_POST
] = "start-post",
1024 [SERVICE_RUNNING
] = "running",
1025 [SERVICE_RELOAD
] = "reload",
1026 [SERVICE_STOP
] = "stop",
1027 [SERVICE_STOP_SIGTERM
] = "stop-sigterm",
1028 [SERVICE_STOP_SIGKILL
] = "stop-sigkill",
1029 [SERVICE_STOP_POST
] = "stop-post",
1030 [SERVICE_FINAL_SIGTERM
] = "final-sigterm",
1031 [SERVICE_FINAL_SIGKILL
] = "final-sigkill",
1032 [SERVICE_MAINTAINANCE
] = "maintainance",
1033 [SERVICE_AUTO_RESTART
] = "auto-restart",
1036 DEFINE_STRING_TABLE_LOOKUP(service_state
, ServiceState
);
1038 static const char* const service_restart_table
[_SERVICE_RESTART_MAX
] = {
1039 [SERVICE_ONCE
] = "once",
1040 [SERVICE_RESTART_ON_SUCCESS
] = "restart-on-success",
1041 [SERVICE_RESTART_ALWAYS
] = "restart-on-failure",
1044 DEFINE_STRING_TABLE_LOOKUP(service_restart
, ServiceRestart
);
1046 static const char* const service_type_table
[_SERVICE_TYPE_MAX
] = {
1047 [SERVICE_FORKING
] = "forking",
1048 [SERVICE_SIMPLE
] = "simple",
1049 [SERVICE_FINISH
] = "finish"
1052 DEFINE_STRING_TABLE_LOOKUP(service_type
, ServiceType
);
1054 static const char* const service_exec_command_table
[_SERVICE_EXEC_MAX
] = {
1055 [SERVICE_EXEC_START_PRE
] = "ExecStartPre",
1056 [SERVICE_EXEC_START
] = "ExecStart",
1057 [SERVICE_EXEC_START_POST
] = "ExecStartPost",
1058 [SERVICE_EXEC_RELOAD
] = "ExecReload",
1059 [SERVICE_EXEC_STOP
] = "ExecStop",
1060 [SERVICE_EXEC_STOP_POST
] = "ExecStopPost",
1063 DEFINE_STRING_TABLE_LOOKUP(service_exec_command
, ServiceExecCommand
);
1065 const UnitVTable service_vtable
= {
1066 .suffix
= ".service",
1068 .init
= service_init
,
1069 .done
= service_done
,
1071 .dump
= service_dump
,
1073 .start
= service_start
,
1074 .stop
= service_stop
,
1075 .reload
= service_reload
,
1077 .can_reload
= service_can_reload
,
1079 .active_state
= service_active_state
,
1081 .sigchld_event
= service_sigchld_event
,
1082 .timer_event
= service_timer_event
,