You are not logged in.
Pages: 1
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
FWIW, I use the same method to get things stopped or started with netctl, one time config, no big deal..
Offline
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
Haven't used hooks or interfaces, but try, and let us know if it works
Offline
Haven't used hooks or interfaces, but try, and let us know if it works
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
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
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
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
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
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
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
Pages: 1