List of hooks?



  • (x-post from /r/PFSENSE)

    Reading this reddit post got me thinking: I don't think these type of "hooks" are documented anywhere.

    For example /etc/rc.gateway_alarm gets triggered when a gateway changes state (up/packetloss/latency/down) and is an OK place to add extra actions that you want to happen for those things, like sending additional alerts or killing states.

    I know we can scour the code and try to sniff out the rest of them but, is there already such a list somewhere that can be published?



  • @luckman212 said in List of hooks?:

    For example /etc/rc.gateway_alarm gets triggered when a gateway changes state (up/packetloss/latency/down) and is an OK place to add extra actions that you want to happen for those things, like sending additional alerts or killing states.

    Not really, because the content of /etc/ gets overwritten when pfSense updates. So officially documenting it will likely cause an additional flood of complaints on every pfSense update. The only thing supported is: https://www.netgate.com/docs/pfsense/development/executing-commands-at-boot-time.html#shell-script-option



  • I agree, modifying the /etc/rc.* files directly is not durable. It would be better if the rc* files tested for the existence of a user-defined script named /etc/{scriptname}_custom and executed that if it exists. This would be safer, and survive upgrades.

    E.g. in the case of rc.gateway_alarm (at the end) instead of:

    exit $?
    

    It could be:

    [ -x /etc/rc.gateway_alarm_custom ] && /etc/rc.gateway_alarm_custom 
    exit $?
    

    And then users could create /etc/rc.gateway_alarm_custom if they need to do any custom work there:

    #!/bin/sh
    logger -t rc.hook "doing extra stuff..."
    [...stuff...]
    echo '<?php include("notices.inc"); $msg = "stuff has completed"; notify_via_smtp($msg);?>' | php -q