/[smeserver]/rpms/e-smith-base/sme10/e-smith-base-5.8.0-bz11345-systemctlWrapper.patch
ViewVC logotype

Contents of /rpms/e-smith-base/sme10/e-smith-base-5.8.0-bz11345-systemctlWrapper.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download)
Sun Jun 6 20:38:32 2021 UTC (3 years, 5 months ago) by jpp
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
FILE REMOVED
5.8.1

1 diff -Nur --no-dereference e-smith-base-5.8.0.old/root/sbin/e-smith/systemctl e-smith-base-5.8.0/root/sbin/e-smith/systemctl
2 --- e-smith-base-5.8.0.old/root/sbin/e-smith/systemctl 1969-12-31 19:00:00.000000000 -0500
3 +++ e-smith-base-5.8.0/root/sbin/e-smith/systemctl 2021-03-18 23:08:52.585000000 -0400
4 @@ -0,0 +1,180 @@
5 +#!/bin/bash
6 +#systemctl wrapper fo Koozali SME Server
7 +
8 +allargs=$@
9 +opts=();
10 +syscommand="";
11 +sysunit=""
12 +debug=$(/sbin/e-smith/config get debug || echo "false")
13 +if [ "$debug" != "true" ]; then debug=false;fi
14 +
15 +# short OPTIONS we must pay attention as they have more arguments
16 +#-t, --type=
17 +#-s, --signal=
18 +#-p, --property=
19 +#-o, --output=
20 +#-n, --lines=
21 +#-H, --host=
22 +#-M, --machine=
23 +
24 +#commands we should return directly to systemd
25 +#list-units,list-sockets,list-timers,is-active,is-failed,status,show,cat,set-property,help,reset-failed,list-dependencies,
26 +#list-unit-files,is-enabled,get-default,set-default
27 +#list-machines
28 +#list-jobs
29 +#snapshot,delete
30 +#show-environment,set-environment,unset-environment,import-environment
31 +#daemon-reload,daemon-reexec
32 +#is-system-running,default,rescue,emergency,halt,poweroff,reboot,kexec,switch-root,suspend,hibernate,hybrid-sleep
33 +
34 +# This is a list of commands :
35 +# -we want to handle ourself or
36 +# -we need to translate for systemd or
37 +# -we do not want admin uses against the SME Server
38 +#
39 +# commands we handle: start,stop,reload,restart,try-restart,reload-or-restart,reload-or-try-restart,isolate,kill
40 +# enable,disable,reenable,preset,preset-all,mask,unmask,link,add-wants,edit
41 +# commands we deactivate/hide : mask,unmask,link,add-wants,edit set-default
42 +# not systemd but we might use them : adjust sigterm sighup sigusr1 sigusr2
43 +filteredcommands=(start stop reload restart try-restart reload-or-restart reload-or-try-restart isolate kill enable disable reenable preset preset-all adjust sigterm sighup sigusr1 sigusr2 mask unmask link add-wants add-requires edit set-default );
44 +
45 +# fucntion to check if this is a command we want
46 +contains2 () {
47 + local seeking=$1
48 + local in=0
49 + for element in "${filteredcommands[@]}"; do
50 + if [[ $element == "$seeking" ]]; then
51 + in=1
52 + break
53 + fi
54 + done
55 + return $in
56 +}
57 +
58 +# if no args we return to systemcl
59 +if [ $# -eq 0 ]; then
60 + echo "we return to systemctl"
61 + /usr/bin/systemctl
62 + exit
63 +fi
64 +
65 +#parse args
66 +while [ "$#" -gt 0 ]; do
67 + case "$1" in
68 + -p|-t|-s|-o|-n|H|-M) temp=$1; shift ; opts+=("$temp $1"); ;;
69 + --*) opts+=("$1") ;;
70 + -*) opts+=("$1") ;;
71 + *) if [[ "$syscommand" == "" ]]; then syscommand="$1" ; else sysunit="$1"; fi ;;
72 + esac
73 + shift
74 +done
75 +
76 +servicename=${sysunit%".service"}
77 +
78 +#we return to systemd systemctl command unless this is one of the command we want to handle
79 +if ( contains2 "$syscommand" ) ; then
80 + ($debug) && echo "we return to /usr/bin/systemctl ${allargs[*]}"
81 + /usr/bin/systemctl ${allargs[*]}
82 + exit
83 +fi
84 +
85 +
86 +# here we convert sig* to kill -s=SIG* or SME commant to ones systemd recognize
87 +case "$syscommand" in
88 + adjust|sighup|sigusr1|sigusr2)
89 + $syscommand="reload-or-restart";
90 + ;;
91 + sigterm)
92 + $syscommand="restart";
93 + ;;
94 +esac
95 +
96 +
97 +# catch here non unit signals, or ones we would like to do something different
98 +#enable disable reenable preset preset-all
99 +#mask unmask link add-wants edit
100 +case "$syscommand" in
101 + preset-all)
102 + ($debug) && echo "We do /etc/e-smith/events/actions/systemd-default"
103 + /etc/e-smith/events/actions/systemd-default
104 + exit
105 + ;;
106 + preset)
107 + # TODO looking if we could use /etc/e-smith/events/actions/systemd-default none $servicename
108 + ($debug) && echo "We do /etc/e-smith/events/actions/systemd-default"
109 + /etc/e-smith/events/actions/systemd-default
110 + exit
111 + ;;
112 + enable|disable|reenable)
113 + # looking if we could use
114 + newstatus="enabled"
115 + todo="enable"
116 + if [ $syscommand == "disable" ]; then newstatus="disabled";todo="disable" ; fi
117 + /sbin/e-smith/config setprop $servicename status $newstatus
118 + #/etc/e-smith/events/actions/systemd-default none $servicename
119 + # TODO looking if we could do it only for the service would be great!
120 + ($debug) && echo "We do /etc/e-smith/events/actions/systemd-default"
121 + ($debug) && echo "/usr/bin/systemctl $todo $sysunit ${opts[*]}"
122 + /etc/e-smith/events/actions/systemd-default
123 + /usr/bin/systemctl $todo $sysunit ${opts[*]}
124 + exit
125 + ;;
126 + set-default |isolate)
127 + echo "We only $syscommand against sme-server.target"
128 + ($debug) && echo "/etc/e-smith/events/actions/systemd-default"
129 + ($debug) && echo "/etc/e-smith/events/actions/systemd-isolate"
130 + /etc/e-smith/events/actions/systemd-default
131 + /etc/e-smith/events/actions/systemd-isolate
132 + ;;
133 + link|mask|unmask|add-wants|add-requires|edit)
134 + echo "Please, do not use $syscommand for Koozali SME Server"
135 + exit
136 + ;;
137 +esac
138 +
139 +
140 +#check the unit exist or fails : we do not care systemctl will do this...
141 +
142 +# here we check if in db and if enabled or disabled
143 +# if not or not service = return to systemctl directly
144 +stype=$(/sbin/e-smith/db configuration gettype $servicename || echo "none")
145 +sstatus=$(/sbin/e-smith/db configuration getprop $servicename status || echo "disabled")
146 +if [ $stype == "none" ] ; then
147 + # not defined in db, we redirect
148 + echo "Information: $sysunit is not defined in configuration DB."
149 + ($debug) && echo "/usr/bin/systemctl ${allargs[*]}"
150 + /usr/bin/systemctl ${allargs[*]}
151 + exit
152 +elif [ $stype != "service" ] ; then
153 + echo "Information: $sysunit is not defined as a service in configuration DB but $type"
154 + ($debug) && echo "/usr/bin/systemctl ${allargs[*]}"
155 + /usr/bin/systemctl ${allargs[*]}
156 + exit
157 +elif [ $sstatus == "disabled" ]; then
158 + echo "Information: $sysunit is $sstatus in configuration DB."
159 + # we might want to simply stop
160 + #/usr/bin/systemctl stop $sysunit
161 + # but we will do what we were asked for
162 + ($debug) && echo "/usr/bin/systemctl ${allargs[*]}"
163 + /usr/bin/systemctl ${allargs[*]}
164 + exit
165 +elif [ $sstatus == "enabled" ]; then
166 + #echo "$sstatus"
167 + # starting in case
168 + #systemctl is-active -q $sysunit will return zero if active; non zero if not
169 + #/usr/bin/systemctl is-active -q $sysunit || /usr/bin/systemctl start $sysunit
170 + # now executing the command
171 + ($debug) && echo "/usr/bin/systemctl $syscommand $sysunit ${opts[*]}"
172 + /usr/bin/systemctl $syscommand $sysunit ${opts[*]}
173 + exit
174 +fi
175 +
176 +
177 +
178 +
179 +
180 +echo "if you see that, we missed something, report the command to https://bugs.koozali.org"
181 +echo "options : " ${opts[*]};
182 +echo "command : " $syscommand;
183 +echo "unit :" $sysunit;
184 +echo $@

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed