What's new

service-event-end question

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

omrij

Occasional Visitor
Hi
tried searching before starting this thread and also tried asking chatgpt without success :(
using latest Merlinwrt on GT-AX6000
I have a script which I need to run after every start/restart of wireless and after reboot (but not other events)
this is the template I tried but it didn't work
Code:
#!/bin/sh

# Check if the event is start, restart, or reboot
if [ "$1" = "start" ] || [ "$1" = "restart" ]; then
    if [ "$2" = "wireless" ]; then
        logger "Wireless is starting or restarting. Executing custom script..."
        
        # Place your custom commands here
        # Example: restart a service, configure settings, etc.
        # /path/to/your/custom/script.sh
    fi
elif [ "$1" = "reboot" ]; then
    logger "System is rebooting. Executing custom reboot script..."
    
    # Place your custom reboot-related commands here
    # /path/to/your/custom/reboot_script.sh
fi

any help would be appreciated
 
Last edited:
Ran into similar problem quite some time ago. You would think the event model was thorough and complete, but I ran across several times when events simply weren't triggered for some reason. I ended up actually taking the template and writing a message to the log each time it was called so I could tell exactly when it was called, and for what service. It was then I realized you can't just assume it will work for all services, all the time.


Annoying, but that's just the way it is. I ended up using other events as a workaround.
 
Last edited:
Based on the asuswrt-merlin's official documentation, I'm not sure if I fully understand it correctly. You might want to give it a try yourself.


1728166616119.png


Capturing Wireless Service Restart Events (service-event and service-event-end)

You can create two scripts to handle the events before and after the wireless service starts or stops. These scripts will be triggered when events like start, stop, or restart occur for the wireless service.

Example for service-event:​

This script will be executed before the wireless service is restarted, stopped, or started.

Code:
#!/bin/sh


EVENT=$1  # Event type: start, stop, restart
TARGET=$2  # Target service: wireless, httpd, etc.


# Check if the target is wireless
if [ "$TARGET" = "wireless" ]; then
    echo "custom commands here"
fi

Example for service-event-end:​

This script will be executed after the wireless service has completed starting, stopping, or restarting.

Code:
#!/bin/sh

EVENT=$1  # Event type: start, stop, restart
TARGET=$2  # Target service: wireless, httpd, etc.

# Check if the target is wireless
if [ "$TARGET" = "wireless" ]; then
    echo "custom commands here"
fi


I've observed that other scripts also retrieve the status in a similar way.

Code:
#!/bin/sh


if [ "$1" = "start" ] && [ "$2" = "SkynetStats" ]; then sh /jffs/scripts/firewall debug genstats; fi # Skynet
/jffs/scripts/scribe service_event "$@" & # added by scribe
if echo "$2" | /bin/grep -q "uiScribe"; then { /jffs/scripts/uiScribe service_event "$@" & }; fi # uiScribe
if echo "$2" | /bin/grep -q "connmon"; then { /jffs/scripts/connmon service_event "$@" & }; fi # connmon
/jffs/scripts/dn-vnstat service_event "$@" & # dn-vnstat
if echo "$2" | /bin/grep -q "ntpmerlin"; then { /jffs/scripts/ntpmerlin service_event "$@" & }; fi # ntpMerlin
if echo "$2" | /bin/grep -q "scmerlin"; then { /jffs/scripts/scmerlin service_event "$@" & }; fi # scMerlin
/jffs/addons/unbound/unbound_stats.sh generate "$1" "$2" & # Unbound_Stats.sh


[ "$2" = diversion ] && /opt/share/diversion/webui/process.div "$1" & # Added by Diversion
if echo "$2" | /bin/grep -q "uiDivStats"; then { /jffs/scripts/uiDivStats service_event "$@" & }; fi # uiDivStats

I'm not sure if the target service name is 'wireless', 'wlceventd', or something else.
 
Last edited:

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top