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
&&
266 state
!= SERVICE_START_POST
&&
267 state
!= SERVICE_RUNNING
&&
268 state
!= SERVICE_RELOAD
&&
269 state
!= SERVICE_STOP
&&
270 state
!= SERVICE_STOP_SIGTERM
&&
271 state
!= SERVICE_STOP_SIGKILL
)
272 if (s
->main_pid
> 0) {
273 unit_unwatch_pid(UNIT(s
), s
->main_pid
);
277 if (state
!= SERVICE_START_PRE
&&
278 state
!= SERVICE_START
&&
279 state
!= SERVICE_START_POST
&&
280 state
!= SERVICE_RELOAD
&&
281 state
!= SERVICE_STOP
&&
282 state
!= SERVICE_STOP_SIGTERM
&&
283 state
!= SERVICE_STOP_SIGKILL
&&
284 state
!= SERVICE_STOP_POST
&&
285 state
!= SERVICE_FINAL_SIGTERM
&&
286 state
!= SERVICE_FINAL_SIGKILL
)
287 if (s
->control_pid
> 0) {
288 unit_unwatch_pid(UNIT(s
), s
->control_pid
);
292 if (state
!= SERVICE_START_PRE
&&
293 state
!= SERVICE_START
&&
294 state
!= SERVICE_START_POST
&&
295 state
!= SERVICE_RELOAD
&&
296 state
!= SERVICE_STOP
&&
297 state
!= SERVICE_STOP_POST
)
298 s
->control_command
= NULL
;
300 if (state
== SERVICE_DEAD
||
301 state
== SERVICE_STOP
||
302 state
== SERVICE_STOP_SIGTERM
||
303 state
== SERVICE_STOP_SIGKILL
||
304 state
== SERVICE_STOP_POST
||
305 state
== SERVICE_FINAL_SIGTERM
||
306 state
== SERVICE_FINAL_SIGKILL
||
307 state
== SERVICE_MAINTAINANCE
||
308 state
== SERVICE_AUTO_RESTART
)
309 service_notify_sockets(s
);
311 log_debug("%s changed %s → %s", unit_id(UNIT(s
)), service_state_to_string(old_state
), service_state_to_string(state
));
313 unit_notify(UNIT(s
), state_translation_table
[old_state
], state_translation_table
[state
]);
316 static int service_collect_fds(Service
*s
, int **fds
, unsigned *n_fds
) {
328 if ((r
= service_get_sockets(s
, &set
)) < 0)
331 SET_FOREACH(socket
, set
, i
) {
335 if ((r
= socket_collect_fds(socket
, &cfds
, &cn_fds
)) < 0)
347 if (!(t
= new(int, rn_fds
+cn_fds
))) {
353 memcpy(t
, rfds
, rn_fds
);
354 memcpy(t
+rn_fds
, cfds
, cn_fds
);
359 rn_fds
= rn_fds
+cn_fds
;
377 static int service_spawn(Service
*s
, ExecCommand
*c
, bool timeout
, bool pass_fds
, pid_t
*_pid
) {
388 if ((r
= service_collect_fds(s
, &fds
, &n_fds
)) < 0)
392 if ((r
= unit_watch_timer(UNIT(s
), s
->timeout_usec
, &s
->timer_watch
)) < 0)
395 unit_unwatch_timer(UNIT(s
), &s
->timer_watch
);
397 if ((r
= exec_spawn(c
, &s
->exec_context
, fds
, n_fds
, &pid
)) < 0)
400 if ((r
= unit_watch_pid(UNIT(s
), pid
)) < 0)
401 /* FIXME: we need to do something here */
413 unit_unwatch_timer(UNIT(s
), &s
->timer_watch
);
418 static void service_enter_dead(Service
*s
, bool success
, bool allow_restart
) {
426 (s
->restart
== SERVICE_RESTART_ALWAYS
||
427 (s
->restart
== SERVICE_RESTART_ON_SUCCESS
&& !s
->failure
))) {
429 if ((r
= unit_watch_timer(UNIT(s
), s
->restart_usec
, &s
->timer_watch
)) < 0)
432 service_set_state(s
, SERVICE_AUTO_RESTART
);
434 service_set_state(s
, s
->failure
? SERVICE_MAINTAINANCE
: SERVICE_DEAD
);
439 log_warning("%s failed to run install restart timer: %s", unit_id(UNIT(s
)), strerror(-r
));
440 service_enter_dead(s
, false, false);
443 static void service_enter_signal(Service
*s
, ServiceState state
, bool success
);
445 static void service_enter_stop_post(Service
*s
, bool success
) {
452 if ((s
->control_command
= s
->exec_command
[SERVICE_EXEC_STOP_POST
]))
453 if ((r
= service_spawn(s
, s
->control_command
, true, false, &s
->control_pid
)) < 0)
457 service_set_state(s
, SERVICE_STOP_POST
);
459 if (!s
->control_command
)
460 service_enter_dead(s
, true, true);
465 log_warning("%s failed to run stop executable: %s", unit_id(UNIT(s
)), strerror(-r
));
466 service_enter_signal(s
, SERVICE_FINAL_SIGTERM
, false);
469 static void service_enter_signal(Service
*s
, ServiceState state
, bool success
) {
478 if (s
->main_pid
> 0 || s
->control_pid
> 0) {
481 sig
= (state
== SERVICE_STOP_SIGTERM
|| state
== SERVICE_FINAL_SIGTERM
) ? SIGTERM
: SIGKILL
;
484 if (s
->main_pid
> 0) {
485 if (kill(s
->main_pid
, sig
) < 0 && errno
!= ESRCH
)
491 if (s
->control_pid
> 0) {
492 if (kill(s
->control_pid
, sig
) < 0 && errno
!= ESRCH
)
502 service_set_state(s
, state
);
504 if (s
->main_pid
<= 0 && s
->control_pid
<= 0)
505 service_enter_dead(s
, true, true);
510 log_warning("%s failed to kill processes: %s", unit_id(UNIT(s
)), strerror(-r
));
514 service_set_state(s
, state
);
515 } else if (state
== SERVICE_STOP_SIGTERM
|| state
== SERVICE_STOP_SIGKILL
)
516 service_enter_stop_post(s
, false);
518 service_enter_dead(s
, false, true);
521 static void service_enter_stop(Service
*s
, bool success
) {
528 if ((s
->control_command
= s
->exec_command
[SERVICE_EXEC_STOP
]))
529 if ((r
= service_spawn(s
, s
->control_command
, true, false, &s
->control_pid
)) < 0)
532 service_set_state(s
, SERVICE_STOP
);
534 if (!s
->control_command
)
535 service_enter_signal(s
, SERVICE_STOP_SIGTERM
, true);
540 log_warning("%s failed to run stop executable: %s", unit_id(UNIT(s
)), strerror(-r
));
541 service_enter_signal(s
, SERVICE_STOP_SIGTERM
, false);
544 static void service_enter_start_post(Service
*s
) {
548 if ((s
->control_command
= s
->exec_command
[SERVICE_EXEC_START_POST
]))
549 if ((r
= service_spawn(s
, s
->control_command
, true, false, &s
->control_pid
)) < 0)
553 service_set_state(s
, SERVICE_START_POST
);
555 if (!s
->control_command
)
556 service_set_state(s
, SERVICE_RUNNING
);
561 log_warning("%s failed to run start-post executable: %s", unit_id(UNIT(s
)), strerror(-r
));
562 service_enter_stop(s
, false);
565 static void service_enter_start(Service
*s
) {
571 assert(s
->exec_command
[SERVICE_EXEC_START
]);
572 assert(!s
->exec_command
[SERVICE_EXEC_START
]->command_next
);
574 if ((r
= service_spawn(s
, s
->exec_command
[SERVICE_EXEC_START
], s
->type
== SERVICE_FORKING
, true, &pid
)) < 0)
577 service_set_state(s
, SERVICE_START
);
579 if (s
->type
== SERVICE_SIMPLE
) {
580 /* For simple services we immediately start
581 * the START_POST binaries. */
584 s
->main_pid_known
= true;
585 service_enter_start_post(s
);
587 } else if (s
->type
== SERVICE_FORKING
) {
589 /* For forking services we wait until the start
592 s
->control_pid
= pid
;
593 s
->control_command
= s
->exec_command
[SERVICE_EXEC_START
];
594 } else if (s
->type
== SERVICE_FINISH
) {
596 /* For finishing services we wait until the start
597 * process exited, too, but it is our main process. */
600 s
->control_command
= s
->exec_command
[SERVICE_EXEC_START
];
602 assert_not_reached("Unknown service type");
607 log_warning("%s failed to run start exectuable: %s", unit_id(UNIT(s
)), strerror(-r
));
608 service_enter_stop(s
, false);
611 static void service_enter_start_pre(Service
*s
) {
616 if ((s
->control_command
= s
->exec_command
[SERVICE_EXEC_START_PRE
]))
617 if ((r
= service_spawn(s
, s
->control_command
, true, false, &s
->control_pid
)) < 0)
620 service_set_state(s
, SERVICE_START_PRE
);
622 if (!s
->control_command
)
623 service_enter_start(s
);
628 log_warning("%s failed to run start-pre executable: %s", unit_id(UNIT(s
)), strerror(-r
));
629 service_enter_dead(s
, false, true);
632 static void service_enter_restart(Service
*s
) {
636 if ((r
= manager_add_job(UNIT(s
)->meta
.manager
, JOB_START
, UNIT(s
), JOB_FAIL
, false, NULL
)) < 0)
639 log_debug("%s scheduled restart job.", unit_id(UNIT(s
)));
640 service_enter_dead(s
, true, false);
645 log_warning("%s failed to schedule restart job: %s", unit_id(UNIT(s
)), strerror(-r
));
646 service_enter_dead(s
, false, false);
649 static void service_enter_reload(Service
*s
) {
654 if ((s
->control_command
= s
->exec_command
[SERVICE_EXEC_RELOAD
]))
655 if ((r
= service_spawn(s
, s
->control_command
, true, false, &s
->control_pid
)) < 0)
658 service_set_state(s
, SERVICE_RELOAD
);
660 if (!s
->control_command
)
661 service_set_state(s
, SERVICE_RUNNING
);
666 log_warning("%s failed to run reload executable: %s", unit_id(UNIT(s
)), strerror(-r
));
667 service_enter_stop(s
, false);
670 static void service_run_next(Service
*s
, bool success
) {
674 assert(s
->control_command
);
675 assert(s
->control_command
->command_next
);
680 s
->control_command
= s
->control_command
->command_next
;
682 if ((r
= service_spawn(s
, s
->control_command
, true, false, &s
->control_pid
)) < 0)
688 log_warning("%s failed to run spawn next executable: %s", unit_id(UNIT(s
)), strerror(-r
));
690 if (s
->state
== SERVICE_STOP
)
691 service_enter_stop_post(s
, false);
692 else if (s
->state
== SERVICE_STOP_POST
)
693 service_enter_dead(s
, false, true);
695 service_enter_stop(s
, false);
698 static int service_start(Unit
*u
) {
699 Service
*s
= SERVICE(u
);
703 /* We cannot fulfill this request right now, try again later
705 if (s
->state
== SERVICE_STOP
||
706 s
->state
== SERVICE_STOP_SIGTERM
||
707 s
->state
== SERVICE_STOP_SIGKILL
||
708 s
->state
== SERVICE_STOP_POST
||
709 s
->state
== SERVICE_FINAL_SIGTERM
||
710 s
->state
== SERVICE_FINAL_SIGKILL
)
714 if (s
->state
== SERVICE_START_PRE
||
715 s
->state
== SERVICE_START
||
716 s
->state
== SERVICE_START_POST
)
719 assert(s
->state
== SERVICE_DEAD
|| s
->state
== SERVICE_MAINTAINANCE
|| s
->state
== SERVICE_AUTO_RESTART
);
721 /* Make sure we don't enter a busy loop of some kind. */
722 if (!ratelimit_test(&s
->ratelimit
)) {
723 log_warning("%s start request repeated too quickly, refusing to start.", unit_id(u
));
728 s
->main_pid_known
= false;
730 service_enter_start_pre(s
);
734 static int service_stop(Unit
*u
) {
735 Service
*s
= SERVICE(u
);
739 if (s
->state
== SERVICE_START_PRE
||
740 s
->state
== SERVICE_START
||
741 s
->state
== SERVICE_START_POST
||
742 s
->state
== SERVICE_RELOAD
)
745 if (s
->state
== SERVICE_AUTO_RESTART
) {
746 service_set_state(s
, SERVICE_DEAD
);
750 assert(s
->state
== SERVICE_RUNNING
);
752 service_enter_stop(s
, true);
756 static int service_reload(Unit
*u
) {
757 Service
*s
= SERVICE(u
);
761 assert(s
->state
== SERVICE_RUNNING
);
763 service_enter_reload(s
);
767 static bool service_can_reload(Unit
*u
) {
768 Service
*s
= SERVICE(u
);
772 return !!s
->exec_command
[SERVICE_EXEC_RELOAD
];
775 static UnitActiveState
service_active_state(Unit
*u
) {
778 return state_translation_table
[SERVICE(u
)->state
];
781 static int main_pid_good(Service
*s
) {
784 /* Returns 0 if the pid is dead, 1 if it is good, -1 if we
787 /* If we know the pid file, then lets just check if it is
789 if (s
->main_pid_known
)
790 return s
->main_pid
> 0;
792 /* We don't know the pid */
796 static bool control_pid_good(Service
*s
) {
799 return s
->control_pid
> 0;
802 static void service_sigchld_event(Unit
*u
, pid_t pid
, int code
, int status
) {
803 Service
*s
= SERVICE(u
);
809 success
= code
== CLD_EXITED
&& status
== 0;
810 s
->failure
= s
->failure
|| !success
;
812 if (s
->main_pid
== pid
) {
814 exec_status_fill(&s
->main_exec_status
, pid
, code
, status
);
817 if (s
->type
== SERVICE_SIMPLE
|| s
->type
== SERVICE_FINISH
) {
818 assert(s
->exec_command
[SERVICE_EXEC_START
]);
819 s
->exec_command
[SERVICE_EXEC_START
]->exec_status
= s
->main_exec_status
;
822 log_debug("%s: main process exited, code=%s status=%i", unit_id(u
), sigchld_code_to_string(code
), status
);
824 /* The service exited, so the service is officially
829 case SERVICE_START_POST
:
832 /* Need to wait until the operation is
837 assert(s
->type
== SERVICE_FINISH
);
839 /* This was our main goal, so let's go on */
841 service_enter_start_post(s
);
843 service_enter_stop(s
, false);
846 case SERVICE_RUNNING
:
847 service_enter_stop(s
, success
);
850 case SERVICE_STOP_SIGTERM
:
851 case SERVICE_STOP_SIGKILL
:
853 if (!control_pid_good(s
))
854 service_enter_stop_post(s
, success
);
856 /* If there is still a control process, wait for that first */
860 assert_not_reached("Uh, main process died at wrong time.");
863 } else if (s
->control_pid
== pid
) {
864 assert(s
->control_command
);
866 exec_status_fill(&s
->control_command
->exec_status
, pid
, code
, status
);
869 log_debug("%s: control process exited, code=%s status=%i", unit_id(u
), sigchld_code_to_string(code
), status
);
871 /* If we are shutting things down anyway we
872 * don't care about failing commands. */
874 if (s
->control_command
->command_next
&&
875 (success
|| (s
->state
== SERVICE_EXEC_STOP
|| s
->state
== SERVICE_EXEC_STOP_POST
)))
877 /* There is another command to *
878 * execute, so let's do that. */
880 service_run_next(s
, success
);
883 /* No further commands for this step, so let's
884 * figure out what to do next */
886 log_debug("%s got final SIGCHLD for state %s", unit_id(u
), service_state_to_string(s
->state
));
890 case SERVICE_START_PRE
:
892 service_enter_start(s
);
894 service_enter_stop(s
, false);
898 assert(s
->type
== SERVICE_FORKING
);
900 /* Let's try to load the pid
901 * file here if we can. We
902 * ignore the return value,
903 * since the PID file might
904 * actually be created by a
905 * START_POST script */
909 service_load_pid_file(s
);
911 service_enter_start_post(s
);
913 service_enter_stop(s
, false);
917 case SERVICE_START_POST
:
918 if (success
&& s
->pid_file
&& !s
->main_pid_known
) {
921 /* Hmm, let's see if we can
922 * load the pid now after the
923 * start-post scripts got
926 if ((r
= service_load_pid_file(s
)) < 0)
927 log_warning("%s: failed to load PID file %s: %s", unit_id(UNIT(s
)), s
->pid_file
, strerror(-r
));
934 if (main_pid_good(s
) != 0)
935 service_set_state(s
, SERVICE_RUNNING
);
937 service_enter_stop(s
, true);
939 service_enter_stop(s
, false);
944 if (main_pid_good(s
) > 0)
945 /* Still not dead and we know the PID? Let's go hunting. */
946 service_enter_signal(s
, SERVICE_STOP_SIGTERM
, success
);
948 service_enter_stop_post(s
, success
);
951 case SERVICE_STOP_SIGTERM
:
952 case SERVICE_STOP_SIGKILL
:
953 if (main_pid_good(s
) <= 0)
954 service_enter_stop_post(s
, success
);
956 /* If there is still a service
957 * process around, wait until
958 * that one quit, too */
961 case SERVICE_STOP_POST
:
962 case SERVICE_FINAL_SIGTERM
:
963 case SERVICE_FINAL_SIGKILL
:
964 service_enter_dead(s
, success
, true);
968 assert_not_reached("Uh, control process died at wrong time.");
972 assert_not_reached("Got SIGCHLD for unkown PID");
975 static void service_timer_event(Unit
*u
, uint64_t elapsed
, Watch
* w
) {
976 Service
*s
= SERVICE(u
);
979 assert(elapsed
== 1);
981 assert(w
== &s
->timer_watch
);
985 case SERVICE_START_PRE
:
987 case SERVICE_START_POST
:
989 log_warning("%s operation timed out. Stopping.", unit_id(u
));
990 service_enter_stop(s
, false);
994 log_warning("%s stopping timed out. Terminating.", unit_id(u
));
995 service_enter_signal(s
, SERVICE_STOP_SIGTERM
, false);
998 case SERVICE_STOP_SIGTERM
:
999 log_warning("%s stopping timed out. Killing.", unit_id(u
));
1000 service_enter_signal(s
, SERVICE_STOP_SIGKILL
, false);
1003 case SERVICE_STOP_SIGKILL
:
1004 /* Uh, wie sent a SIGKILL and it is still not gone?
1005 * Must be something we cannot kill, so let's just be
1006 * weirded out and continue */
1008 log_warning("%s still around after SIGKILL. Ignoring.", unit_id(u
));
1009 service_enter_stop_post(s
, false);
1012 case SERVICE_STOP_POST
:
1013 log_warning("%s stopping timed out (2). Terminating.", unit_id(u
));
1014 service_enter_signal(s
, SERVICE_FINAL_SIGTERM
, false);
1017 case SERVICE_FINAL_SIGTERM
:
1018 log_warning("%s stopping timed out (2). Killing.", unit_id(u
));
1019 service_enter_signal(s
, SERVICE_FINAL_SIGKILL
, false);
1022 case SERVICE_FINAL_SIGKILL
:
1023 log_warning("%s still around after SIGKILL (2). Entering maintainance mode.", unit_id(u
));
1024 service_enter_dead(s
, false, true);
1027 case SERVICE_AUTO_RESTART
:
1028 log_debug("%s holdoff time over, scheduling restart.", unit_id(u
));
1029 service_enter_restart(s
);
1033 assert_not_reached("Timeout at wrong time.");
1037 static const char* const service_state_table
[_SERVICE_STATE_MAX
] = {
1038 [SERVICE_DEAD
] = "dead",
1039 [SERVICE_START_PRE
] = "start-pre",
1040 [SERVICE_START
] = "start",
1041 [SERVICE_START_POST
] = "start-post",
1042 [SERVICE_RUNNING
] = "running",
1043 [SERVICE_RELOAD
] = "reload",
1044 [SERVICE_STOP
] = "stop",
1045 [SERVICE_STOP_SIGTERM
] = "stop-sigterm",
1046 [SERVICE_STOP_SIGKILL
] = "stop-sigkill",
1047 [SERVICE_STOP_POST
] = "stop-post",
1048 [SERVICE_FINAL_SIGTERM
] = "final-sigterm",
1049 [SERVICE_FINAL_SIGKILL
] = "final-sigkill",
1050 [SERVICE_MAINTAINANCE
] = "maintainance",
1051 [SERVICE_AUTO_RESTART
] = "auto-restart",
1054 DEFINE_STRING_TABLE_LOOKUP(service_state
, ServiceState
);
1056 static const char* const service_restart_table
[_SERVICE_RESTART_MAX
] = {
1057 [SERVICE_ONCE
] = "once",
1058 [SERVICE_RESTART_ON_SUCCESS
] = "restart-on-success",
1059 [SERVICE_RESTART_ALWAYS
] = "restart-on-failure",
1062 DEFINE_STRING_TABLE_LOOKUP(service_restart
, ServiceRestart
);
1064 static const char* const service_type_table
[_SERVICE_TYPE_MAX
] = {
1065 [SERVICE_FORKING
] = "forking",
1066 [SERVICE_SIMPLE
] = "simple",
1067 [SERVICE_FINISH
] = "finish"
1070 DEFINE_STRING_TABLE_LOOKUP(service_type
, ServiceType
);
1072 static const char* const service_exec_command_table
[_SERVICE_EXEC_MAX
] = {
1073 [SERVICE_EXEC_START_PRE
] = "ExecStartPre",
1074 [SERVICE_EXEC_START
] = "ExecStart",
1075 [SERVICE_EXEC_START_POST
] = "ExecStartPost",
1076 [SERVICE_EXEC_RELOAD
] = "ExecReload",
1077 [SERVICE_EXEC_STOP
] = "ExecStop",
1078 [SERVICE_EXEC_STOP_POST
] = "ExecStopPost",
1081 DEFINE_STRING_TABLE_LOOKUP(service_exec_command
, ServiceExecCommand
);
1083 const UnitVTable service_vtable
= {
1084 .suffix
= ".service",
1086 .init
= service_init
,
1087 .done
= service_done
,
1089 .dump
= service_dump
,
1091 .start
= service_start
,
1092 .stop
= service_stop
,
1093 .reload
= service_reload
,
1095 .can_reload
= service_can_reload
,
1097 .active_state
= service_active_state
,
1099 .sigchld_event
= service_sigchld_event
,
1100 .timer_event
= service_timer_event
,