1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/hotspot_ynh.git synced 2024-09-03 19:25:53 +02:00

custom systemd config for hostapd to handle multiple instances

This commit is contained in:
HgO 2023-08-21 16:17:22 +02:00
parent 676e6d9733
commit d6b5dc62c5
9 changed files with 47 additions and 14 deletions

View file

@ -0,0 +1,21 @@
[Unit]
Documentation=man:systemd-sysv-generator(8)
SourcePath=/etc/init.d/hostapd
Description=LSB: Advanced IEEE 802.11 management daemon
After=remote-fs.target
After=network-online.target
Wants=network-online.target
[Service]
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
SuccessExitStatus=5 6
Environment=DAEMON_CONF=/etc/hostapd/hostapd-%i.conf
ExecStart=/etc/init.d/hostapd start
ExecStop=/etc/init.d/hostapd stop
ExecReload=/etc/init.d/hostapd reload

View file

@ -63,7 +63,7 @@ is_dhcpd4_running() {
}
is_hostapd_running() {
systemctl is-active hostapd &>/dev/null
systemctl is-active "hostapd@${wifi_device}" &>/dev/null
}
is_running() {
@ -206,7 +206,7 @@ stop_dhcpd() {
}
stop_hostapd() {
systemctl stop hostapd
systemctl stop "hostapd@${wifi_device}"
}
if [ "$1" != restart ]; then
@ -275,7 +275,7 @@ start)
configure_hostapd
echo "Starting hostapd..."
if ! systemctl start hostapd; then
if ! systemctl start "hostapd@${wifi_device}"; then
journalctl -u hostapd -n 100 --no-hostname --no-pager
exit 1
fi

View file

@ -41,7 +41,7 @@ ynh_print_info --message="Declaring files to be backed up..."
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="/etc/hostapd/hostapd.conf"
ynh_backup --src_path="/etc/hostapd/hostapd.conf.tpl"
ynh_backup --src_path="/etc/hostapd/hostapd-${wifi_device}.conf"
ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl"

View file

@ -181,6 +181,7 @@ set__dns() {
# OVERWRITING APPLY STEP
#=================================================
ynh_app_config_apply() {
old_wifi_device=$(ynh_app_setting_get $app wifi_device)
# Stop vpn client
ynh_print_info --message="Stopping hotspot in order to edit files"
@ -194,7 +195,11 @@ ynh_app_config_apply() {
local sec_comment="#"
fi
ynh_add_config --template="/etc/hostapd/hostapd.base.conf" --destination="/etc/hostapd/hostapd-${wifi_device}.conf"
ynh_secure_remove --file="/etc/hostapd/hostapd-${old_wifi_device}.conf"
ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${old_wifi_device}.conf"
ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${old_wifi_device}.conf"
ynh_add_config --template="/etc/hostapd/hostapd.conf.tpl" --destination="/etc/hostapd/hostapd-${wifi_device}.conf"
ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf"
if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then

View file

@ -158,7 +158,7 @@ ynh_script_progression --message="Copying configuration files..."
mkdir -pm 0755 /etc/dnsmasq.dhcpd/
chown root: /etc/dnsmasq.dhcpd/
install -b -o root -g root -m 0644 ../conf/hostapd.*.conf /etc/hostapd/
install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/hostapd.conf.tpl
install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl
install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl
@ -179,14 +179,8 @@ install -o root -g root -m 0755 ../conf/openvpn_90-hotspot /etc/openvpn/scripts/
ynh_script_progression --message="Configuring hostapd..."
## hostapd
ynh_replace_string --match_string="^DAEMON_CONF=$" --replace_string="&/etc/hostapd/hostapd.conf" --target_file=/etc/init.d/hostapd
ynh_store_file_checksum --file="/etc/init.d/hostapd"
# We also need to put this in /etc/default/hostapd because on some setup
# like RPi, the version of hostapd is different and /etc/init.d/hostapd
# isnt used ... instead the service is "pure systemd" ...
echo "DAEMON_CONF=/etc/hostapd/hostapd.conf" > /etc/default/hostapd
# Set default inits
# The boot order of these services are important, so they are disabled by default
# and the ynh-hotspot service handles them.
@ -201,6 +195,8 @@ ynh_script_progression --message="Configuring a systemd service..."
# Create a dedicated systemd config
ynh_add_systemd_config --service=$service_name
# Create custom systemd config for hostapd to handle multiple wifi devices
ynh_add_systemd_config --service="hostapd@.service" --template="../conf/systemd_hostapd.service"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST

View file

@ -73,7 +73,7 @@ ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${wifi_device}.conf"
ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl"
ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf"
ynh_secure_remove --file="/etc/hostapd/hostapd.conf"
ynh_secure_remove --file="/etc/hostapd/hostapd.conf.tpl"
ynh_secure_remove --file="/etc/hostapd/hostapd-${wifi_device}.conf"
#=================================================

View file

@ -62,7 +62,7 @@ else
pkg_dependencies="$pkg_dependencies $free_firmware_packages"
fi
ynh_restore_file --origin_path="/etc/hostapd/hostapd.conf"
ynh_restore_file --origin_path="/etc/hostapd/hostapd.conf.tpl"
ynh_restore_file --origin_path="/etc/hostapd/hostapd-${wifi_device}.conf"
ynh_restore_file --origin_path="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl"

View file

@ -120,6 +120,15 @@ if [[ -n ${multissid} ]]; then
ynh_app_setting_delete --app=$app --key=multissid
fi
ynh_secure_remove --file="/etc/hostapd/hostapd.conf"
ynh_secure_remove --file="/etc/hostapd/hostapd.base.conf"
ynh_secure_remove --file="/etc/hostapd/hostapd.accesspoint.conf"
for FILE in $(ls /etc/dnsmasq.dhcpd/dhcpdv{4,6}-ssid{0..3}.conf 2>/dev/null); do
ynh_secure_remove --file="$FILE"
ynh_secure_remove --file="$FILE"
done
# Old stuff prior to 2.x
ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net)
@ -203,6 +212,8 @@ ynh_script_progression --message="Upgrading systemd configuration..."
# Create a dedicated systemd config
ynh_add_systemd_config --service=$service_name
# Create custom systemd config for hostapd to handle multiple wifi devices
ynh_add_systemd_config --service="hostapd@.service" --template="../conf/systemd_hostapd.service"
#=================================================
# GENERIC FINALIZATION