You are not logged in.

#1 2012-12-30 12:07:23

kpj
Member
Registered: 2012-12-30
Posts: 7

[systemd] network dependent starting of services

Hello,
normally it is possible to change to order/dependencies of services as described here.
Furthermore one can automatically connect with either Ethernet (net-auto-wired.service) or Wlan (net-auto-wireless.service) at boot.

Currently I enabled hostapd.service. However, I only want to start it, if I am connected with ethernet and not wlan.
If I am connected with wlan, i don't want to start hostapd.
And I want to automatically connect to ethernet, if it is available. Otherwise to a known wlan hotspot.

I don't really know how to solve that problem.
Thanks for any help,

kpj

Offline

#2 2012-12-30 12:24:01

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 14,787
Website

Re: [systemd] network dependent starting of services

To answer the question in the title of the thread, you probably want the "Requires=net-auto-wired.service" entry in hostpad.service.

Prioritizing wired over wireless would be configured in your network management.  Is this netcfg?


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#3 2012-12-30 12:25:02

kpj
Member
Registered: 2012-12-30
Posts: 7

Re: [systemd] network dependent starting of services

Thanks!

Yes I use netcfg.
Should I enable both "net-auto-wired.service" and "net-auto-wireless.service" at the same time?

Last edited by kpj (2012-12-30 12:30:00)

Offline

#4 2012-12-30 12:42:43

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 14,787
Website

Re: [systemd] network dependent starting of services

That I'm not sure of, which I why I only addressed the one part of the question - I've never used netcfg.


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#5 2012-12-30 14:09:18

kpj
Member
Registered: 2012-12-30
Posts: 7

Re: [systemd] network dependent starting of services

Oh okay, what do you use instead?

Offline

#6 2012-12-30 14:38:42

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 14,787
Website

Re: [systemd] network dependent starting of services

I don't use any network management tools.  Netcfg is what you would want for this.  I'm just not the one to advise how to configure it.

Last edited by Trilby (2012-12-30 14:39:21)


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#7 2012-12-30 16:58:23

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: [systemd] network dependent starting of services

With netcfg you can define commands being issued after the network is up and before it is down (and before it is up and after it is down works as well).
As an example, I have these two lines

POST_UP="/bin/su - army -l -c 'transmission-daemon --pid-file /tmp/transmission.pid'"
PRE_DOWN="killall -w transmission-daemon"

in both my profiles. The commands are being run as root, so you could insert something like

POST_UP="systemd start SERVICE.service"
PRE_DOWN="systemd stop SERVICE.service"

But I think this isn't a very nice solution wink This should also be possible within systemd with the options it provides.

Last edited by Army (2012-12-30 16:59:11)

Offline

#8 2012-12-30 22:35:06

kpj
Member
Registered: 2012-12-30
Posts: 7

Re: [systemd] network dependent starting of services

Thanks a lot for your help, even if it is not a "nice" solution ;-)
I'll definitely try it out!

POST_UP="systemctl start hostapd.service"

Last edited by kpj (2012-12-30 22:40:33)

Offline

#9 2012-12-30 23:01:23

Never
Member
Registered: 2008-07-01
Posts: 102

Re: [systemd] network dependent starting of services

The lines under [UNIT] here have been altered, been watching it in journalctl -b , it's doing exactly what I want it to and no one here seems to have anything negative to say about it, figure out where the services files are by doing systemctl status <service>.  Just make use of WANTS/AFTER as you need them. You probably need something like "AFTER=netcfg@eth0.service" in the unit of service you want to wait for eth0 to be up, whatever its profile name is.

Last edited by Never (2012-12-30 23:09:20)

Offline

Board footer

Powered by FluxBB