You are not logged in.
Pages: 1
Okay so i want to automatically try to connect to my local (home) wifi on startup.
I wrote a script which get's executed at startup (via service)
The script:
#!/bin/bash
# connect to wifi
wpa_supplicant -B -c /etc/wpa_supplicant/wifi-name.conf -i wlp4s0
dhcpcdThis script works perfectly fine when I execute it with root during runtime.
But it doesn't work for some reason on startup. (I also tried to work around it with a sleep command which also didn't work)
Does anybody know maybe why it doesn't work?
A workaround would also be okay.
Thanks in advance!
Last edited by Stefan_xyz (2019-09-02 11:11:33)
Offline
What you are trying to do is "a workaround". What you want is to enable a systemd service.
Moving to NC...
Offline
What you are trying to do is "a workaround". What you want is to enable a systemd service.
The script get's already called and executed during startup via a systemd service (self written). The service is also enabled.
I know this because I execute other commands also in this script.
Offline
While that might be true it's unclear whether your service file does the right things. The packages in question do come with properly defined services that would not need you to try and reinvent the wheel: https://wiki.archlinux.org/index.php/WP … _(systemd)
If you actually want to fix this in your own hack (which you frankly probably shouldn't...) you might want to post your service file.
Last edited by V1del (2019-09-02 08:38:44)
Online
While that might be true it's unclear whether your service file does the right things. The packages in question do come with properly defined services that would not need you to try and reinvent the wheel: https://wiki.archlinux.org/index.php/WP … _(systemd)
If you actually want to fix this in your own hack (which you frankly probably shouldn't...) you might want to post your service file.
The service file:
[Unit]
Description=Starts a script at startup
[Service]
ExecStart=/scripts/startup.sh
[Install]
WantedBy=multi-user.targetI enabled wpa_supplicant but it doesn't change anything.
Offline
That's an insufficient service file for something that's supposed to handle network hardware, just stop this and use existing services, or at least read them to see what you're missing.
I enabled wpa_supplicant but it doesn't change anything.
That's not an error message what exactly, which command, did you enable, and did you enable a corresponding dhcpcd service too?
Which instructions did you follow to install Arch?
Last edited by V1del (2019-09-02 08:57:50)
Online
That's an insufficient service file for something that's supposed to handle network hardware, just stop this and use existing services, or at least read them to see what you're missing.
Hmm i don't quite see how this is inusfficient since it executes my script at startup and all further commands get executed in this script so I'm perfectly fine with it. (And the service execute the script!!!)
That's not an error message what exactly, which command, did you enable, and did you enable a corresponding dhcpcd service too?
As you see in the script posted i set of an corresponding dhcpcd service.
I logged the outputs:
dhcpd "error" (no standard output):
dev: loaded udev
no interfaces have a carrier
forked to background, child pid 923wpa_supplicant log (no error):
Successfully initialized wpa_supplicantBut the script works fine during runtime. It also get's executed during startup. It just doesn't work during startup (or it works but the settings get reset)
Which instructions did you follow to install Arch?
I followed the standard installtation guide
Offline
Your script runs too soon, without any attempt to wait for network hardware to be available. You will at the very least want a Wants=network.target and After=network.target
But this is likely to break in subtle ways with things that expect the proper systemd services to be invoked, you should simply enable these directly and not try to reinvent the ordering wheel systemd cleanly solves.
Which is what I refered to when I told you to tell me the exact command, because the section i linked to lists several.
Also FWIW
systemctl status startup.service #Or whatever the actual name isOnline
Your script runs too soon, without any attempt to wait for network hardware to be available. You will at the very least want a Wants=network.target and After=network.target
I implemented a sleep command (used them before but also didn't work) which is ends well after i logged into my user. I get again the same ("error") messages.
But this is likely to break in subtle ways with things that expect the proper systemd services to be invoked, you should simply enable these directly and not try to reinvent the ordering wheel systemd cleanly solves.
In what way breaking? (Does this also apply to my "sleep-solution"?
Which is what I refered to when I told you to tell me the exact command, because the section i linked to lists several.
I don't understand what you mean with that. Do you need more information? Or what?
Offline
V1del wrote:Your script runs too soon, without any attempt to wait for network hardware to be available. You will at the very least want a Wants=network.target and After=network.target
I implemented a sleep command (used them before but also didn't work) which is ends well after i logged into my user. I get again the same ("error") messages.
I'd assume the actual error here being that you let dhcpcd fork off, systemd runs the service, your bash shell exits successfully, and systemd cleans up any resulting child processes. If you want to actually work with forking services you'd need to define type=forking in your service file. Just as the proper and already existing systemd services for dhcpcd do.
In what way breaking? (Does this also apply to my "sleep-solution"?
There might be services that utilize information system services supply as to when the connection is up or similar, which they can't ask for, since logically you aren't running the actual service files. Will in this particular case likely not be as problematic as it could be, but still.
That said, ignore your own service file, follow the link I posted (if you want to explicitly enable on an interface make sure you rename your config file to the outlined template, enable the relevant dhcpcd service on the chosen interface) post the commands you are using to accomplish this. Should it still not work on reboot post the complete output of
sudo journalctl -b > journal.log
systemctl list-unit-files --state enabled
#If you still intend to use that interface, these should be your enabled services
systemctl status wpa_supplicant@wlp4s0
systemctl status dhcpcd@wlp4s0Last edited by V1del (2019-09-02 10:47:31)
Online
I'd assume the actual error here being that you let dhcpcd fork off, systemd runs the service, your bash shell exits successfully, and systemd cleans up any resulting child processes. If you want to actually work with forking services you'd need to define type=forking in your service file. Just as the proper and already existing systemd services for dhcpcd do.
There might be services that utilize information system services supply as to when the connection is up or similar, which they can't ask for, since logically you aren't running the actual service files. Will in this particular case likely not be as problematic as it could be, but still.
Okay i see thanks for the explanation
That said, ignore your own service file, follow the link I posted (if you want to explicitly enable on an interface make sure you rename your config file to the outlined template, enable the relevant dhcpcd service on the chosen interface) post the commands you are using to accomplish this. Should it still not work on reboot post the complete output of
Okay yeah it worked. THANKS!
For those interested:
I enabled the wpa_supplicant@interface.service and renamed my wpa_supplicant file (which i named "SSID.conf") to "wpa_supplicant-interface.conf
I also enabled an dhcpcd@interface.servcie to get an IP-Addr.
For me Information: here . Source from V1del
Offline
Pages: 1