Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
docs:guide-user:advanced:hotplug_extras [2021/04/13 02:14] – [Implementation] wording vgaeteradocs:guide-user:advanced:hotplug_extras [2023/10/03 18:12] – [Instructions] avoid global delay, use delay per script if necessary vgaetera
Line 1: Line 1:
 ====== Hotplug extras ====== ====== Hotplug extras ======
-{{section>meta:infobox:howto_links#cli_skills&noheader&nofooter&noeditbutton}}+{{section>meta:infobox:howto_links#basic_skills&noheader&nofooter&noeditbutton}}
  
 ===== Introduction ===== ===== Introduction =====
-  * This instruction extends [[docs:guide-user:base-system:hotplug|Hotplug]] functionality. +  * This instruction extends the functionality of [[docs:guide-user:base-system:hotplug|Hotplug]].
-  * Follow [[docs:guide-user:advanced:opkg_extras|Opkg extras]] to extend Opkg functionality. +
-  * Follow [[docs:guide-user:advanced:uci_extras|UCI extras]] to extend UCI functionality.+
   * Follow the [[docs:guide-user:advanced:hotplug_extras#automated|automated]] section for quick setup.   * Follow the [[docs:guide-user:advanced:hotplug_extras#automated|automated]] section for quick setup.
  
Line 12: Line 10:
  
 ===== Implementation ===== ===== Implementation =====
-  * Rely on [[https://github.com/openwrt/openwrt/blob/master/package/base-files/files/lib/functions/network.sh|network functions]] to identify WAN interface. +  * Use [[docs:guide-user:base-system:hotplug|Hotplug]] to detect connectivity change and trigger network dependent scripts. 
-  * Use [[docs:guide-user:base-system:hotplug|Hotplug]] to detect WAN connectivity and trigger network dependent scripts.+  * Process subsystem-specific scripts with [[https://github.com/openwrt/openwrt/blob/master/package/base-files/files/sbin/hotplug-call|hotplug-call]].
   * Delay script invocation with [[man>sleep(1)|sleep]] to work around tunneled connections.   * Delay script invocation with [[man>sleep(1)|sleep]] to work around tunneled connections.
   * Write and read non-interactive logs with [[docs:guide-user:base-system:log.essentials|Syslog]] for troubleshooting.   * Write and read non-interactive logs with [[docs:guide-user:base-system:log.essentials|Syslog]] for troubleshooting.
Line 22: Line 20:
 mkdir -p /etc/hotplug.d/iface mkdir -p /etc/hotplug.d/iface
 cat << "EOF" > /etc/hotplug.d/iface/90-online cat << "EOF" > /etc/hotplug.d/iface/90-online
-. /lib/functions/network.sh +if [ "${INTERFACE}" = "loopback" ] 
-network_flush_cache +then exit 0
-network_find_wan NET_IF +
-network_find_wan6 NET_IF6 +
-if [ "${INTERFACE}" = "${NET_IF}" -o "${INTERFACE}" = "${NET_IF6}" ] \ +
-&& [ "${ACTION}" = "ifup" -o "${ACTION}" = "ifupdate" ] +
-then for FILE in /etc/hotplug.d/online/+
-do . "${FILE}" 2>&+
-done | logger -t hotplug-online+
 fi fi
 +if [ "${ACTION}" != "ifup" ] \
 +&& [ "${ACTION}" != "ifupdate" ]
 +then exit 0
 +fi
 +if [ "${ACTION}" = "ifupdate" ] \
 +&& [ -z "${IFUPDATE_ADDRESSES}" ] \
 +&& [ -z "${IFUPDATE_DATA}" ]
 +then exit 0
 +fi
 +hotplug-call online
 EOF EOF
 cat << "EOF" >> /etc/sysupgrade.conf cat << "EOF" >> /etc/sysupgrade.conf
 /etc/hotplug.d/iface/90-online /etc/hotplug.d/iface/90-online
-EOF 
-mkdir -p /etc/hotplug.d/online 
-cat << "EOF" > /etc/hotplug.d/online/30-sleep 
-sleep 10 
-EOF 
-cat << "EOF" >> /etc/sysupgrade.conf 
-/etc/hotplug.d/online/30-sleep 
 EOF EOF
 </code> </code>
Line 47: Line 41:
 ===== Examples ===== ===== Examples =====
 <code bash> <code bash>
-Check hotplug log+Example script 
 +cat << "EOF" > /etc/hotplug.d/online/00-logger 
 +logger -t hotplug $(env) 
 +EOF 
 +/etc/init.d/network restart
 logread -e hotplug logread -e hotplug
 </code> </code>
Line 53: Line 51:
 ===== Automated ===== ===== Automated =====
 <code bash> <code bash>
-opkg update +wget -U "" -O hotplug-extras.sh "https://openwrt.org/_export/code/docs/guide-user/advanced/hotplug_extras?codeblock=0"
-opkg install libustream-mbedtls +
-uclient-fetch -O hotplug-extras.sh "https://openwrt.org/_export/code/docs/guide-user/advanced/hotplug_extras?codeblock=0"+
 . ./hotplug-extras.sh . ./hotplug-extras.sh
 </code> </code>
  
  • Last modified: 2023/10/14 05:44
  • by vgaetera