Blob Blame History Raw
# needed for building on el6
%{?nodejs_find_provides_and_requires}

# filter provides and requires from examples directory RHBZ#1263969
%{?perl_default_filter}

%global enable_tests 1

%if 0%{?fedora} >= 19 || 0%{?rhel} >= 7
%bcond_without systemd
%endif

Name:       statsd
Version:    0.7.2
Release:    10%{?dist}
Summary:    A simple, lightweight network daemon to collect metrics over UDP
License:    MIT
URL:        https://github.com/etsy/statsd/
Source0:    https://github.com/etsy/%{name}/archive/v%{version}.tar.gz#/%{name}-v%{version}.tar.gz
Source1:    statsd.service
Source2:    statsd.sysvinit

BuildArch:      noarch
%if 0%{?fedora} >= 19
ExclusiveArch: %{nodejs_arches} noarch
%else
ExclusiveArch: %{ix86} x86_64 %{arm} noarch
%endif

BuildRequires:  dos2unix
BuildRequires:  nodejs-packaging
BuildRequires:  nodeunit
BuildRequires:  npm(temp)
BuildRequires:  npm(underscore)
BuildRequires:  perl-generators

Requires(pre):  shadow-utils

%if %{with systemd}
BuildRequires:      systemd
Requires(post):     systemd
Requires(preun):    systemd
Requires(postun):   systemd
%else
Requires(post):     chkconfig
Requires(preun):    chkconfig
Requires(postun):   initscripts
%endif


%description
A network daemon that runs on the Node.js platform and listens for statistics, 
like counters and timers, sent over UDP or TCP and sends aggregates to one or 
more pluggable backend services (e.g., Graphite).


%prep
%setup -q -n %{name}-%{version}

# fix end of line encodings
/usr/bin/dos2unix examples/go/statsd.go
/usr/bin/dos2unix examples/csharp_example.cs

# set Graphitehost to localhost in default config
sed -i 's/graphite\.example\.com/localhost/' exampleConfig.js


%build
#nothing to do


%install
%{__mkdir_p} %{buildroot}%{nodejs_sitelib}/%{name}
cp -pr package.json proxy.js stats.js utils %{buildroot}%{nodejs_sitelib}/%{name}
cp -pr backends lib bin %{buildroot}%{nodejs_sitelib}/%{name}

%{__mkdir_p} %{buildroot}%{_bindir}
ln -s %{nodejs_sitelib}/%{name}/bin/%{name} %{buildroot}%{_bindir}/%{name}

%{__mkdir_p} %{buildroot}%{_sysconfdir}/%{name}
cp -pr exampleConfig.js %{buildroot}%{_sysconfdir}/%{name}/config.js


%if %{with systemd}
%{__install} -Dp -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}/%{name}.service
%else
%{__install} -Dp -m 0755 %{SOURCE2} %{buildroot}%{_initddir}/%{name}
%endif

%nodejs_symlink_deps


%if 0%{?enable_tests}
%check
%nodejs_symlink_deps --check
./run_tests.sh
%endif


%pre
getent group statsd >/dev/null || groupadd -r statsd
getent passwd statsd >/dev/null || \
    useradd -r -g statsd -d / -s /sbin/nologin \
    -c "statsd daemon user" statsd
exit 0


%post
%if %{with systemd}
%systemd_post %{name}.service
%else
/sbin/chkconfig --add %{name}
%endif


%preun
%if %{with systemd}
%systemd_preun %{name}.service
%else
if [ $1 -eq 0 ] ; then
    /sbin/service %{name} stop >/dev/null 2>&1
    /sbin/chkconfig --del %{name}
fi
%endif


%postun
%if %{with systemd}
%systemd_postun_with_restart %{name}.service
%else
if [ "$1" -ge "1" ] ; then
    /sbin/service %{name} condrestart >/dev/null 2>&1 || :
fi
%endif


%files
# following macro is needed for el6
%{!?_licensedir:%global license %%doc}
%doc README.md CONTRIBUTING.md Changelog.md exampleConfig.js exampleProxyConfig.js docs/ examples/
%license LICENSE
%{nodejs_sitelib}/%{name}
%{_bindir}/statsd
%{_sysconfdir}/%{name}
%config(noreplace) %{_sysconfdir}/%{name}/config.js

%if %{with systemd}
%{_unitdir}/%{name}.service
%else
%{_initddir}/%{name}
%endif


%changelog
* Tue Oct 17 2017 Piotr Popieluch <piotr1212@gmail.com> - 0.7.2-10
- Add "Wants=network.target" to unitfile RHBZ#1502746

* Thu Jul 27 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.7.2-9
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild

* Sat Feb 11 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.7.2-8
- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild

* Fri Feb 05 2016 Fedora Release Engineering <releng@fedoraproject.org> - 0.7.2-7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild

* Fri Sep 18 2015 Piotr Popieluch <piotr1212@gmail.com> - 0.7.2-6
- filter perl provides and requires RHBZ#1263969
- move license to license tag

* Tue Jul 07 2015 Piotr Popieluch <piotr1212@gmail.com> - 0.7.2-5
- set correct ExclusiveArch for EPEL

* Fri Jun 19 2015 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.7.2-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild

* Tue Dec  2 2014 Piotr Popieluch <piotr1212@gmail.com> - 0.7.2-3
- fix end of line encodings

* Tue Nov 18 2014 Piotr Popieluch <piotr1212@gmail.com> - 0.7.2-2
- added epel6 support

* Sat Nov 15 2014 Piotr Popieluch <piotr1212@gmail.com> - 0.7.2-1
- Initial package