From: Stefan Schantl Date: Sun, 14 Apr 2013 12:17:35 +0000 (+0000) Subject: aiccu: Introduce support for systemd and add aiccu-config-helper. X-Git-Tag: 007~149 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfebc08f00717b872b49afc081ab6f2db3a81231;p=network.git aiccu: Introduce support for systemd and add aiccu-config-helper. Reference #10348. --- diff --git a/functions.aiccu b/functions.aiccu index 54bbdbf7..01213bee 100644 --- a/functions.aiccu +++ b/functions.aiccu @@ -19,60 +19,39 @@ # # ############################################################################### -function aiccu_config_dir() { - local device=${1} - - echo "${RUN_DIR}/aiccu/${device}" -} - function aiccu_start() { local device=${1} - shift - assert isset device - local config_dir=$(aiccu_config_dir ${device}) - mkdir -p ${config_dir} - - local config_file=${config_dir}/config - aiccu_configure ${device} $@ > ${config_file} - - aiccu start ${config_file} &>/dev/null + # Tell systemd to start aiccu on this device. + service_start "aiccu@${device}.service" local ret=$? - case "${ret}" in - 0) - log DEBUG "Aiccu was successfully started for '${device}'." - return ${EXIT_OK} - ;; - *) - error_log "Could not start aiccu properly for '${device}'." - - error_log "Configuration file dump:" - local line - while read line; do - error_log " ${line}" - done < ${config_file} - - return ${EXIT_ERROR} - ;; - esac + if [ ${ret} -eq ${EXIT_OK} ]; then + log DEBUG "aiccu was successfully started on '${device}'." + else + log ERROR "Could not start aiccu properly on '${device}': ${ret}" + return ${EXIT_ERROR} + fi + + return ${EXIT_OK} } function aiccu_stop() { local device=${1} - assert isset device - aiccu stop $(aiccu_config_dir ${device})/config - - rm -rf $(aiccu_config_dir ${device}) + # Tell sysemd to stop aiccu on this device. + service_stop "aiccu@${device}.service" } -function aiccu_configure() { +function aiccu_write_config() { local device=${1} + local file=${2} + shift 2 assert isset device + assert isset file local user local secret @@ -118,30 +97,38 @@ function aiccu_configure() { assert isset require_tls assert isoneof protocol tic tsp l2tp -cat < ${file} + + ( + print "# Server info" + print "server ${server}" + print "protocol ${protocol}" + print + + if isset tunnel_id; then + print "# Tunnel ID" + print "tunnel_id ${tunnel_id}" + print + fi + + print "# Credentials" + print "username ${user}" + print "password ${secret}" + print + + print "ipv6_interface ${device}" + print + + print "# Security" + print "requiretls ${require_tls}" + print + + # Misc. + print "verbose true" + print "daemonize false" + print "automatic true" + ) >> ${file} return ${EXIT_OK} } diff --git a/helpers/aiccu-config-helper b/helpers/aiccu-config-helper new file mode 100755 index 00000000..53800221 --- /dev/null +++ b/helpers/aiccu-config-helper @@ -0,0 +1,60 @@ +#!/bin/bash +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2013 IPFire Network Development Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +. /usr/lib/network/functions + +action="${1}" +assert isset action + +zone="${2}" +assert isset zone +assert zone_exists ${zone} + +config_file="${RUN_DIR}/${zone}/aiccu.conf" + +case "${action}" in + create) + # Create the configuration file for this zone. + zone_config_read ${zone} + + config_dir="$(dirname ${config_file})" + mkdir -p ${config_dir} + + aiccu_write_config ${zone} ${config_file} \ + --server="${SERVER}" \ + --protocol="${PROTOCOL}" \ + --user="${USER}" \ + --secret="${SECRET}" \ + --tunnel-id="${TUNNEL_ID}" \ + --require-tls="${REQUIRE_TLS}" + ;; + + remove) + rm -f ${config_file} + ;; + + *) + log ERROR "Unknown action passed: ${action}" + exit ${EXIT_ERROR} + ;; +esac + +exit ${EXIT_OK} diff --git a/hooks/zones/aiccu b/hooks/zones/aiccu index 66d7b382..05433b05 100755 --- a/hooks/zones/aiccu +++ b/hooks/zones/aiccu @@ -78,27 +78,19 @@ function _parse_cmdline() { function _up() { local zone=${1} - shift - assert isset zone - zone_config_read ${zone} - - aiccu_start ${zone} \ - --server="${SERVER}" \ - --protocol="${PROTOCOL}" \ - --user="${USER}" \ - --secret="${SECRET}" \ - --tunnel-id="${TUNNEL_ID}" \ - --require-tls="${REQUIRE_TLS}" + # Start aiccu on this zone. + aiccu_start ${zone} - exit $? + exit ${EXIT_OK} } function _down() { local zone=${1} - shift + assert isset zone + # Stop aiccu on this zone. aiccu_stop ${zone} exit ${EXIT_OK}