You are not logged in.

#1 2014-08-17 14:58:55

captaincurrie
Member
From: /dev/random
Registered: 2013-11-01
Posts: 82

[Solved] netctl and network-online.target

Hello,

When a connection is acheived I want netctl to start the systemd network-online.target, and
when a connection is dropped, i want netctl to stop it.

I understand i could add the lines

ExecUpPost=systemctl start network-online.target
ExecDownPre=systemctl stop network-online.target	

To all my profiles, but that seems a little sloppy to me. Is there any way
to do it all in one go?

Also, i'm open to other ways to order the starting/stopping of services after the network has
come up/down.

Thanks.

Last edited by captaincurrie (2014-12-26 14:54:18)

Offline

#2 2014-08-17 16:14:00

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: [Solved] netctl and network-online.target

FWIW, I use the same method to get things stopped or started with netctl, one time config, no big deal..

Offline

#3 2014-08-17 17:31:06

captaincurrie
Member
From: /dev/random
Registered: 2013-11-01
Posts: 82

Re: [Solved] netctl and network-online.target

qinohe wrote:

FWIW, I use the same method to get things stopped or started with netctl, one time config, no big deal..

Thanks. I guess its not that bad....:P

Still, netctl provides hooks, scripts that are read whenever
a profile is read. It seems like an obivous feature to have the same thing
when a connection is achieved/dropped

Like have subdirectories /etc/netctl/hooks/up and /etc/netctl/hooks/down
that are parsed when a connection is achieved/dropped

Last edited by captaincurrie (2014-08-17 17:32:30)

Offline

#4 2014-08-17 18:34:06

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: [Solved] netctl and network-online.target

Haven't used hooks or interfaces, but try, and let us know if it works wink

Offline

#5 2014-08-17 19:12:23

captaincurrie
Member
From: /dev/random
Registered: 2013-11-01
Posts: 82

Re: [Solved] netctl and network-online.target

qinohe wrote:

Haven't used hooks or interfaces, but try, and let us know if it works wink

It doesn't work for what i want. Scripts are only read when the profile is read.

So the script is still read if the connection fails.

Offline

#6 2014-11-28 12:20:21

lah
Member
Registered: 2014-08-26
Posts: 28

Re: [Solved] netctl and network-online.target

Hi captaincurrie,

Here are some useful links about this issue :
http://www.freedesktop.org/wiki/Softwar … orkTarget/
http://unix.stackexchange.com/questions … as-started

I've added

ExecUpPost='date > /tmp/netctl_up.log; systemctl start network-online.target'
ExecDownPre='systemctl stop network-online.target'

to my netctl profile. And I've added thes dependencies to a unit (smbnetfs) requiring network :

Wants=network-online.target
After=network-online.target

Here are results :

Wifi connected at
Fri Nov 28 13:04:02 CET 2014

sudo systemctl status network-online.target
* network-online.target - Network is Online
   Loaded: loaded (/usr/lib/systemd/system/network-online.target; static)
   Active: active since Fri 2014-11-28 13:03:34 CET; 2min 50s ago
     Docs: man:systemd.special(7)
           http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget

sudo systemctl status smbnetfs             
* smbnetfs.service - Mount Samba Shares
   Loaded: loaded (/usr/lib/systemd/system/smbnetfs.service; enabled)
  Drop-In: /etc/systemd/system/smbnetfs.service.d
           `-launch_after_network.conf
   Active: active (running) since Fri 2014-11-28 13:03:34 CET; 3min 14s ago
 Main PID: 220 (smbnetfs)
   CGroup: /system.slice/smbnetfs.service
           |-220 /usr/bin/smbnetfs -f -o allow_other /mnt/smbnet
           `-232 /usr/bin/smbnetfs -f -o allow_other /mnt/smbnet

Nov 28 13:03:34 a4h-rpi-arch systemd[1]: Started Mount Samba Shares.
Nov 28 13:03:36 a4h-rpi-arch smbnetfs[220]: WARNING: Unknown libsmbclient version: 4.1.13
Nov 28 13:03:36 a4h-rpi-arch smbnetfs[220]: SMBNetFS may not work as expected.

As I understand, network-online.target is pulled by smbnetfs but at this time network is already up. But in reality, connection was really up when commands in ExecUpPost havec been executed i.e. 28s after.
So,

ExecUpPost='systemctl start network-online.target'

is useless, isn't it?

I think solution is to add a netctl-wait-online.service executed in ExecUpPost and including

Before=network-online.target

lah

Offline

#7 2014-11-28 13:15:28

lah
Member
Registered: 2014-08-26
Posts: 28

Re: [Solved] netctl and network-online.target

I've added following unit :

[Unit]
Description=Wait for Network to be Configured
DefaultDependencies=no
Conflicts=shutdown.target
Requisite=netctl-auto@wlan0.service
After=netctl-auto@wlan0.service
Before=network-online.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/echo wireless connection up
ExecStop=/usr/bin/echo wireless connection down

[Install]
WantedBy=network-online.target

and I start this unit in

ExecUpPost='date > /tmp/toto; systemctl start netctl-wait-online.service'

Here are results :

sudo systemctl status netctl-wait-online.service
[sudo] password for remi: 
* netctl-wait-online.service - Wait for Network to be Configured
   Loaded: loaded (/etc/systemd/system/netctl-wait-online.service; disabled)
   Active: active (exited) since Fri 2014-11-28 13:51:35 CET; 1min 2s ago
  Process: 284 ExecStart=/usr/bin/echo wireless connection up (code=exited, status=0/SUCCESS)
 Main PID: 284 (code=exited, status=0/SUCCESS)

Nov 28 13:51:35 a4h-rpi-arch echo[284]: wireless connection up
Nov 28 13:51:35 a4h-rpi-arch systemd[1]: Started Wait for Network to be Configured.


sudo systemctl status smbnetfs                  
* smbnetfs.service - Mount Samba Shares
   Loaded: loaded (/usr/lib/systemd/system/smbnetfs.service; enabled)
  Drop-In: /etc/systemd/system/smbnetfs.service.d
           `-launch_after_network.conf
   Active: active (running) since Fri 2014-11-28 13:51:06 CET; 1min 45s ago
 Main PID: 219 (smbnetfs)
   CGroup: /system.slice/smbnetfs.service
           |-219 /usr/bin/smbnetfs -f -o allow_other /mnt/smbnet
           `-231 /usr/bin/smbnetfs -f -o allow_other /mnt/smbnet

Nov 28 13:51:06 a4h-rpi-arch systemd[1]: Started Mount Samba Shares.
Nov 28 13:51:08 a4h-rpi-arch smbnetfs[219]: WARNING: Unknown libsmbclient version: 4.1.13
Nov 28 13:51:08 a4h-rpi-arch smbnetfs[219]: SMBNetFS may not work as expected.

sudo systemctl status network-online.target
* network-online.target - Network is Online
   Loaded: loaded (/usr/lib/systemd/system/network-online.target; static)
   Active: active since Fri 2014-11-28 13:51:06 CET; 2min 33s ago
     Docs: man:systemd.special(7)
           http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget

Nov 28 13:51:06 a4h-rpi-arch systemd[1]: Starting Network is Online.
Nov 28 13:51:06 a4h-rpi-arch systemd[1]: Reached target Network is Online.

I think I missed something... network-online.target has been active before netctl-wait-online.service but I wrote Before=network-online.target in  netctl-wait-online.service ...
Any help would be suggested.

lah

Offline

#8 2014-11-28 17:59:33

captaincurrie
Member
From: /dev/random
Registered: 2013-11-01
Posts: 82

Re: [Solved] netctl and network-online.target

Hey Iah,

Will get back to you soon. Thanks for the reply as i have not yet found a satisfiable solution.

It seems to me that at this point, any solution will be 'hacky'.

It should be properly handled by netctl itself. That is there should be a netctl-online.target which is started/stopped
whenever netctl itself knows its online or not. Or something like that. I'm a big noob when it comes to the details of networking...

Offline

#9 2014-12-14 21:34:10

captaincurrie
Member
From: /dev/random
Registered: 2013-11-01
Posts: 82

Re: [Solved] netctl and network-online.target

Hey,

Here is a dirty hack....

Use the ExecStartPre option in your service files to run a bash script which checks for a connection. If this script fails, the unit fails....

For example:

[Unit]
Description=Getmail

[Service]
ExecStartPre=%h/bin/connected
ExecStart=%h/bin/getmail

Can this be generalized in any way?

Offline

#10 2014-12-16 12:43:22

captaincurrie
Member
From: /dev/random
Registered: 2013-11-01
Posts: 82

Re: [Solved] netctl and network-online.target

Here is a possible solution (possible because i can't get it to work, but the concept is nice)

User a systemd path unit to monitor certain files in the proc filesystem related to networking.

For example, i've been trying this

[Unit]
Description=Monitor Network Change

[Path]
PathChanged=/proc/net/arp

With the corresponding service unit

[Unit]
Description=Check Network Status

[Service]
Type=oneshot
ExecStart=%h/bin/connected

Where connected is a script that checks for a connection, then starts or stop the network-online.target if there is a connection or not.

Sounds good doesnt it!

I also tried hooking up the failure of network-check.service to stop network-online.target, but i can't do that for someone reason.

Anyways. This should work based on the systemd manual, but the path unit never seems to get activated. No idea why. Gonna try
and communicate this upstream.

Offline

#11 2014-12-26 14:53:56

captaincurrie
Member
From: /dev/random
Registered: 2013-11-01
Posts: 82

Re: [Solved] netctl and network-online.target

Alright, i misunderstood hooks! They are not explained well in the manual!!!!

See the arch wiki (i updated it myself)
https://wiki.archlinux.org/index.php/Netctl#Using_hooks

Offline

Board footer

Powered by FluxBB