You are not logged in.

#1 2013-07-21 00:40:43

sxtynnmach1
Member
From: 127.0.0.1
Registered: 2009-10-31
Posts: 12

[SOLVED] Netctl script execution order?

The man pages are bit ambiguous, but this is what I'd like to know:

Given I'm connecting to wireless network "MyESSID" on interface "wlan0", what is the execution order of these scripts:

  • /etc/netctl/hooks/*

  • /etc/netctl/interfaces/wlan0

  • /etc/netctl/wlan0-MyESSID (ExecUpPost)

Given I'm disconnecting from the same interface/essid, what is the execution order again:

  • /etc/netctl/hooks/*

  • /etc/netctl/interfaces/wlan0

  • /etc/netctl/wlan0-MyESSID (ExecDownPre)

Some of my wireless networks need proxies, and others don't.
I'd like to start/stop Dropbox on connect/disconnect of any network (but only after the proxies are set)

Thanks in advance!

Last edited by sxtynnmach1 (2013-07-27 05:38:39)


Hello Darkness, my old friend. I've come to talk with you again.

Offline

#2 2013-07-21 00:52:08

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [SOLVED] Netctl script execution order?

The nice thing about netctl is that is is jsut a collection of shell scripts.  So you should check out /usr/bin/netctl and see if there is a function there that tells you about this. If not there, then check out what other files it may source and then check those functions as well.

Offline

#3 2013-07-21 04:27:59

bkhl
Member
Registered: 2013-07-21
Posts: 6

Re: [SOLVED] Netctl script execution order?

Let us know how you set it up. I was just now also looking for the most convenient way to turn a service (in my case CrashPlan) on or off based on network location.

Offline

#4 2013-07-21 04:56:53

sxtynnmach1
Member
From: 127.0.0.1
Registered: 2009-10-31
Posts: 12

Re: [SOLVED] Netctl script execution order?

To be honest I've been experimenting between wicd, networkmanager and netctl.

I really like wicd's way of executing scripts based on preconnect, postconnect, predisconnect and postdisconnect. Each script you make receives the ESSID or profile name so that you can have if or case statements per network location.

Unfortunately, it seems that wicd development has stagnated for the past year and a half sad

I didn't want something as heavy-weight as networkmanager, but it's looking to be the most convenient solution. After looking through the netctl bash scripts it seems a bit janky with it's handling of /etc/netctl/hooks.


Hello Darkness, my old friend. I've come to talk with you again.

Offline

#5 2013-07-21 04:58:43

bkhl
Member
Registered: 2013-07-21
Posts: 6

Re: [SOLVED] Netctl script execution order?

For my purposes in this particular case I can live with just having a "systemctl crashplan restart" in /etc/netctl/interfaces/INTERFACE. I think making hook scripts aware of action (up/down) and interface, as well as maybe ESSID or whatever would be useful though, so if you have an idea on how that should work I think you should put in a feature request.

Last edited by bkhl (2013-07-21 18:23:23)

Offline

#6 2013-07-26 17:31:03

sxtynnmach1
Member
From: 127.0.0.1
Registered: 2009-10-31
Posts: 12

Re: [SOLVED] Netctl script execution order?

Added the feature request to the netctl github page.

Since the hooks/interface scripts are sourced instead of passed to a subshell, they have access to previously-defined variables. At the time of this writing, when netctl sources it's hooks and interface scripts the following are already available in the environment:

  • $interface (ex: wlan0)

  • $profile (ex: wlan0-essid)

  • $action (ex: CONNECT, see wpa_actiond --help)

  • $ssid

Following the convention of prepending two-digit numbers to my scripts to enforce execution order, I have gotten pretty fine-grained control over my scripts and netctl actions smile

/etc/netctl/hooks/10-proxy.sh
-----------------------------
#!/bin/sh
if [ "$profile" = "wlan0-companyESSID" ]
then
    case "$action" in
        "CONNECT"|"REESTABLISHED")
            export http_proxy="http://proxy.company.com:8080"
            ;;
        *)
            unset http_proxy
            ;;
    esac
fi

Hello Darkness, my old friend. I've come to talk with you again.

Offline

#7 2013-07-27 09:40:49

bkhl
Member
Registered: 2013-07-21
Posts: 6

Re: [SOLVED] Netctl script execution order?

Good to know. I don't think your proxy setting script will work like that though, since the environment variable will only be visible within the scope of the script.

Offline

#8 2013-07-27 09:43:21

sxtynnmach1
Member
From: 127.0.0.1
Registered: 2009-10-31
Posts: 12

Re: [SOLVED] Netctl script execution order?

I was intentionally setting the proxy that way :-)

I have another hook script later on that starts processes that pull http_proxy from the environment, if available.


Hello Darkness, my old friend. I've come to talk with you again.

Offline

Board footer

Powered by FluxBB