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?

Reply via email to