65 lines
1.8 KiB
Desktop File
Executable File
65 lines
1.8 KiB
Desktop File
Executable File
# apt install --no-install-recommends libqmi-utils ifmetric
|
|
# cp -v ./qmi-network@.service /etc/systemd/system/
|
|
# systemctl daemon-reload
|
|
# systemctl enable --now qmi-network@0
|
|
|
|
# This will NOT work without a .network for your wwan device.
|
|
[Unit]
|
|
Description=qmi-network for cdc-wdm%i device
|
|
|
|
Before=freepbx.service
|
|
Before=asterisk.service
|
|
|
|
Requires=sys-subsystem-net-devices-wwan%i.device
|
|
|
|
[Service]
|
|
Type=simple
|
|
Restart=always
|
|
RestartSec=60s
|
|
TimeoutSec=90s
|
|
|
|
##
|
|
|
|
# Ping host.
|
|
Environment=PHOST="one.one.one.one"
|
|
|
|
# Normal wwan%i metric (should be higher than all other dev).
|
|
Environment=NMETRIC=1025
|
|
|
|
# Failover wwan%i metric.
|
|
Environment=FOMETRIC=128
|
|
|
|
# Ping test interval.
|
|
Environment=TESTINT=20
|
|
|
|
##
|
|
|
|
# Make sure the state is cleared before starting.
|
|
ExecStartPre=-rm /tmp/qmi-network-state-cdc-wdm%i
|
|
|
|
# Stop wwan so it can be reconfigured.
|
|
ExecStartPre=networkctl down wwan%i
|
|
|
|
# Raw IP must be enabled.
|
|
ExecStartPre=sh -c "echo 'Y' | tee /sys/class/net/wwan%i/qmi/raw_ip"
|
|
|
|
# Bring up the network.
|
|
ExecStartPre=networkctl up wwan%i
|
|
|
|
# Start the network via qmi-network scripts.
|
|
# As some networks and/or devices take a long time to connect we should
|
|
# give it some time to be ready before starting the connection process.
|
|
ExecStartPre=-sh -e -c "sleep 5; qmi-network /dev/cdc-wdm%i start && sleep 5;"
|
|
|
|
# Main loop with **very basic** failover.
|
|
ExecStart=sh -e -c "while true; do ping -w 10 -I wwan%i -c 3 one.one.one.one 2>&1 >/dev/null; (ping -w 10 -c 3 ${PHOST} 2>&1 >/dev/null && ifmetric wwan%i ${NMETRIC}) || (ping -w 10 -I wwan%i -c 3 ${PHOST} 2>&1 >/dev/null && ifmetric wwan%i ${FOMETRIC}); sleep ${TESTINT}; done;"
|
|
|
|
# Stop.. DOWN TIME!
|
|
ExecStop=networkctl down wwan%i
|
|
ExecStop=qmi-network /dev/cdc-wdm%i stop
|
|
# Be sure the network state is cleared on stop too.
|
|
ExecStop=-rm /tmp/qmi-network-state-cdc-wdm%i
|
|
|
|
[Install]
|
|
WantedBy=sys-subsystem-net-devices-wwan%i.device
|