Changeset 56850 in vbox for trunk/src/VBox/Installer
- Timestamp:
- Jul 8, 2015 9:01:47 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Installer/linux/routines.sh
r56842 r56850 185 185 } 186 186 187 ## Creates a systemd wrapper in /lib for an LSB init script 188 systemd_wrap_init_script() 189 { 190 self="systemd_wrap_init_script" 191 ## The init script to be installed. The file may be copied or referenced. 192 script="$(readlink -f -- "${1}")" 193 ## Name for the service. 194 name="$2" 195 test -x "$script" && test ! "$name" = "" || \ 196 { log "$self: invalid arguments" && return 1; } 197 test -d /usr/lib/systemd/system && unit_path=/usr/lib/systemd/system 198 test -d /lib/systemd/system && unit_path=/lib/systemd/system 199 test -n "${unit_path}" || \ 200 { log "$self: systemd unit path not found" && return 1; } 201 description=`sed -n 's/# *Description: *\(.*\)/\1/p' "${script}"` 202 required=`sed -n 's/# *Required-Start: *\(.*\)/\1/p' "${script}"` 203 runlevels=`sed -n 's/# *Default-Start: *\(.*\)/\1/p' "${script}"` 204 before=`for i in ${runlevels}; do printf "runlevel${i}.target "; done` 205 after=`for i in ${required}; do printf "${i}.service "; done` 206 cat > "${unit_path}/${name}.service" << EOF 207 [Unit] 208 SourcePath=${script} 209 Description=${description} 210 Before=${before}shutdown.target 211 After=${after} 212 Conflicts=shutdown.target 213 214 [Service] 215 Type=forking 216 Restart=no 217 TimeoutSec=5min 218 IgnoreSIGPIPE=no 219 KillMode=process 220 GuessMainPID=no 221 RemainAfterExit=yes 222 ExecStart=${script} start 223 ExecStop=${script} stop 224 EOF 225 } 226 187 227 ## Installs a file containing a shell script as an init script 188 228 install_init_script() … … 195 235 test -x "$script" && test ! "$name" = "" || \ 196 236 { log "$self: invalid arguments" && return 1; } 237 test -d /lib/systemd/system || test -d /usr/lib/systemd/system && systemd_wrap_init_script "$script" "$name" 197 238 if test -d /etc/rc.d/init.d 198 239 then … … 203 244 cp "$script" "/etc/init.d/$name" 2> /dev/null 204 245 chmod 755 "/etc/init.d/$name" 2> /dev/null 205 else206 log "${self}: error: unknown init type"207 return 1208 246 fi 209 247 return 0 … … 218 256 test ! "$name" = "" || \ 219 257 { log "$self: missing argument" && return 1; } 258 rm -f /lib/systemd/system/"$name".service /usr/lib/systemd/system/"$name".service 220 259 if test -d /etc/rc.d/init.d 221 260 then … … 224 263 then 225 264 rm -f "/etc/init.d/$name" > /dev/null 2>&1 226 else227 log "${self}: error: unknown init type"228 return 1229 265 fi 230 266 return 0 … … 241 277 test ! -z "${name}" && test ! -z "${action}" || \ 242 278 { log "${self}: missing argument" && return 1; } 243 if test -x "/etc/rc.d/init.d/${name}" 244 then 245 script="/etc/rc.d/init.d/${name}" 246 elif test -x "/etc/init.d/${name}" 247 then 248 script="/etc/init.d/${name}" 249 else 250 log "${self}: error: unknown init type or unknown service ${name}" 251 return 1 252 fi 253 if test -x "`which service 2>/dev/null`" 279 if test -x "`which systemctl 2>/dev/null`" 280 then 281 systemctl ${action} "${name}" 282 elif test -x "`which service 2>/dev/null`" 254 283 then 255 284 service "${name}" ${action} … … 257 286 then 258 287 invoke-rc.d "${name}" ${action} 259 else 260 "${script}" "${action}" 288 elif test -x "/etc/rc.d/init.d/${name}" 289 then 290 "/etc/rc.d/init.d/${name}" "${action}" 291 elif test -x "/etc/init.d/${name}" 292 then 293 "/etc/init.d/${name}" "${action}" 261 294 fi 262 295 }
Note:
See TracChangeset
for help on using the changeset viewer.