RASPI Archlinux SystemD issue

Ask questions about Arch Linux ARM. Please search before making a new topic.

RASPI Archlinux SystemD issue

Postby seza » Sat Dec 08, 2012 7:09 am

Hi all,
Great forum - thank you all for sharing your knowledge.
I have a startup issue using SystemD.
I have a shell script that starts HostAPD, NATing and DNSMASQ, when I start script manually it works fine but when I set it up to autostart during boot using [systemctl enable] it fails to start HostAPD, here are the files I am using:

--- the main script: /usr/lib/systemd/scripts/apstart ---

#!/bin/bash

# Enable NAT
iptables --flush
iptables --table nat --flush
iptables --delete-chain
iptables --table nat --delete-chain
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
iptables --append FORWARD --in-interface wlan0 -j ACCEPT
sleep 5
sysctl -w net.ipv4.ip_forward=1
sleep 5
ifconfig wlan0 down
hostapd -B /etc/hostapd/hostapd.conf
sleep 5
ifconfig wlan0 192.168.2.1 netmask 255.255.255.0
sleep 3
ifconfig wlan0 up
sleep 3
------------
--- Service file: /etc/systemd/system/apstart.service ---

[Unit]
Description=hostapd start

[Service]
ExecStart=/usr/lib/systemd/scripts/apstart 1>/dev/null

[Install]
WantedBy=multi-user.target
---------
seza
 
Posts: 13
Joined: Sat Dec 08, 2012 6:51 am

Re: RASPI Archlinux SystemD issue

Postby pepedog » Sat Dec 08, 2012 11:02 am

No going to try to answer straight away, and can understand why tinkering to get the order of things just right, but a few questions first
Bridge is so much easier to set up, is there a need for firwall, or fixed ip addresses needed? Bridge takes minutes to set up.
Are you using say netcfg to bring up interfaces? You can stuff things in the /etc/network.d/ file, eg
POST_UP="sleep 5 && ifconfig wlan0 up"
And there is PRE_UP to use as well
iptables save should save everything in /etc/iptables/iptables.rules then systemctl enable iptables takes care of that
So then this will take care of things
systemctl enable hostapd iptables netcfg

I don't think sysctl -w net.ipv4.ip_forward=1 is required any more, I think it's default, check with
cat /proc/sys/net/ipv4/ip_forward
Or edit /etc/sysctl.conf
pepedog
Developer
 
Posts: 2431
Joined: Mon Jun 07, 2010 3:30 pm
Location: London UK

Re: RASPI Archlinux SystemD issue

Postby moonman » Sat Dec 08, 2012 11:33 am

If you still want the service after what pepedog suggested, try this:

$this->bbcode_second_pass_code('', '
[Unit]
Description=hostapd start

[Service]
User=root
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/sh /usr/lib/systemd/scripts/apstart 1>/dev/null


[Install]
WantedBy=multi-user.target')

Try /bin/bash if /bin/sh doesn't work
Pogoplug V4 | GoFlex Home | Raspberry Pi 4 4GB | CuBox-i4 Pro | ClearFog | BeagleBone Black | Odroid U2 | Odroid C1 | Odroid XU4
-----------------------------------------------------------------------------------------------------------------------
[armv5] Updated U-Boot | [armv5] NAND Rescue System
moonman
Developer
 
Posts: 3388
Joined: Sat Jan 15, 2011 3:36 am

Re: RASPI Archlinux SystemD issue

Postby seza » Sat Dec 08, 2012 12:56 pm

Thank you both,
Please bear with me, I am bit newbie - used to the GUI on Windows/Ubunto.

Pepedog, I am interested in your idea, could you please elaborate bit more
as to what I need to do step by step - plz include scripts and paths etc ...
there is no need for firewall or fixed IP's - am not using NetCFG.

(bit of background ... this is a Raspberry PI running Linux alarmpi 3.2.27-17-ARCH,
connected via Eth0 to the Internet and via USB to an Alfa wireless apdtr,
what I hope to achieve is run HostAPD on the Pi to distribute the Internet to WIFI clients)

the simplest way to achieve that is the best.
seza
 
Posts: 13
Joined: Sat Dec 08, 2012 6:51 am

Re: RASPI Archlinux SystemD issue

Postby pepedog » Sat Dec 08, 2012 4:50 pm

I hope I got all this for bridge
pacman -S crda netcfg hostapd
$this->bbcode_second_pass_code('', 'nano /etc/network.d/bridge
paste this
INTERFACE="br0"
CONNECTION="bridge"
DESCRIPTION="Bridge wired and wireless connection"
# Only add wired interface here, hostapd will add wireless
BRIDGE_INTERFACES="eth0"
IP="dhcp"')
$this->bbcode_second_pass_code('', 'nano etc/conf.d/netcfg
just change this line
NETWORKS=(bridge)
')
$this->bbcode_second_pass_code('', '/etc/hostapd/hostapd.conf
interface=wlan0
bridge=br0
driver=nl80211
logger_stdout=-1
logger_stdout_level=2
ssid=mypiap
hw_mode=g
channel=9
auth_algs=3
max_num_sta=5
wpa=2
wpa_passphrase=mypassord8charsormore
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
rsn_pairwise=CCMP')
$this->bbcode_second_pass_code('', 'nano /etc/conf.d/wireless-regdom
edit uncomment your country')
$this->bbcode_second_pass_code('', 'rm /etc/systemd/system/multi-user.target.wants/dhcpcd\@eth0.service
systemctl enable netcfg hostapd
sync
reboot')
pepedog
Developer
 
Posts: 2431
Joined: Mon Jun 07, 2010 3:30 pm
Location: London UK

Re: RASPI Archlinux SystemD issue

Postby seza » Sat Dec 08, 2012 7:00 pm

Many thanks Pepedog,
I will give that try and report back.
also Moonman - thank you, your suggestion worked beautifully.
seza
 
Posts: 13
Joined: Sat Dec 08, 2012 6:51 am


Return to User Questions

Who is online

Users browsing this forum: No registered users and 8 guests