Debian Codegraph @

tools/hook-hotplug

raw symbols SCIP
1 #!/bin/sh
2 # This file is part of cloud-init. See LICENSE file for license information.
3
4 # This script checks if cloud-init has hotplug hooked and if
5 # cloud-init is ready; if so invoke cloud-init hotplug-hook
6
7 fifo=/run/cloud-init/share/hook-hotplug-cmd
8 log_file=/run/cloud-init/hook-hotplug.log
9
10 should_run() {
11 if [ -d /run/systemd ]; then
12 # check that the socket is ready
13 [ -p $fifo ]
14 else
15 # on non-systemd, check cloud-init fully finished.
16 [ -e /run/cloud-init/result.json ]
17 fi
18 }
19
20 if ! should_run; then
21 # This happens when a device is hotplugged before cloud-init-hotplugd.socket is
22 # listening on the socket.
23 echo "Not running hotplug, not ready yet" >> ${log_file}
24 exit 0
25 fi
26
27 # open cloud-init's hotplug-hook fifo rw
28 exec 3<> $fifo
29 env_params=" --subsystem=${SUBSYSTEM} handle --devpath=${DEVPATH} --udevaction=${ACTION}"
30 # write params to cloud-init's hotplug-hook fifo
31 echo "${env_params}" >&3
32 echo "Running hotplug hook: $env_params" >> ${log_file}