Skip to content

howto - arch linux migrate rc.local to systemd unit (wpa_supplicant based wlan)

So, you have migrated your arch linux to systemd and your beloved rc.local is not executed anymore? Time to jump into the systemd by writing your own unit. You have two options. One would be to write a unit that simple executes the rc.local. The second option would be to split up your rc.local into logical parts and write one unit per logical part (like "setup [w]lan, mount filesystems, start service xyz").

I want to provide you a way to implement the second solution. I can tell you, after you have written your first systemd unit, the concept of systemd won't be that big alien in you mind. I still have a tear drop in my eyes when i think back to my "only two files to configure my system"-systemV times, but thats nothing for this blog entry ;-).

So lets go and write a systemd unit to start up your wlan interface by using wpa_supplicant and dhcpd. We have to split this task into two steps. First we create the systemd service which determines when and how our real script should be handled. The second step includes writing of the script that contains the "real work". First step - writing the systemd service

vim lib/systemd/system/wlan_wpa_supplicant.service
[Unit] Description="something usefull in here" #the service file is a wrapper. the real action is done in the on the following line (should be set with +x) ConditionPathExists=/my/path/to/the/execute/script #two example targets below Before=network.target Wants=network.target [Service] #we only want to execute a script by the service - fire and forget - one shot only ;-) Type=oneshot RemainAfterExit=yes KillMode=none #the following two lines define what should happen when the service is started or stopped ExecStart=/my/path/to/the/execute/script start ExecStop=/my/path/to/the/execute/script stop [Install] WantedBy=multi-user.target
Second step - write the bashscript
vim /etc/wlan_wpa_supplicant_service
#!/bin/bash case "$1" in "start") wpa_supplicant -B -D wext -i wlan0 -c /etc/wpa_supplicant.conf sleep 3 dhcpcd -b wlan0 ;; "stop") dhcpd wlan0 --exit ;; esac exit 0
Now, we only have to enable this service.
sudo systemctl enable wlan_wpa_supplicant.service
And thats it, try a reboot and enjoy your first systemd service :-).

Links Example on github.com Writing custom service files man systemd.service wiki.gentoo.org

Trackbacks

Keine Trackbacks

Kommentare

Ansicht der Kommentare: Linear | Verschachtelt

Noch keine Kommentare

Kommentar schreiben

Die angegebene E-Mail-Adresse wird nicht dargestellt, sondern nur für eventuelle Benachrichtigungen verwendet.
Um einen Kommentar hinterlassen zu können, erhalten Sie nach dem Kommentieren eine E-Mail mit Aktivierungslink an ihre angegebene Adresse.

Um maschinelle und automatische Übertragung von Spamkommentaren zu verhindern, bitte die Zeichenfolge im dargestellten Bild in der Eingabemaske eintragen. Nur wenn die Zeichenfolge richtig eingegeben wurde, kann der Kommentar angenommen werden. Bitte beachten Sie, dass Ihr Browser Cookies unterstützen muss, um dieses Verfahren anzuwenden.
CAPTCHA

Markdown-Formatierung erlaubt
Formular-Optionen