systemd unit for wpa_supplicant & dhclient on trisquel (Ubuntu)

4 risposte [Ultimo contenuto]
znavko
Offline
Iscritto: 06/11/2018

Hello! I cannot see networkmanager's slow work. I disabled NetworkManager and wpa__supplicant services this way:

# systemctl disable NetworkManager
# systemctl disable NetworkManager-wait-online
# systemctl disable wpa_supplicant

also I deleted dnsmasq for prevent possible errors.

I connect via wpa_supplicant & dhclient usig this config and this line:

# cat /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=sudo
update_config=1

network={
ssid="internet"
scan_ssid=1
psk=hashlonghash
proto=RSN
key_mgmt=WPA-PSK
}

# /sbin/wpa_supplicant -B -i wlp1s0 -c /etc/wpa_supplicant/wpa_supplicant.conf && /sbin/dhclient wlp1s0

Now I want to add this line to systemd. I created Unit that does not work:

# cat /etc/wpa_supplicant/wpa_supplicant_my.service
[Unit]
Description=Start WPA Supplicant and Dhclient
After=network.target

[Service]
Type=oneshot
ExecStart=/sbin/wpa_supplicant -B -i wlp1s0 -c /etc/wpa_supplicant/wpa_supplicant.conf && /sbin/dhclient wlp1s0
ExecStop=/usr/bin/killall -q wpa_supplicant && /usr/bin/killall -q dhclient
#RemainAfterExit=true
#TimeoutStartSec=5sec

[Install]
WantedBy=multi-user.target

# systemctl link /etc/wpa_supplicant/wpa_supplicant_my.service

# systemctl start wpa_supplicant_my.service
Job for wpa_supplicant_my.service failed because the control process exited with error code. See "systemctl status wpa_supplicant_my.service" and "journalctl -xe" for details.

# systemctl status wpa_supplicant
● wpa_supplicant_my.service - Start WPA Supplicant and Dhclient
Loaded: loaded (/etc/wpa_supplicant/wpa_supplicant_my.service; linked; vendor preset: enabled)
Active: failed (Result: exit-code) since Сб 2018-06-16 22:41:26 +03; 14s ago
Process: 1412 ExecStop=/usr/bin/killall -q wpa_supplicant && /usr/bin/killall -q dhclient (code=exited, status=1/FAILURE)
Process: 1409 ExecStart=/sbin/wpa_supplicant -B -i wlp1s0 -c /etc/wpa_supplicant/wpa_supplicant.conf && /sbin/dhclient wlp1s0 (code=exited, status=
Main PID: 1409 (code=exited, status=0/SUCCESS)

июн 16 22:41:26 asus systemd[1]: Starting Start WPA Supplicant and Dhclient...
июн 16 22:41:26 asus wpa_supplicant[1409]: Successfully initialized wpa_supplicant
июн 16 22:41:26 asus systemd[1]: wpa_supplicant_my.service: Control process exited, code=exited status=1
июн 16 22:41:26 asus systemd[1]: Failed to start Start WPA Supplicant and Dhclient.
июн 16 22:41:26 asus systemd[1]: wpa_supplicant_my.service: Unit entered failed state.
июн 16 22:41:26 asus systemd[1]: wpa_supplicant_my.service: Failed with result 'exit-code'.

# systemctl enable wpa_supplicant_my.service
Failed to execute operation: Too many levels of symbolic links

# /sbin/wpa_supplicant -B -i wlp1s0 -c /etc/wpa_supplicant/wpa_supplicant.conf && /sbin/dhclient wlp1s0
Successfully initialized wpa_supplicant

# ps -aux | grep -e wpa -e dhclient
root 1405 0.0 0.0 26108 3456 pts/0 T 22:41 0:00 systemctl status wpa_supplicant_my
root 1461 0.0 0.0 52476 3140 ? Ss 22:44 0:00 /sbin/wpa_supplicant -B -i wlp1s0 -c /etc/wpa_supplicant/wpa_supplicant.conf
root 1563 0.0 0.0 16124 860 ? Ss 22:44 0:00 /sbin/dhclient wlp1s0
root 1565 0.0 0.0 14188 928 pts/0 S+ 22:44 0:00 grep --color=auto -e wpa -e dhclient

# systemctl stop wpa_supplicant_my

# ps -aux | grep -e wpa -e dhclient
root 1405 0.0 0.0 26108 3456 pts/0 T 22:41 0:00 systemctl status wpa_supplicant_my
root 1461 0.0 0.0 52476 3140 ? Ss 22:44 0:00 /sbin/wpa_supplicant -B -i wlp1s0 -c /etc/wpa_supplicant/wpa_supplicant.conf
root 1563 0.0 0.0 16124 860 ? Ss 22:44 0:00 /sbin/dhclient wlp1s0
root 1569 0.0 0.0 14188 1092 pts/0 S+ 22:44 0:00 grep --color=auto -e wpa -e dhclient

Please, why it does not enable with error: Failed to execute operation: Too many levels of symbolic links ???
Why it does not kill processes when stops and why id does not start?

znavko
Offline
Iscritto: 06/11/2018

I solved this issue. I modified service script and it starts and stops in a proper way. So each command must have own line ExecStart, cannot use &&.
Also `enable` was not working cause needs to put service file to /lib/systemd/system/wpa_supplicant_my.service and then generate a link.

This is how to make service works:

# cat /lib/systemd/system/wpa_supplicant_my.service
[Unit]
Description=Start WPA Supplicant and Dhclient
After=network.target

[Service]
Type=oneshot
RemainAfterExit=yes

ExecStart=/sbin/wpa_supplicant -B -i wlp1s0 -c /etc/wpa_supplicant/wpa_supplicant.conf
ExecStart=/sbin/dhclient wlp1s0

ExecStop=/usr/bin/killall -q wpa_supplicant
ExecStop=/usr/bin/killall -q dhclient

#TimeoutStartSec=5sec

[Install]
WantedBy=multi-user.target

# systemctl link /lib/systemd/system/wpa_supplicant_my.service

# systemctl start wpa_supplicant_my.service

# systemctl enable wpa_supplicant_my.service

After reboot I have wifi.

# systemctl status wpa_supplicant_my.service
● wpa_supplicant_my.service - Start WPA Supplicant and Dhclient
Loaded: loaded (/lib/systemd/system/wpa_supplicant_my.service; enabled; vendo
Active: active (exited) since Сб 2018-06-16 23:27:02 +03; 6min ago
Process: 985 ExecStart=/sbin/dhclient wlp1s0 (code=exited, status=0/SUCCESS)
Process: 967 ExecStart=/sbin/wpa_supplicant -B -i wlp1s0 -c /etc/wpa_supplican
Main PID: 985 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/wpa_supplicant_my.service
├─ 984 /sbin/wpa_supplicant -B -i wlp1s0 -c /etc/wpa_supplicant/wpa_s
└─1221 /sbin/dhclient wlp1s0

июн 16 23:26:57 asus systemd[1]: Starting Start WPA Supplicant and Dhclient...
июн 16 23:26:57 asus wpa_supplicant[967]: Successfully initialized wpa_supplican
июн 16 23:26:58 asus root[998]: /etc/dhcp/dhclient-enter-hooks.d/avahi-autoipd r
июн 16 23:26:58 asus dhclient[985]: DHCPREQUEST of 192.168.1.68 on wlp1s0 to 255
июн 16 23:27:01 asus dhclient[985]: DHCPREQUEST of 192.168.1.68 on wlp1s0 to 255
июн 16 23:27:01 asus dhclient[985]: DHCPACK of 192.168.1.68 from 192.168.1.1
июн 16 23:27:02 asus dhclient[985]: bound to 192.168.1.68 -- renewal in 10977 se
июн 16 23:27:02 asus systemd[1]: Started Start WPA Supplicant and Dhclient.

----
The next question is: How to watch if wifi is broken and down and then make my service restarts?

Magic Banana

I am a member!

I am a translator!

Offline
Iscritto: 07/24/2010

I am no expert in writing unit files. However, I do not think the type "oneshot" is right here. Also, I believe services "After=network.target" expect wpa_supplicant (unless you never connect to an encrypted Wifi network... but, then, why not disabling wpa_supplicant?). You should read 'man systemd.service'. Also, what is wrong with /lib/systemd/system/wpa_supplicant.service (the default unit)?

znavko
Offline
Iscritto: 06/11/2018

In openrc my configuration was much simpler. I only wrote /etc/wpa_supplicant/wpa_supplicant.conf and added to openrc wpa_supplicand and dhcpcd services. So this worked without any actions from my side.

Systemd has lot of specific functions, adding services more difficult.

I tried 'Type=Simple' as somebody offered foo service in web and it did not work.

I tried also 'ExecStop=command1 && command2' and it caused the error when I stop the service.

Also I used this one I have seen in web 'WantedBy=multi-user.target' .

Magic Banana

I am a member!

I am a translator!

Offline
Iscritto: 07/24/2010

You should read 'man systemd.service'.