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"
34 #define COMMENTS "#;\n"
35 #define NEWLINES "\n\r"
38 static const char * const rcnd_table
[] = {
39 "/rc0.d", SPECIAL_RUNLEVEL0_TARGET
,
40 "/rc1.d", SPECIAL_RUNLEVEL1_TARGET
,
41 "/rc2.d", SPECIAL_RUNLEVEL2_TARGET
,
42 "/rc3.d", SPECIAL_RUNLEVEL3_TARGET
,
43 "/rc4.d", SPECIAL_RUNLEVEL4_TARGET
,
44 "/rc5.d", SPECIAL_RUNLEVEL5_TARGET
,
45 "/rc6.d", SPECIAL_RUNLEVEL6_TARGET
,
46 "/boot.d", SPECIAL_BASIC_TARGET
49 static const UnitActiveState state_translation_table
[_SERVICE_STATE_MAX
] = {
50 [SERVICE_DEAD
] = UNIT_INACTIVE
,
51 [SERVICE_START_PRE
] = UNIT_ACTIVATING
,
52 [SERVICE_START
] = UNIT_ACTIVATING
,
53 [SERVICE_START_POST
] = UNIT_ACTIVATING
,
54 [SERVICE_RUNNING
] = UNIT_ACTIVE
,
55 [SERVICE_EXITED
] = UNIT_ACTIVE
,
56 [SERVICE_RELOAD
] = UNIT_ACTIVE_RELOADING
,
57 [SERVICE_STOP
] = UNIT_DEACTIVATING
,
58 [SERVICE_STOP_SIGTERM
] = UNIT_DEACTIVATING
,
59 [SERVICE_STOP_SIGKILL
] = UNIT_DEACTIVATING
,
60 [SERVICE_STOP_POST
] = UNIT_DEACTIVATING
,
61 [SERVICE_FINAL_SIGTERM
] = UNIT_DEACTIVATING
,
62 [SERVICE_FINAL_SIGKILL
] = UNIT_DEACTIVATING
,
63 [SERVICE_MAINTAINANCE
] = UNIT_INACTIVE
,
64 [SERVICE_AUTO_RESTART
] = UNIT_ACTIVATING
,
67 static void service_unwatch_control_pid(Service
*s
) {
70 if (s
->control_pid
<= 0)
73 unit_unwatch_pid(UNIT(s
), s
->control_pid
);
77 static void service_unwatch_main_pid(Service
*s
) {
83 unit_unwatch_pid(UNIT(s
), s
->main_pid
);
87 static void service_done(Unit
*u
) {
88 Service
*s
= SERVICE(u
);
98 free(s
->sysv_runlevels
);
99 s
->sysv_runlevels
= NULL
;
101 exec_context_done(&s
->exec_context
);
102 exec_command_free_array(s
->exec_command
, _SERVICE_EXEC_COMMAND_MAX
);
103 s
->control_command
= NULL
;
105 /* This will leak a process, but at least no memory or any of
107 service_unwatch_main_pid(s
);
108 service_unwatch_control_pid(s
);
110 unit_unwatch_timer(u
, &s
->timer_watch
);
113 static int sysv_translate_name(const char *name
, char **_r
) {
115 static const char * const table
[] = {
116 "$local_fs", SPECIAL_LOCAL_FS_TARGET
,
117 "$network", SPECIAL_NETWORK_TARGET
,
118 "$named", SPECIAL_NSS_LOOKUP_TARGET
,
119 "$portmap", SPECIAL_RPCBIND_TARGET
,
120 "$remote_fs", SPECIAL_REMOTE_FS_TARGET
,
121 "$syslog", SPECIAL_SYSLOG_TARGET
,
122 "$time", SPECIAL_RTC_SET_TARGET
128 for (i
= 0; i
< ELEMENTSOF(table
); i
+= 2)
129 if (streq(table
[i
], name
)) {
130 if (!(r
= strdup(table
[i
+1])))
139 if (asprintf(&r
, "%s.service", name
) < 0)
150 static int sysv_chkconfig_order(Service
*s
) {
156 if (s
->sysv_start_priority
< 0)
159 /* For each pair of services where at least one lacks a LSB
160 * header, we use the start priority value to order things. */
162 LIST_FOREACH(units_per_type
, other
, UNIT(s
)->meta
.manager
->units_per_type
[UNIT_SERVICE
]) {
166 t
= (Service
*) other
;
171 if (t
->sysv_start_priority
< 0)
174 /* If both units have modern headers we don't care
175 * about the priorities */
176 if ((!s
->sysv_path
|| s
->sysv_has_lsb
) &&
177 (!t
->sysv_path
|| t
->sysv_has_lsb
))
180 if (t
->sysv_start_priority
< s
->sysv_start_priority
)
182 else if (t
->sysv_start_priority
> s
->sysv_start_priority
)
187 /* FIXME: Maybe we should compare the name here lexicographically? */
189 if (!(r
= unit_add_dependency(UNIT(s
), d
, UNIT(t
))) < 0)
196 static ExecCommand
*exec_command_new(const char *path
, const char *arg1
) {
199 if (!(c
= new0(ExecCommand
, 1)))
202 if (!(c
->path
= strdup(path
))) {
207 if (!(c
->argv
= strv_new(path
, arg1
, NULL
))) {
216 static int sysv_exec_commands(Service
*s
) {
220 assert(s
->sysv_path
);
222 if (!(c
= exec_command_new(s
->sysv_path
, "start")))
224 exec_command_append_list(s
->exec_command
+SERVICE_EXEC_START
, c
);
226 if (!(c
= exec_command_new(s
->sysv_path
, "stop")))
228 exec_command_append_list(s
->exec_command
+SERVICE_EXEC_STOP
, c
);
230 if (!(c
= exec_command_new(s
->sysv_path
, "reload")))
232 exec_command_append_list(s
->exec_command
+SERVICE_EXEC_RELOAD
, c
);
237 static int priority_from_rcd(Service
*s
, const char *init_script
) {
241 STRV_FOREACH(p
, UNIT(s
)->meta
.manager
->sysvrcnd_path
)
242 for (i
= 0; i
< ELEMENTSOF(rcnd_table
); i
+= 2) {
247 if (asprintf(&path
, "%s/%s", *p
, rcnd_table
[i
]) < 0)
255 log_warning("opendir() failed on %s: %s", path
, strerror(errno
));
260 while ((de
= readdir(d
))) {
263 if (ignore_file(de
->d_name
))
266 if (de
->d_name
[0] != 'S')
269 if (strlen(de
->d_name
) < 4)
272 if (!streq(de
->d_name
+ 3, init_script
))
275 /* Yay, we found it! Now decode the priority */
277 a
= undecchar(de
->d_name
[1]);
278 b
= undecchar(de
->d_name
[2]);
283 s
->sysv_start_priority
= a
*10 + b
;
285 log_debug("Determined priority %i from link farm for %s", s
->sysv_start_priority
, unit_id(UNIT(s
)));
297 static int service_load_sysv_path(Service
*s
, const char *path
) {
314 if (!(f
= fopen(path
, "re"))) {
315 r
= errno
== ENOENT
? 0 : -errno
;
319 s
->type
= SERVICE_FORKING
;
320 s
->restart
= SERVICE_ONCE
;
323 if (!(s
->sysv_path
= strdup(path
))) {
329 char l
[LINE_MAX
], *t
;
331 if (!fgets(l
, sizeof(l
), f
)) {
336 log_error("Failed to read configuration file '%s': %s", path
, strerror(-r
));
346 if (state
== NORMAL
&& streq(t
, "### BEGIN INIT INFO")) {
348 s
->sysv_has_lsb
= true;
352 if ((state
== LSB_DESCRIPTION
|| state
== LSB
) && streq(t
, "### END INIT INFO")) {
358 t
+= strspn(t
, WHITESPACE
);
360 if (state
== NORMAL
) {
362 /* Try to parse Red Hat style chkconfig headers */
364 if (startswith(t
, "chkconfig:")) {
366 char runlevels
[16], *k
;
370 if (sscanf(t
+10, "%15s %i %*i",
372 &start_priority
) != 2) {
374 log_warning("[%s:%u] Failed to parse chkconfig line. Ignoring.", path
, line
);
378 if (start_priority
< 0 || start_priority
> 99)
379 log_warning("[%s:%u] Start priority out of range. Ignoring.", path
, line
);
381 s
->sysv_start_priority
= start_priority
;
383 char_array_0(runlevels
);
384 k
= delete_chars(runlevels
, WHITESPACE
"-");
389 if (!(d
= strdup(k
))) {
394 free(s
->sysv_runlevels
);
395 s
->sysv_runlevels
= d
;
399 } else if (startswith(t
, "description:")) {
401 size_t k
= strlen(t
);
404 if (t
[k
-1] == '\\') {
409 if (!(d
= strdup(strstrip(t
+12)))) {
414 free(u
->meta
.description
);
415 u
->meta
.description
= d
;
417 } else if (startswith(t
, "pidfile:")) {
424 if (!path_is_absolute(fn
)) {
425 log_warning("[%s:%u] PID file not absolute. Ignoring.", path
, line
);
429 if (!(fn
= strdup(fn
))) {
438 } else if (state
== DESCRIPTION
) {
440 /* Try to parse Red Hat style description
443 size_t k
= strlen(t
);
451 assert(u
->meta
.description
);
452 if (asprintf(&d
, "%s %s", u
->meta
.description
, strstrip(t
)) < 0) {
457 free(u
->meta
.description
);
458 u
->meta
.description
= d
;
460 } else if (state
== LSB
|| state
== LSB_DESCRIPTION
) {
462 if (startswith(t
, "Provides:")) {
468 FOREACH_WORD(w
, z
, t
+9, i
) {
471 if (!(n
= strndup(w
, z
))) {
476 r
= sysv_translate_name(n
, &m
);
485 if (unit_name_to_type(m
) == UNIT_SERVICE
)
486 r
= unit_add_name(u
, m
);
488 if ((r
= unit_add_dependency_by_name_inverse(u
, UNIT_REQUIRES
, m
)) >= 0)
489 r
= unit_add_dependency_by_name(u
, UNIT_BEFORE
, m
);
498 } else if (startswith(t
, "Required-Start:") ||
499 startswith(t
, "Should-Start:")) {
505 FOREACH_WORD(w
, z
, strchr(t
, ':')+1, i
) {
508 if (!(n
= strndup(w
, z
))) {
513 r
= sysv_translate_name(n
, &m
);
522 r
= unit_add_dependency_by_name(u
, UNIT_AFTER
, m
);
528 } else if (startswith(t
, "Default-Start:")) {
533 k
= delete_chars(t
+14, WHITESPACE
"-");
536 if (!(d
= strdup(k
))) {
541 free(s
->sysv_runlevels
);
542 s
->sysv_runlevels
= d
;
545 } else if (startswith(t
, "Description:")) {
548 state
= LSB_DESCRIPTION
;
550 if (!(d
= strdup(strstrip(t
+12)))) {
555 free(u
->meta
.description
);
556 u
->meta
.description
= d
;
558 } else if (startswith(t
, "Short-Description:") &&
559 !u
->meta
.description
) {
562 /* We use the short description only
563 * if no long description is set. */
567 if (!(d
= strdup(strstrip(t
+18)))) {
572 u
->meta
.description
= d
;
574 } else if (state
== LSB_DESCRIPTION
) {
576 if (startswith(l
, "#\t") || startswith(l
, "# ")) {
579 assert(u
->meta
.description
);
580 if (asprintf(&d
, "%s %s", u
->meta
.description
, t
) < 0) {
585 free(u
->meta
.description
);
586 u
->meta
.description
= d
;
593 /* If init scripts have no LSB header, then we enforce the
594 * ordering via the chkconfig priorities. We try to determine
595 * a priority for *all* init scripts here, since they are
596 * needed as soon as at least one non-LSB script is used. */
598 if (s
->sysv_start_priority
< 0) {
599 log_debug("%s has no chkconfig header, trying to determine SysV priority from link farm.", unit_id(u
));
601 if ((r
= priority_from_rcd(s
, file_name_from_path(path
))) < 0)
604 if (s
->sysv_start_priority
< 0)
605 log_warning("%s has neither a chkconfig header nor a directory link, cannot order unit!", unit_id(u
));
608 if ((r
= sysv_exec_commands(s
)) < 0)
611 if (!s
->sysv_runlevels
|| chars_intersect("12345", s
->sysv_runlevels
)) {
612 /* If there a runlevels configured for this service
613 * but none of the standard ones, then we assume this
614 * is some special kind of service (which might be
615 * needed for early boot) and don't create any links
618 if ((r
= unit_add_dependency_by_name(u
, UNIT_REQUIRES
, SPECIAL_BASIC_TARGET
)) < 0 ||
619 (r
= unit_add_dependency_by_name(u
, UNIT_AFTER
, SPECIAL_BASIC_TARGET
)) < 0)
623 /* Special setting for all SysV services */
624 s
->valid_no_process
= true;
626 /* Don't timeout special services during boot (like fsck) */
627 if (s
->sysv_runlevels
&& !chars_intersect("12345", s
->sysv_runlevels
))
628 s
->timeout_usec
= -1;
630 u
->meta
.load_state
= UNIT_LOADED
;
641 static int service_load_sysv_name(Service
*s
, const char *name
) {
647 STRV_FOREACH(p
, UNIT(s
)->meta
.manager
->sysvinit_path
) {
651 if (asprintf(&path
, "%s/%s", *p
, name
) < 0)
654 assert(endswith(path
, ".service"));
655 path
[strlen(path
)-8] = 0;
657 r
= service_load_sysv_path(s
, path
);
663 if ((UNIT(s
)->meta
.load_state
!= UNIT_STUB
))
670 static int service_load_sysv(Service
*s
) {
677 /* Load service data from SysV init scripts, preferably with
680 if (strv_isempty(UNIT(s
)->meta
.manager
->sysvinit_path
))
683 if ((t
= unit_id(UNIT(s
))))
684 if ((r
= service_load_sysv_name(s
, t
)) < 0)
687 if (UNIT(s
)->meta
.load_state
== UNIT_STUB
)
688 SET_FOREACH(t
, UNIT(s
)->meta
.names
, i
) {
689 if (t
== unit_id(UNIT(s
)))
692 if ((r
== service_load_sysv_name(s
, t
)) < 0)
695 if (UNIT(s
)->meta
.load_state
!= UNIT_STUB
)
702 static void service_init(Unit
*u
) {
703 Service
*s
= SERVICE(u
);
706 assert(u
->meta
.load_state
== UNIT_STUB
);
711 s
->timeout_usec
= DEFAULT_TIMEOUT_USEC
;
712 s
->restart_usec
= DEFAULT_RESTART_USEC
;
714 exec_context_init(&s
->exec_context
);
716 s
->timer_watch
.type
= WATCH_INVALID
;
718 s
->state
= SERVICE_DEAD
;
720 s
->sysv_start_priority
= -1;
721 s
->permissions_start_only
= false;
722 s
->root_directory_start_only
= false;
723 s
->valid_no_process
= false;
725 s
->sysv_has_lsb
= false;
726 s
->main_pid
= s
->control_pid
= 0;
727 s
->main_pid_known
= false;
730 RATELIMIT_INIT(s
->ratelimit
, 10*USEC_PER_SEC
, 5);
733 static int service_verify(Service
*s
) {
736 if (UNIT(s
)->meta
.load_state
!= UNIT_LOADED
)
739 if (!s
->exec_command
[SERVICE_EXEC_START
]) {
740 log_error("%s lacks ExecStart setting. Refusing.", unit_id(UNIT(s
)));
747 static int service_load(Unit
*u
) {
749 Service
*s
= SERVICE(u
);
753 /* Load a .service file */
754 if ((r
= unit_load_fragment(u
)) < 0)
757 /* Load a classic init script as a fallback, if we couldn't find anything */
758 if (u
->meta
.load_state
== UNIT_STUB
)
759 if ((r
= service_load_sysv(s
)) < 0)
762 /* Still nothing found? Then let's give up */
763 if (u
->meta
.load_state
== UNIT_STUB
)
766 /* We were able to load something, then let's add in the
767 * dropin directories. */
768 if ((r
= unit_load_dropin(unit_follow_merge(u
))) < 0)
771 /* This is a new unit? Then let's add in some extras */
772 if (u
->meta
.load_state
== UNIT_LOADED
) {
773 if ((r
= unit_add_exec_dependencies(u
, &s
->exec_context
)) < 0)
776 if ((r
= unit_add_default_cgroup(u
)) < 0)
779 if ((r
= sysv_chkconfig_order(s
)) < 0)
783 return service_verify(s
);
786 static void service_dump(Unit
*u
, FILE *f
, const char *prefix
) {
788 ServiceExecCommand c
;
789 Service
*s
= SERVICE(u
);
795 p2
= strappend(prefix
, "\t");
796 prefix2
= p2
? p2
: prefix
;
799 "%sService State: %s\n"
800 "%sPermissionsStartOnly: %s\n"
801 "%sRootDirectoryStartOnly: %s\n"
802 "%sValidNoProcess: %s\n"
805 prefix
, service_state_to_string(s
->state
),
806 prefix
, yes_no(s
->permissions_start_only
),
807 prefix
, yes_no(s
->root_directory_start_only
),
808 prefix
, yes_no(s
->valid_no_process
),
809 prefix
, kill_mode_to_string(s
->kill_mode
),
810 prefix
, service_type_to_string(s
->type
));
812 if (s
->control_pid
> 0)
814 "%sControl PID: %llu\n",
815 prefix
, (unsigned long long) s
->control_pid
);
819 "%sMain PID: %llu\n",
820 prefix
, (unsigned long long) s
->main_pid
);
825 prefix
, s
->pid_file
);
827 exec_context_dump(&s
->exec_context
, f
, prefix
);
829 for (c
= 0; c
< _SERVICE_EXEC_COMMAND_MAX
; c
++) {
831 if (!s
->exec_command
[c
])
834 fprintf(f
, "%s→ %s:\n",
835 prefix
, service_exec_command_to_string(c
));
837 exec_command_dump_list(s
->exec_command
[c
], f
, prefix2
);
842 "%sSysV Init Script Path: %s\n"
843 "%sSysV Init Script has LSB Header: %s\n",
844 prefix
, s
->sysv_path
,
845 prefix
, yes_no(s
->sysv_has_lsb
));
847 if (s
->sysv_start_priority
>= 0)
849 "%sSysVStartPriority: %i\n",
850 prefix
, s
->sysv_start_priority
);
852 if (s
->sysv_runlevels
)
853 fprintf(f
, "%sSysVRunLevels: %s\n",
854 prefix
, s
->sysv_runlevels
);
859 static int service_load_pid_file(Service
*s
) {
866 if (s
->main_pid_known
)
869 assert(s
->main_pid
<= 0);
874 if ((r
= read_one_line_file(s
->pid_file
, &k
)) < 0)
877 if ((r
= safe_atolu(k
, &p
)) < 0) {
882 if ((unsigned long) (pid_t
) p
!= p
)
885 if (kill((pid_t
) p
, 0) < 0 && errno
!= EPERM
) {
886 log_warning("PID %llu read from file %s does not exist. Your service or init script might be broken.",
887 (unsigned long long) p
, s
->pid_file
);
891 if ((r
= unit_watch_pid(UNIT(s
), (pid_t
) p
)) < 0)
892 /* FIXME: we need to do something here */
895 s
->main_pid
= (pid_t
) p
;
896 s
->main_pid_known
= true;
901 static int service_get_sockets(Service
*s
, Set
**_set
) {
910 /* Collects all Socket objects that belong to this
911 * service. Note that a service might have multiple sockets
912 * via multiple names. */
914 if (!(set
= set_new(NULL
, NULL
)))
917 SET_FOREACH(t
, UNIT(s
)->meta
.names
, i
) {
921 /* Look for all socket objects that go by any of our
922 * units and collect their fds */
924 if (!(k
= unit_name_change_suffix(t
, ".socket"))) {
929 p
= manager_get_unit(UNIT(s
)->meta
.manager
, k
);
934 if ((r
= set_put(set
, p
)) < 0)
947 static int service_notify_sockets_dead(Service
*s
) {
955 /* Notifies all our sockets when we die */
957 if ((r
= service_get_sockets(s
, &set
)) < 0)
960 SET_FOREACH(sock
, set
, i
)
961 socket_notify_service_dead(sock
);
968 static void service_set_state(Service
*s
, ServiceState state
) {
969 ServiceState old_state
;
972 old_state
= s
->state
;
975 if (state
!= SERVICE_START_PRE
&&
976 state
!= SERVICE_START
&&
977 state
!= SERVICE_START_POST
&&
978 state
!= SERVICE_RELOAD
&&
979 state
!= SERVICE_STOP
&&
980 state
!= SERVICE_STOP_SIGTERM
&&
981 state
!= SERVICE_STOP_SIGKILL
&&
982 state
!= SERVICE_STOP_POST
&&
983 state
!= SERVICE_FINAL_SIGTERM
&&
984 state
!= SERVICE_FINAL_SIGKILL
&&
985 state
!= SERVICE_AUTO_RESTART
)
986 unit_unwatch_timer(UNIT(s
), &s
->timer_watch
);
988 if (state
!= SERVICE_START
&&
989 state
!= SERVICE_START_POST
&&
990 state
!= SERVICE_RUNNING
&&
991 state
!= SERVICE_RELOAD
&&
992 state
!= SERVICE_STOP
&&
993 state
!= SERVICE_STOP_SIGTERM
&&
994 state
!= SERVICE_STOP_SIGKILL
)
995 service_unwatch_main_pid(s
);
997 if (state
!= SERVICE_START_PRE
&&
998 state
!= SERVICE_START
&&
999 state
!= SERVICE_START_POST
&&
1000 state
!= SERVICE_RELOAD
&&
1001 state
!= SERVICE_STOP
&&
1002 state
!= SERVICE_STOP_SIGTERM
&&
1003 state
!= SERVICE_STOP_SIGKILL
&&
1004 state
!= SERVICE_STOP_POST
&&
1005 state
!= SERVICE_FINAL_SIGTERM
&&
1006 state
!= SERVICE_FINAL_SIGKILL
) {
1007 service_unwatch_control_pid(s
);
1008 s
->control_command
= NULL
;
1011 if (state
== SERVICE_DEAD
||
1012 state
== SERVICE_STOP
||
1013 state
== SERVICE_STOP_SIGTERM
||
1014 state
== SERVICE_STOP_SIGKILL
||
1015 state
== SERVICE_STOP_POST
||
1016 state
== SERVICE_FINAL_SIGTERM
||
1017 state
== SERVICE_FINAL_SIGKILL
||
1018 state
== SERVICE_MAINTAINANCE
||
1019 state
== SERVICE_AUTO_RESTART
)
1020 service_notify_sockets_dead(s
);
1022 if (old_state
!= state
)
1023 log_debug("%s changed %s → %s", unit_id(UNIT(s
)), service_state_to_string(old_state
), service_state_to_string(state
));
1025 unit_notify(UNIT(s
), state_translation_table
[old_state
], state_translation_table
[state
]);
1028 static int service_collect_fds(Service
*s
, int **fds
, unsigned *n_fds
) {
1032 unsigned rn_fds
= 0;
1040 if ((r
= service_get_sockets(s
, &set
)) < 0)
1043 SET_FOREACH(sock
, set
, i
) {
1047 if ((r
= socket_collect_fds(sock
, &cfds
, &cn_fds
)) < 0)
1059 if (!(t
= new(int, rn_fds
+cn_fds
))) {
1065 memcpy(t
, rfds
, rn_fds
);
1066 memcpy(t
+rn_fds
, cfds
, cn_fds
);
1071 rn_fds
= rn_fds
+cn_fds
;
1089 static int service_spawn(
1094 bool apply_permissions
,
1108 if ((r
= service_collect_fds(s
, &fds
, &n_fds
)) < 0)
1112 if ((r
= unit_watch_timer(UNIT(s
), s
->timeout_usec
, &s
->timer_watch
)) < 0)
1115 unit_unwatch_timer(UNIT(s
), &s
->timer_watch
);
1117 if ((r
= exec_spawn(c
,
1122 UNIT(s
)->meta
.manager
->confirm_spawn
,
1123 UNIT(s
)->meta
.cgroup_bondings
,
1127 if ((r
= unit_watch_pid(UNIT(s
), pid
)) < 0)
1128 /* FIXME: we need to do something here */
1140 unit_unwatch_timer(UNIT(s
), &s
->timer_watch
);
1145 static int main_pid_good(Service
*s
) {
1148 /* Returns 0 if the pid is dead, 1 if it is good, -1 if we
1151 /* If we know the pid file, then lets just check if it is
1153 if (s
->main_pid_known
)
1154 return s
->main_pid
> 0;
1156 /* We don't know the pid */
1160 static int control_pid_good(Service
*s
) {
1163 return s
->control_pid
> 0;
1166 static int cgroup_good(Service
*s
) {
1171 if (s
->valid_no_process
)
1174 if ((r
= cgroup_bonding_is_empty_list(UNIT(s
)->meta
.cgroup_bondings
)) < 0)
1180 static void service_enter_dead(Service
*s
, bool success
, bool allow_restart
) {
1187 if (allow_restart
&&
1188 (s
->restart
== SERVICE_RESTART_ALWAYS
||
1189 (s
->restart
== SERVICE_RESTART_ON_SUCCESS
&& !s
->failure
))) {
1191 if ((r
= unit_watch_timer(UNIT(s
), s
->restart_usec
, &s
->timer_watch
)) < 0)
1194 service_set_state(s
, SERVICE_AUTO_RESTART
);
1196 service_set_state(s
, s
->failure
? SERVICE_MAINTAINANCE
: SERVICE_DEAD
);
1201 log_warning("%s failed to run install restart timer: %s", unit_id(UNIT(s
)), strerror(-r
));
1202 service_enter_dead(s
, false, false);
1205 static void service_enter_signal(Service
*s
, ServiceState state
, bool success
);
1207 static void service_enter_stop_post(Service
*s
, bool success
) {
1214 service_unwatch_control_pid(s
);
1216 if ((s
->control_command
= s
->exec_command
[SERVICE_EXEC_STOP_POST
])) {
1217 if ((r
= service_spawn(s
,
1221 !s
->permissions_start_only
,
1222 !s
->root_directory_start_only
,
1223 &s
->control_pid
)) < 0)
1227 service_set_state(s
, SERVICE_STOP_POST
);
1229 service_enter_signal(s
, SERVICE_FINAL_SIGTERM
, true);
1234 log_warning("%s failed to run stop-post executable: %s", unit_id(UNIT(s
)), strerror(-r
));
1235 service_enter_signal(s
, SERVICE_FINAL_SIGTERM
, false);
1238 static void service_enter_signal(Service
*s
, ServiceState state
, bool success
) {
1247 if (s
->kill_mode
!= KILL_NONE
) {
1248 int sig
= (state
== SERVICE_STOP_SIGTERM
|| state
== SERVICE_FINAL_SIGTERM
) ? SIGTERM
: SIGKILL
;
1250 if (s
->kill_mode
== KILL_CONTROL_GROUP
) {
1252 if ((r
= cgroup_bonding_kill_list(UNIT(s
)->meta
.cgroup_bondings
, sig
)) < 0) {
1253 if (r
!= -EAGAIN
&& r
!= -ESRCH
)
1262 if (s
->main_pid
> 0) {
1263 if (kill(s
->kill_mode
== KILL_PROCESS
? s
->main_pid
: -s
->main_pid
, sig
) < 0 && errno
!= ESRCH
)
1269 if (s
->control_pid
> 0) {
1270 if (kill(s
->kill_mode
== KILL_PROCESS
? s
->control_pid
: -s
->control_pid
, sig
) < 0 && errno
!= ESRCH
)
1282 if ((r
= unit_watch_timer(UNIT(s
), s
->timeout_usec
, &s
->timer_watch
)) < 0)
1285 service_set_state(s
, state
);
1286 } else if (state
== SERVICE_STOP_SIGTERM
|| state
== SERVICE_STOP_SIGKILL
)
1287 service_enter_stop_post(s
, true);
1289 service_enter_dead(s
, true, true);
1294 log_warning("%s failed to kill processes: %s", unit_id(UNIT(s
)), strerror(-r
));
1296 if (state
== SERVICE_STOP_SIGTERM
|| state
== SERVICE_STOP_SIGKILL
)
1297 service_enter_stop_post(s
, false);
1299 service_enter_dead(s
, false, true);
1302 static void service_enter_stop(Service
*s
, bool success
) {
1309 service_unwatch_control_pid(s
);
1311 if ((s
->control_command
= s
->exec_command
[SERVICE_EXEC_STOP
])) {
1312 if ((r
= service_spawn(s
,
1316 !s
->permissions_start_only
,
1317 !s
->root_directory_start_only
,
1318 &s
->control_pid
)) < 0)
1321 service_set_state(s
, SERVICE_STOP
);
1323 service_enter_signal(s
, SERVICE_STOP_SIGTERM
, true);
1328 log_warning("%s failed to run stop executable: %s", unit_id(UNIT(s
)), strerror(-r
));
1329 service_enter_signal(s
, SERVICE_STOP_SIGTERM
, false);
1332 static void service_enter_running(Service
*s
, bool success
) {
1338 if (main_pid_good(s
) != 0 && cgroup_good(s
) != 0)
1339 service_set_state(s
, SERVICE_RUNNING
);
1340 else if (s
->valid_no_process
)
1341 service_set_state(s
, SERVICE_EXITED
);
1343 service_enter_stop(s
, true);
1346 static void service_enter_start_post(Service
*s
) {
1350 service_unwatch_control_pid(s
);
1352 if ((s
->control_command
= s
->exec_command
[SERVICE_EXEC_START_POST
])) {
1353 if ((r
= service_spawn(s
,
1357 !s
->permissions_start_only
,
1358 !s
->root_directory_start_only
,
1359 &s
->control_pid
)) < 0)
1363 service_set_state(s
, SERVICE_START_POST
);
1365 service_enter_running(s
, true);
1370 log_warning("%s failed to run start-post executable: %s", unit_id(UNIT(s
)), strerror(-r
));
1371 service_enter_stop(s
, false);
1374 static void service_enter_start(Service
*s
) {
1380 assert(s
->exec_command
[SERVICE_EXEC_START
]);
1381 assert(!s
->exec_command
[SERVICE_EXEC_START
]->command_next
);
1383 if (s
->type
== SERVICE_FORKING
)
1384 service_unwatch_control_pid(s
);
1386 service_unwatch_main_pid(s
);
1388 if ((r
= service_spawn(s
,
1389 s
->exec_command
[SERVICE_EXEC_START
],
1390 s
->type
== SERVICE_FORKING
,
1397 if (s
->type
== SERVICE_SIMPLE
) {
1398 /* For simple services we immediately start
1399 * the START_POST binaries. */
1402 s
->main_pid_known
= true;
1404 service_enter_start_post(s
);
1406 } else if (s
->type
== SERVICE_FORKING
) {
1408 /* For forking services we wait until the start
1409 * process exited. */
1411 s
->control_pid
= pid
;
1413 s
->control_command
= s
->exec_command
[SERVICE_EXEC_START
];
1414 service_set_state(s
, SERVICE_START
);
1416 } else if (s
->type
== SERVICE_FINISH
) {
1418 /* For finishing services we wait until the start
1419 * process exited, too, but it is our main process. */
1422 s
->main_pid_known
= true;
1424 s
->control_command
= s
->exec_command
[SERVICE_EXEC_START
];
1425 service_set_state(s
, SERVICE_START
);
1427 assert_not_reached("Unknown service type");
1432 log_warning("%s failed to run start exectuable: %s", unit_id(UNIT(s
)), strerror(-r
));
1433 service_enter_signal(s
, SERVICE_FINAL_SIGTERM
, false);
1436 static void service_enter_start_pre(Service
*s
) {
1441 service_unwatch_control_pid(s
);
1443 if ((s
->control_command
= s
->exec_command
[SERVICE_EXEC_START_PRE
])) {
1444 if ((r
= service_spawn(s
,
1448 !s
->permissions_start_only
,
1449 !s
->root_directory_start_only
,
1450 &s
->control_pid
)) < 0)
1453 service_set_state(s
, SERVICE_START_PRE
);
1455 service_enter_start(s
);
1460 log_warning("%s failed to run start-pre executable: %s", unit_id(UNIT(s
)), strerror(-r
));
1461 service_enter_dead(s
, false, true);
1464 static void service_enter_restart(Service
*s
) {
1468 service_enter_dead(s
, true, false);
1470 if ((r
= manager_add_job(UNIT(s
)->meta
.manager
, JOB_START
, UNIT(s
), JOB_FAIL
, false, NULL
)) < 0)
1473 log_debug("%s scheduled restart job.", unit_id(UNIT(s
)));
1478 log_warning("%s failed to schedule restart job: %s", unit_id(UNIT(s
)), strerror(-r
));
1479 service_enter_dead(s
, false, false);
1482 static void service_enter_reload(Service
*s
) {
1487 service_unwatch_control_pid(s
);
1489 if ((s
->control_command
= s
->exec_command
[SERVICE_EXEC_RELOAD
])) {
1490 if ((r
= service_spawn(s
,
1494 !s
->permissions_start_only
,
1495 !s
->root_directory_start_only
,
1496 &s
->control_pid
)) < 0)
1499 service_set_state(s
, SERVICE_RELOAD
);
1501 service_enter_running(s
, true);
1506 log_warning("%s failed to run reload executable: %s", unit_id(UNIT(s
)), strerror(-r
));
1507 service_enter_stop(s
, false);
1510 static void service_run_next(Service
*s
, bool success
) {
1514 assert(s
->control_command
);
1515 assert(s
->control_command
->command_next
);
1520 s
->control_command
= s
->control_command
->command_next
;
1522 service_unwatch_control_pid(s
);
1524 if ((r
= service_spawn(s
,
1528 !s
->permissions_start_only
,
1529 !s
->root_directory_start_only
,
1530 &s
->control_pid
)) < 0)
1536 log_warning("%s failed to run spawn next executable: %s", unit_id(UNIT(s
)), strerror(-r
));
1538 if (s
->state
== SERVICE_START_PRE
)
1539 service_enter_signal(s
, SERVICE_FINAL_SIGTERM
, false);
1540 else if (s
->state
== SERVICE_STOP
)
1541 service_enter_signal(s
, SERVICE_STOP_SIGTERM
, false);
1542 else if (s
->state
== SERVICE_STOP_POST
)
1543 service_enter_dead(s
, false, true);
1545 service_enter_stop(s
, false);
1548 static int service_start(Unit
*u
) {
1549 Service
*s
= SERVICE(u
);
1553 /* We cannot fulfill this request right now, try again later
1555 if (s
->state
== SERVICE_STOP
||
1556 s
->state
== SERVICE_STOP_SIGTERM
||
1557 s
->state
== SERVICE_STOP_SIGKILL
||
1558 s
->state
== SERVICE_STOP_POST
||
1559 s
->state
== SERVICE_FINAL_SIGTERM
||
1560 s
->state
== SERVICE_FINAL_SIGKILL
)
1563 /* Already on it! */
1564 if (s
->state
== SERVICE_START_PRE
||
1565 s
->state
== SERVICE_START
||
1566 s
->state
== SERVICE_START_POST
)
1569 assert(s
->state
== SERVICE_DEAD
|| s
->state
== SERVICE_MAINTAINANCE
|| s
->state
== SERVICE_AUTO_RESTART
);
1571 /* Make sure we don't enter a busy loop of some kind. */
1572 if (!ratelimit_test(&s
->ratelimit
)) {
1573 log_warning("%s start request repeated too quickly, refusing to start.", unit_id(u
));
1578 s
->main_pid_known
= false;
1580 service_enter_start_pre(s
);
1584 static int service_stop(Unit
*u
) {
1585 Service
*s
= SERVICE(u
);
1589 /* Cannot do this now */
1590 if (s
->state
== SERVICE_START_PRE
||
1591 s
->state
== SERVICE_START
||
1592 s
->state
== SERVICE_START_POST
||
1593 s
->state
== SERVICE_RELOAD
)
1597 if (s
->state
== SERVICE_STOP
||
1598 s
->state
== SERVICE_STOP_SIGTERM
||
1599 s
->state
== SERVICE_STOP_SIGKILL
||
1600 s
->state
== SERVICE_STOP_POST
||
1601 s
->state
== SERVICE_FINAL_SIGTERM
||
1602 s
->state
== SERVICE_FINAL_SIGKILL
)
1605 if (s
->state
== SERVICE_AUTO_RESTART
) {
1606 service_set_state(s
, SERVICE_DEAD
);
1610 assert(s
->state
== SERVICE_RUNNING
|| s
->state
== SERVICE_EXITED
);
1612 service_enter_stop(s
, true);
1616 static int service_reload(Unit
*u
) {
1617 Service
*s
= SERVICE(u
);
1621 assert(s
->state
== SERVICE_RUNNING
|| s
->state
== SERVICE_EXITED
);
1623 service_enter_reload(s
);
1627 static bool service_can_reload(Unit
*u
) {
1628 Service
*s
= SERVICE(u
);
1632 return !!s
->exec_command
[SERVICE_EXEC_RELOAD
];
1635 static UnitActiveState
service_active_state(Unit
*u
) {
1638 return state_translation_table
[SERVICE(u
)->state
];
1641 static const char *service_sub_state_to_string(Unit
*u
) {
1644 return service_state_to_string(SERVICE(u
)->state
);
1647 static void service_sigchld_event(Unit
*u
, pid_t pid
, int code
, int status
) {
1648 Service
*s
= SERVICE(u
);
1654 success
= code
== CLD_EXITED
&& status
== 0;
1655 s
->failure
= s
->failure
|| !success
;
1657 if (s
->main_pid
== pid
) {
1659 exec_status_fill(&s
->main_exec_status
, pid
, code
, status
);
1662 if (s
->type
== SERVICE_SIMPLE
|| s
->type
== SERVICE_FINISH
) {
1663 assert(s
->exec_command
[SERVICE_EXEC_START
]);
1664 s
->exec_command
[SERVICE_EXEC_START
]->exec_status
= s
->main_exec_status
;
1667 log_debug("%s: main process exited, code=%s, status=%i", unit_id(u
), sigchld_code_to_string(code
), status
);
1669 /* The service exited, so the service is officially
1674 case SERVICE_START_POST
:
1675 case SERVICE_RELOAD
:
1677 /* Need to wait until the operation is
1682 assert(s
->type
== SERVICE_FINISH
);
1684 /* This was our main goal, so let's go on */
1686 service_enter_start_post(s
);
1688 service_enter_signal(s
, SERVICE_FINAL_SIGTERM
, false);
1691 case SERVICE_RUNNING
:
1692 service_enter_running(s
, success
);
1695 case SERVICE_STOP_SIGTERM
:
1696 case SERVICE_STOP_SIGKILL
:
1698 if (!control_pid_good(s
))
1699 service_enter_stop_post(s
, success
);
1701 /* If there is still a control process, wait for that first */
1705 assert_not_reached("Uh, main process died at wrong time.");
1708 } else if (s
->control_pid
== pid
) {
1709 assert(s
->control_command
);
1711 exec_status_fill(&s
->control_command
->exec_status
, pid
, code
, status
);
1714 log_debug("%s: control process exited, code=%s status=%i", unit_id(u
), sigchld_code_to_string(code
), status
);
1716 /* If we are shutting things down anyway we
1717 * don't care about failing commands. */
1719 if (s
->control_command
->command_next
&& success
) {
1721 /* There is another command to *
1722 * execute, so let's do that. */
1724 log_debug("%s running next command for state %s", unit_id(u
), service_state_to_string(s
->state
));
1725 service_run_next(s
, success
);
1728 /* No further commands for this step, so let's
1729 * figure out what to do next */
1731 log_debug("%s got final SIGCHLD for state %s", unit_id(u
), service_state_to_string(s
->state
));
1735 case SERVICE_START_PRE
:
1737 service_enter_start(s
);
1739 service_enter_signal(s
, SERVICE_FINAL_SIGTERM
, false);
1743 assert(s
->type
== SERVICE_FORKING
);
1745 /* Let's try to load the pid
1746 * file here if we can. We
1747 * ignore the return value,
1748 * since the PID file might
1749 * actually be created by a
1750 * START_POST script */
1754 service_load_pid_file(s
);
1756 service_enter_start_post(s
);
1758 service_enter_signal(s
, SERVICE_FINAL_SIGTERM
, false);
1762 case SERVICE_START_POST
:
1763 if (success
&& s
->pid_file
&& !s
->main_pid_known
) {
1766 /* Hmm, let's see if we can
1767 * load the pid now after the
1768 * start-post scripts got
1771 if ((r
= service_load_pid_file(s
)) < 0)
1772 log_warning("%s: failed to load PID file %s: %s", unit_id(UNIT(s
)), s
->pid_file
, strerror(-r
));
1777 case SERVICE_RELOAD
:
1779 service_enter_running(s
, true);
1781 service_enter_stop(s
, false);
1786 service_enter_signal(s
, SERVICE_STOP_SIGTERM
, success
);
1789 case SERVICE_STOP_SIGTERM
:
1790 case SERVICE_STOP_SIGKILL
:
1791 if (main_pid_good(s
) <= 0)
1792 service_enter_stop_post(s
, success
);
1794 /* If there is still a service
1795 * process around, wait until
1796 * that one quit, too */
1799 case SERVICE_STOP_POST
:
1800 case SERVICE_FINAL_SIGTERM
:
1801 case SERVICE_FINAL_SIGKILL
:
1802 service_enter_dead(s
, success
, true);
1806 assert_not_reached("Uh, control process died at wrong time.");
1810 assert_not_reached("Got SIGCHLD for unkown PID");
1813 static void service_timer_event(Unit
*u
, uint64_t elapsed
, Watch
* w
) {
1814 Service
*s
= SERVICE(u
);
1817 assert(elapsed
== 1);
1819 assert(w
== &s
->timer_watch
);
1823 case SERVICE_START_PRE
:
1825 log_warning("%s operation timed out. Terminating.", unit_id(u
));
1826 service_enter_signal(s
, SERVICE_FINAL_SIGTERM
, false);
1829 case SERVICE_START_POST
:
1830 case SERVICE_RELOAD
:
1831 log_warning("%s operation timed out. Stopping.", unit_id(u
));
1832 service_enter_stop(s
, false);
1836 log_warning("%s stopping timed out. Terminating.", unit_id(u
));
1837 service_enter_signal(s
, SERVICE_STOP_SIGTERM
, false);
1840 case SERVICE_STOP_SIGTERM
:
1841 log_warning("%s stopping timed out. Killing.", unit_id(u
));
1842 service_enter_signal(s
, SERVICE_STOP_SIGKILL
, false);
1845 case SERVICE_STOP_SIGKILL
:
1846 /* Uh, wie sent a SIGKILL and it is still not gone?
1847 * Must be something we cannot kill, so let's just be
1848 * weirded out and continue */
1850 log_warning("%s still around after SIGKILL. Ignoring.", unit_id(u
));
1851 service_enter_stop_post(s
, false);
1854 case SERVICE_STOP_POST
:
1855 log_warning("%s stopping timed out (2). Terminating.", unit_id(u
));
1856 service_enter_signal(s
, SERVICE_FINAL_SIGTERM
, false);
1859 case SERVICE_FINAL_SIGTERM
:
1860 log_warning("%s stopping timed out (2). Killing.", unit_id(u
));
1861 service_enter_signal(s
, SERVICE_FINAL_SIGKILL
, false);
1864 case SERVICE_FINAL_SIGKILL
:
1865 log_warning("%s still around after SIGKILL (2). Entering maintainance mode.", unit_id(u
));
1866 service_enter_dead(s
, false, true);
1869 case SERVICE_AUTO_RESTART
:
1870 log_debug("%s holdoff time over, scheduling restart.", unit_id(u
));
1871 service_enter_restart(s
);
1875 assert_not_reached("Timeout at wrong time.");
1879 static void service_cgroup_notify_event(Unit
*u
) {
1880 Service
*s
= SERVICE(u
);
1884 log_debug("%s: cgroup is empty", unit_id(u
));
1888 /* Waiting for SIGCHLD is usually more interesting,
1889 * because it includes return codes/signals. Which is
1890 * why we ignore the cgroup events for most cases,
1891 * except when we don't know pid which to expect the
1894 case SERVICE_RUNNING
:
1895 service_enter_running(s
, true);
1903 static int service_enumerate(Manager
*m
) {
1907 char *path
= NULL
, *fpath
= NULL
, *name
= NULL
;
1912 STRV_FOREACH(p
, m
->sysvrcnd_path
)
1913 for (i
= 0; i
< ELEMENTSOF(rcnd_table
); i
+= 2) {
1918 if (asprintf(&path
, "%s/%s", *p
, rcnd_table
[i
]) < 0) {
1926 if (!(d
= opendir(path
))) {
1927 if (errno
!= ENOENT
)
1928 log_warning("opendir() failed on %s: %s", path
, strerror(errno
));
1933 while ((de
= readdir(d
))) {
1934 Unit
*runlevel
, *service
;
1936 if (ignore_file(de
->d_name
))
1939 if (de
->d_name
[0] != 'S' && de
->d_name
[0] != 'K')
1942 if (strlen(de
->d_name
) < 4)
1947 if (asprintf(&fpath
, "%s/%s/%s", *p
, rcnd_table
[i
], de
->d_name
) < 0) {
1952 if (access(fpath
, X_OK
) < 0) {
1954 if (errno
!= ENOENT
)
1955 log_warning("access() failed on %s: %s", fpath
, strerror(errno
));
1962 if (asprintf(&name
, "%s.service", de
->d_name
+3) < 0) {
1967 if ((r
= manager_load_unit(m
, name
, &service
)) < 0)
1970 if ((r
= manager_load_unit(m
, rcnd_table
[i
+1], &runlevel
)) < 0)
1973 if (de
->d_name
[0] == 'S') {
1974 if ((r
= unit_add_dependency(runlevel
, UNIT_WANTS
, service
)) < 0)
1977 if ((r
= unit_add_dependency(runlevel
, UNIT_AFTER
, service
)) < 0)
1980 } else if (de
->d_name
[0] == 'K' &&
1981 (streq(rcnd_table
[i
+1], SPECIAL_RUNLEVEL0_TARGET
) ||
1982 streq(rcnd_table
[i
+1], SPECIAL_RUNLEVEL6_TARGET
))) {
1984 /* We honour K links only for
1985 * halt/reboot. For the normal
1986 * runlevels we assume the
1988 * implicitly added by the
1991 if ((r
= unit_add_dependency(runlevel
, UNIT_CONFLICTS
, service
)) < 0)
1994 if ((r
= unit_add_dependency(runlevel
, UNIT_BEFORE
, service
)) < 0)
2011 static const char* const service_state_table
[_SERVICE_STATE_MAX
] = {
2012 [SERVICE_DEAD
] = "dead",
2013 [SERVICE_START_PRE
] = "start-pre",
2014 [SERVICE_START
] = "start",
2015 [SERVICE_START_POST
] = "start-post",
2016 [SERVICE_RUNNING
] = "running",
2017 [SERVICE_EXITED
] = "exited",
2018 [SERVICE_RELOAD
] = "reload",
2019 [SERVICE_STOP
] = "stop",
2020 [SERVICE_STOP_SIGTERM
] = "stop-sigterm",
2021 [SERVICE_STOP_SIGKILL
] = "stop-sigkill",
2022 [SERVICE_STOP_POST
] = "stop-post",
2023 [SERVICE_FINAL_SIGTERM
] = "final-sigterm",
2024 [SERVICE_FINAL_SIGKILL
] = "final-sigkill",
2025 [SERVICE_MAINTAINANCE
] = "maintainance",
2026 [SERVICE_AUTO_RESTART
] = "auto-restart",
2029 DEFINE_STRING_TABLE_LOOKUP(service_state
, ServiceState
);
2031 static const char* const service_restart_table
[_SERVICE_RESTART_MAX
] = {
2032 [SERVICE_ONCE
] = "once",
2033 [SERVICE_RESTART_ON_SUCCESS
] = "restart-on-success",
2034 [SERVICE_RESTART_ALWAYS
] = "restart-always",
2037 DEFINE_STRING_TABLE_LOOKUP(service_restart
, ServiceRestart
);
2039 static const char* const service_type_table
[_SERVICE_TYPE_MAX
] = {
2040 [SERVICE_FORKING
] = "forking",
2041 [SERVICE_SIMPLE
] = "simple",
2042 [SERVICE_FINISH
] = "finish"
2045 DEFINE_STRING_TABLE_LOOKUP(service_type
, ServiceType
);
2047 static const char* const service_exec_command_table
[_SERVICE_EXEC_COMMAND_MAX
] = {
2048 [SERVICE_EXEC_START_PRE
] = "ExecStartPre",
2049 [SERVICE_EXEC_START
] = "ExecStart",
2050 [SERVICE_EXEC_START_POST
] = "ExecStartPost",
2051 [SERVICE_EXEC_RELOAD
] = "ExecReload",
2052 [SERVICE_EXEC_STOP
] = "ExecStop",
2053 [SERVICE_EXEC_STOP_POST
] = "ExecStopPost",
2056 DEFINE_STRING_TABLE_LOOKUP(service_exec_command
, ServiceExecCommand
);
2058 const UnitVTable service_vtable
= {
2059 .suffix
= ".service",
2061 .init
= service_init
,
2062 .load
= service_load
,
2063 .done
= service_done
,
2065 .dump
= service_dump
,
2067 .start
= service_start
,
2068 .stop
= service_stop
,
2069 .reload
= service_reload
,
2071 .can_reload
= service_can_reload
,
2073 .active_state
= service_active_state
,
2074 .sub_state_to_string
= service_sub_state_to_string
,
2076 .sigchld_event
= service_sigchld_event
,
2077 .timer_event
= service_timer_event
,
2079 .cgroup_notify_empty
= service_cgroup_notify_event
,
2081 .enumerate
= service_enumerate