Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Projets publics
puppet-freeradius
Commits
12dab8c2
Commit
12dab8c2
authored
May 14, 2021
by
Nathan Ward
Browse files
Add radsniff support for Debian-like OSes and specifying envfile and pidfile to support any OS
parent
b2714c80
Changes
4
Hide whitespace changes
Inline
Side-by-side
manifests/params.pp
View file @
12dab8c2
...
...
@@ -172,4 +172,14 @@ class freeradius::params {
}
$radacctdir
=
"
\$
{logdir}/radacct"
# Default radsniff environment file location
$fr_radsniff_envfile
=
$::osfamily
?
{
'RedHat'
=>
'/etc/sysconfig/radsniff'
,
'Debian'
=>
'/etc/defaults/radsniff'
,
default
=>
undef
,
}
# Default radsniff pid file location
$fr_radsniff_pidfile
=
"/var/run/
${fr_service}
/radsniff.pid"
}
manifests/radsniff.pp
View file @
12dab8c2
# @summary configure and run radsniff
#
# @param envfile path to the environment file, used by the systemd unit
# @param options commandline options passed to radsniff when it runs
# @param
class
freeradius::radsniff
(
Optional
[
String
]
$envfile
=
undef
,
String
$options
=
''
,
)
{
Optional
[
String
]
$pidfile
=
undef
,
)
inherits
freeradius::params
{
unless
$::freeradius::utils_support
{
fail
(
'freeradius::radsniff requires freeradius have utils_support enabled'
)
}
unless
$facts
[
'os'
][
'family'
]
==
'RedHat'
{
fail
(
'freeradius::radsniff only supports RedHat like OSes at the moment'
)
# Calculate the envfile to use - specified, then calculated, then error if none
if
$envfile
{
$final_envfile
=
$envfile
}
else
{
if
$freeradius::fr_radsniff_envfile
{
$final_envfile
=
$freeradius::fr_radsniff_envfile
}
else
{
fail
(
'freeradius::radsniff requires envfile to be explicitly set on this OS'
)
}
}
# Calculate the pidfile to use - specified, then calculated, then error if none
if
$pidfile
{
$final_pidfile
=
$pidfile
}
else
{
if
$freeradius::fr_radsniff_pidfile
{
$final_pidfile
=
$freeradius::fr_radsniff_pidfile
}
else
{
fail
(
'freeradius::radsniff requires pidfile to be explicitly set on this OS'
)
}
}
$escaped_cmd
=
$options
.
regsubst
(
'"'
,
'\\\\"'
,
'G'
)
file
{
'/etc/sysconfig/radsniff'
:
file
{
$envfile
:
content
=>
@
(
"SYSCONFIG"
),
RADSNIFF_OPTIONS
=
"
${escaped_cmd}
"
|
SYSCONFIG
...
...
spec/classes/radsniff.rb
View file @
12dab8c2
...
...
@@ -13,6 +13,14 @@ describe 'freeradius::radsniff' do
}
end
if
os_facts
[
:osfamily
]
=~
%r{^RedHat|Debian$}
it
do
is_expected
.
to
contain_service
(
'radsniff'
)
.
with_ensure
(
'running'
)
.
with_enable
(
true
)
end
end
case
os_facts
[
:osfamily
]
when
'RedHat'
it
do
...
...
@@ -23,19 +31,63 @@ describe 'freeradius::radsniff' do
end
it
do
is_expected
.
to
contain_service
(
'radsniff'
)
.
with_ensure
(
'running'
)
.
with_enable
(
true
)
is_expected
.
to
contain_systemd__unit_file
(
'radsniff.service'
)
.
with_content
(
%r{^Pidfile=/var/run/radiusd/radsniff.pid$}
)
.
with_content
(
%r{^EnvironmentFile=/etc/sysconfig/radsniff$}
)
.
with_content
(
%r{^ExecStart=/usr/bin/radsniff -P /var/run/radiusd/radsniff.pid -d /etc/raddb $RADSNIFF_OPTIONS$}
)
.
that_notifies
(
'Service[radsniff]'
)
end
when
'Debian'
it
do
is_expected
.
to
contain_file
(
'/etc/defaults/radsniff'
)
.
with_content
(
%r{RADSNIFF_OPTIONS="radsniff cmd
\\
"line
\\
" options"}
)
.
that_notifies
(
'Service[radsniff]'
)
.
that_requires
(
'Package[freeradius-utils]'
)
end
it
do
is_expected
.
to
contain_systemd__unit_file
(
'radsniff.service'
)
.
with_source
(
'puppet:///modules/freeradius/radsniff.service'
)
.
with_content
(
%r{^Pidfile=/var/run/freeradius/radsniff.pid$}
)
.
with_content
(
%r{^EnvironmentFile=/etc/defaults/radsniff$}
)
.
with_content
(
%r{^ExecStart=/usr/bin/radsniff -P /var/run/freeradius/radsniff.pid -d /etc/freeradius $RADSNIFF_OPTIONS$}
)
.
that_notifies
(
'Service[radsniff]'
)
end
else
it
do
is_expected
.
to
compile
.
and_raise_error
(
%r{radsniff only supports RedHat}
)
is_expected
.
to
compile
.
and_raise_error
(
%r{freeradius::radsniff requires envfile to be explicitly set on this OS}
)
is_expected
.
to
compile
.
and_raise_error
(
%r{freeradius::radsniff requires pidfile to be explicitly set on this OS}
)
end
end
context
'with envfile and pidfile set'
do
let
(
:params
)
do
super
().
merge
(
envfile:
'/test/env/file'
,
pidfile:
'/a/pid/file'
,
)
end
if
os_facts
[
:osfamily
]
!~
%r{^RedHat|Debian$}
it
do
is_expected
.
to
contain_service
(
'radsniff'
)
.
with_ensure
(
'running'
)
.
with_enable
(
true
)
end
end
it
do
is_expected
.
to
contain_file
(
'/test/env/file'
)
.
with_content
(
%r{RADSNIFF_OPTIONS="radsniff cmd
\\
"line
\\
" options"}
)
.
that_notifies
(
'Service[radsniff]'
)
.
that_requires
(
'Package[freeradius-utils]'
)
end
it
do
is_expected
.
to
contain_systemd__unit_file
(
'radsniff.service'
)
.
with_content
(
%r{^Pidfile=/a/pid/file$}
)
.
with_content
(
%r{^EnvironmentFile=/test/env/file$}
)
.
with_content
(
%r{^ExecStart=/usr/bin/radsniff -P /a/pid/file -d /etc/freeradius $RADSNIFF_OPTIONS$}
)
.
that_notifies
(
'Service[radsniff]'
)
end
end
end
...
...
fil
es/radsniff.service
→
templat
es/radsniff.service
.erb
View file @
12dab8c2
...
...
@@ -5,9 +5,9 @@ After=radiusd.target
[Service]
Type=forking
P
IDF
ile
=
/var/run/
radius
d/
radsniff
.pid
EnvironmentFile
=
/etc/sysconfig/radsniff
ExecStart
=
/usr/bin/radsniff -P
/var/run/
radius
d/
radsniff
.
pid
-d /etc/raddb
$RADSNIFF_OPTIONS
P
idf
ile=
<%=
scope
[
'::free
radius
::
radsniff
::final_pidfile'
]
%>
EnvironmentFile=
<%=
scope
[
'::freeradius::radsniff::final_envpath'
]
%>
ExecStart=/usr/bin/radsniff -P
<%=
scope
[
'::free
radius
::
radsniff
::
pid
path'
]
%>
-d
<%=
scope
[
'::freeradius::radsniff::fr_basepath'
]
%>
$RADSNIFF_OPTIONS
[Install]
WantedBy=multi-user.target
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment