Annotation of /mcore-src/trunk/mcore-tools/daemon/client/include/systemd.client.class
Parent Directory | Revision Log
Revision 2089 -
(hide annotations)
(download)
Fri May 10 13:29:29 2013 UTC (11 years, 4 months ago) by niro
File size: 2116 byte(s)
Fri May 10 13:29:29 2013 UTC (11 years, 4 months ago) by niro
File size: 2116 byte(s)
-auto-append .service to services when missing to fix a $MROOT issue
1 | niro | 2079 | # $Id$ |
2 | |||
3 | provide basic-init systemd | ||
4 | require basic-system | ||
5 | |||
6 | set_system_service() | ||
7 | { | ||
8 | local command="$1" | ||
9 | local service="$2" | ||
10 | local opts="$3" | ||
11 | |||
12 | [[ -z ${command} ]] && help_system_service && return 1 | ||
13 | [[ -z ${service} ]] && help_system_service && return 1 | ||
14 | |||
15 | niro | 2084 | local chrooted |
16 | if [[ -n ${MROOT} ]] && [[ ${MROOT} != / ]] | ||
17 | niro | 2079 | then |
18 | niro | 2084 | chrooted="system_chroot" |
19 | case ${command} in | ||
20 | start|stop|restart|reload) | ||
21 | eecho "Command not available while \$MROOT is set" | ||
22 | return 1 | ||
23 | ;; | ||
24 | esac | ||
25 | fi | ||
26 | |||
27 | if [[ -n $(${chrooted} systemctl status ${service} | grep 'Reason: No such file or directory') ]] | ||
28 | then | ||
29 | niro | 2079 | eecho "Service '${service}' unkown!" |
30 | return 1 | ||
31 | fi | ||
32 | |||
33 | niro | 2089 | # auto-append .service to fix issues while $MROOT is set |
34 | if [[ -n $(echo ${service} | grep -v '.service$\|.target$\|.mount$\|.socket$\|.timer$') ]] | ||
35 | then | ||
36 | service="${service}.service" | ||
37 | decho "\$service replaced with '${service}'" | ||
38 | fi | ||
39 | |||
40 | niro | 2079 | case "${command}" in |
41 | niro | 2084 | start) ${chrooted} systemctl start "${service}" ;; |
42 | stop) ${chrooted} systemctl stop "${service}" ;; | ||
43 | restart) ${chrooted} systemctl try-restart "${service}" ;; | ||
44 | reload) ${chrooted} systemctl reload-or-try-restart "${service}" ;; | ||
45 | add) ${chrooted} systemctl enable "${service}" ;; | ||
46 | del) ${chrooted} systemctl disable "${service}" ;; | ||
47 | niro | 2079 | *) help_system_service && return ;; |
48 | esac | ||
49 | } | ||
50 | |||
51 | get_system_service() | ||
52 | { | ||
53 | local command="$1" | ||
54 | local service="$2" | ||
55 | |||
56 | [[ -z ${command} ]] && help_system_service && return 1 | ||
57 | [[ -z ${service} ]] && help_system_service && return 1 | ||
58 | |||
59 | niro | 2084 | local chrooted |
60 | if [[ -n ${MROOT} ]] && [[ ${MROOT} != / ]] | ||
61 | niro | 2079 | then |
62 | niro | 2084 | chrooted="system_chroot" |
63 | case ${command} in | ||
64 | status) | ||
65 | eecho "Command not available while \$MROOT is set" | ||
66 | return 1 | ||
67 | ;; | ||
68 | esac | ||
69 | fi | ||
70 | |||
71 | if [[ -n $(${chrooted} systemctl status ${service} | grep 'Reason: No such file or directory') ]] | ||
72 | then | ||
73 | niro | 2079 | eecho "Service '${service}' unkown!" |
74 | return 1 | ||
75 | fi | ||
76 | |||
77 | case "${command}" in | ||
78 | niro | 2084 | status) ${chrooted} systemctl status "${service}" ;; |
79 | enabled) ${chrooted} systemctl is-enabled "${service}"; rvecho "$?" ;; | ||
80 | niro | 2079 | runlevel) rvecho "$(readline ${MROOT}/etc/systemd/system/default.target)" ;; |
81 | *) help_system_service && return ;; | ||
82 | esac | ||
83 | } |