telephony icon indicating copy to clipboard operation
telephony copied to clipboard

asterisk: (re)start asterisk in init script if pppoe-wan up after xDSL break

Open jospezial opened this issue 4 years ago • 8 comments

Maintainer: @jslachta Description: I have seen in /etc/init.d/adblock https://github.com/openwrt/packages/blob/19fcff09107ab9b03331e433a1750c826c3747dd/net/adblock/files/adblock.init#L348-L371 you can use procd_add_interface_trigger to restart the service by status of network interfaces. Works for me with

        option adb_trigger 'wan'

in /etc/config/adblock

Would be nice to have that in /etc/init.d/asterisk and /etc/config/asterisk too. That makes sure asterisk pjsip registrations are up to date and don´t use old IP number. Otherwise it waits until pjsip expiration value is over.

jospezial avatar Sep 06 '21 10:09 jospezial

Can you make this work and send a pull request?

micmac1 avatar Sep 17 '21 18:09 micmac1

Can you make this work and send a pull request?

I am not so good in this. And I don't want to sign off a PR with real name and e-mail in connection with my nick.

jospezial avatar Sep 17 '21 18:09 jospezial

https://github.com/openwrt/telephony/pull/701 was the PR that tried to fix this.

jospezial avatar Nov 06 '21 12:11 jospezial

As mentioned in the PR, you can use hotplug events by setting up a file like /etc/hotplug.d/iface/99-asterisk and execute any command you want. I don't have a DSL connection to test, but something like this should work.

[ "$ACTION" = "ifup" -a "$INTERFACE" = "pppoe-wan" ] && {
  /etc/init.d/asterisk enabled && {
    # this or any other command you want to run
    /usr/sbin/asterisk -x 'pjsip send unregister *all' -x 'pjsip send register *all'
  }
}

micmac1 avatar Nov 06 '21 16:11 micmac1

@micmac1 I tested your example. For "pppoe-wan" "$DEVICE" has to used. And for "wan" "$INTERFACE" This is my /etc/hotplug.d/iface/99-asterisk now:

[ "$ACTION" = "ifdown" -a "$INTERFACE" = "wan" ] && {
  /etc/init.d/asterisk enabled && {
        echo "heartbeat" >/sys/devices/platform/leds/leds/green:telefon/trigger
        /usr/bin/logger -p daemon.info -s -t hotplug_asterisk "Unregistering all outbound pjsip registrations because internet down."
        /usr/sbin/asterisk -x 'pjsip send unregister *all'
  }
}

[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
  /etc/init.d/asterisk enabled && {
        echo "default-on" >/sys/devices/platform/leds/leds/green:telefon/trigger
        /usr/bin/logger -p daemon.info -s -t hotplug_asterisk "Re-registering all outbound pjsip registrations because internet up (again)."
        /usr/sbin/asterisk -x 'pjsip send register *all'
  }
}

Seems to work as I want. The next thing is, how can I signalize if Asterisk has no registrations because of other issues?

jospezial avatar Jan 29 '22 03:01 jospezial

Seems to work as I want. The next thing is, how can I signalize if Asterisk has no registrations because of other issues?

Maybe a cron job that checks periodically and then acts accordingly. Asterisk users mailing list is maybe a better place for your question.

micmac1 avatar Jan 29 '22 10:01 micmac1

@dhewg Do you wanna try out my hotplug script? Or add that LED control in your init script?

jospezial avatar Jan 29 '22 12:01 jospezial

I'm still using my init script patch myself. I don't have a use for led control myself, but I think you can control the led state like you are with the standard OpenWrt led options? netdev state wan up something something?

dhewg avatar Jan 31 '22 18:01 dhewg