forked from RHInception/jsonstats
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jsonstats.spec
243 lines (199 loc) · 7.34 KB
/
jsonstats.spec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# Depends on redhat-rpm-config
%define distribution %(/usr/lib/rpm/redhat/dist.sh --disttype)
%define distribution_version %(/usr/lib/rpm/redhat/dist.sh --distnum)
%if "el" == "%{distribution}"
%{!?rhel: %define rhel %{distribution_version}}
%endif
%if 0%{?rhel} <= 5
%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")}
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
%endif
Name: jsonstats
%define _name jsonstatsd
Release: 1%{?dist}
Summary: Client for exposing system information over a REST interface
Version: 1.0.3
Group: Development/Libraries
License: MIT
Source0: %{name}-%{version}.tar.gz
Url: https://github.com/RHInception/jsonstats
BuildArch: noarch
# Common *Requires
Requires: PyYAML
BuildRequires: python2-devel
BuildRequires: redhat-rpm-config
######################################################################
# RHEL 5/6
%if "%{distribution}" == "el"
# begin inner-if
%if 0%{?rhel} <= 6
Requires(post): chkconfig
Requires(preun): chkconfig
Requires(preun): initscripts
Requires(postun): initscripts
%define boot_system sysv
%endif
######################################################################
# distribution is not "el", so probably fedora
%else
######################################################################
# Fedora =< 17 require systemd-units && systemd
%if 0%{?fedora} > 0
%if 0%{?fedora} <= 17
Requires(post): systemd-units
Requires(preun): systemd-units
Requires(postun): systemd-units
%define boot_system systemd_old
%endif
%endif
######################################################################
# Fedora > 17 just requires systemd
%if 0%{?fedora} > 17
Requires(post): systemd
Requires(preun): systemd
Requires(postun): systemd
BuildRequires: systemd
%define boot_system systemd_new
%endif
######################################################################
# (same w/ RHEL7+)
%if 0%{?rhel} >= 7
Requires(post): systemd
Requires(preun): systemd
Requires(postun): systemd
BuildRequires: systemd
%define boot_system systemd_new
%endif
%endif
######################################################################
# Define the name of the init script to include in the files section
######################################################################
%if %{boot_system} == "sysv"
%define init_script /etc/init.d/jsonstatsd
%else
%define init_script %{_unitdir}/%{_name}.service
%endif
######################################################################
# And this ends our *Requires madness. Let's set up the proper
# pre/post script handlers for creating the jsonstatsd user and
# registering the service with the system init
######################################################################
%pre
getent passwd %{_name} >/dev/null 2>&1 || %{_sbindir}/useradd -M -r --shell %{_sbindir}/nologin %{_name}
######################################################################
# BEGIN SysV
# Reference: http://fedoraproject.org/wiki/Packaging:SysVInitScript#Initscripts_in_spec_file_scriptlets
######################################################################
%if %{boot_system} == "sysv"
%post
/sbin/chkconfig --add %{_name}
%preun
if [ $1 -eq 0 ] ; then
/sbin/service %{_name} stop >/dev/null 2>&1
/sbin/chkconfig --del %{_name}
%{_sbindir}/userdel %{_name} > /dev/null 2>&1
fi
%postun
if [ "$1" -ge "1" ] ; then
/sbin/service ${_name} condrestart >/dev/null 2>&1 || :
fi
%endif
######################################################################
# END SysV
######################################################################
######################################################################
# BEGIN Systemd - Fedora 17 and older
# Reference: http://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Manual_scriptlets_.28Fedora_17_or_older.29
######################################################################
%if %{boot_system} == "systemd_old"
%post
if [ $1 -eq 1 ] ; then
# Initial installation
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
fi
%preun
if [ $1 -eq 0 ] ; then
# Package removal, not upgrade
/bin/systemctl --no-reload disable %{_name}.service > /dev/null 2>&1 || :
/bin/systemctl stop %{_name}.service > /dev/null 2>&1 || :
%{_sbindir}/userdel -r %{_name} > /dev/null 2>&1
fi
%postun
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
if [ $1 -ge 1 ] ; then
# Package upgrade, not uninstall
/bin/systemctl try-restart %{_name}.service >/dev/null 2>&1 || :
fi
%endif
######################################################################
# END Systemd - Fedora 17 and older
######################################################################
######################################################################
# BEGIN Systemd - Fedora 18+ & RHEL7+
######################################################################
%if %{boot_system} == "systemd_new"
%post
%systemd_post %{_name}.service
%preun
%systemd_preun %{_name}.service
%{_sbindir}/userdel -r %{_name} > /dev/null 2>&1
%postun
%systemd_postun_with_restart %{_name}.service
%endif
######################################################################
# END Systemd - Fedora 18+ & RHEL7+
######################################################################
%description
A simple REST client which exposes provides arbitrary system
information ('facts'). The fact providing system is plugin
based. Exposing additional facts is as simple as returning a JSON
serializable python datastructure.
%prep
%setup -q
%build
%{__python} setup.py build
%install
%{__python} setup.py install -O1 --root=$RPM_BUILD_ROOT
%{__mkdir_p} $RPM_BUILD_ROOT%{_localstatedir}/log/%{_name}
mkdir -p $RPM_BUILD_ROOT/%{_mandir}/man1/
cp -v docs/man/man1/*.1 $RPM_BUILD_ROOT/%{_mandir}/man1/
%clean
rm -rf $RPM_BUILD_ROOT
######################################################################
# files for 'jsonstats' package
%files
%defattr(-,root,root)
%{python_sitelib}/*
%{_bindir}/%{_name}
%{init_script}
%config(noreplace)/etc/sysconfig/%{_name}
%attr(0755,jsonstatsd,jsonstatsd) %dir %{_localstatedir}/log/%{_name}
%doc %{_mandir}/man1/jsonstatsd*
%doc README.md LICENSE
######################################################################
%changelog
* Thu May 8 2014 Tim Bielawa <[email protected]> - 1.0.3-1
- Don't set 'epilog' in option parser on old python boxes
* Thu May 1 2014 Chris Murphy <[email protected]> - 1.0.2-2
- Bumped release because of earlier build conflict
* Thu Apr 3 2014 Tim Bielawa <[email protected]> - 1.0.2-1
- New Plugins: Timestamp
- Better debian compat
- Configurable 'extra plugin' paths
- White/black listing plugins
- Fix init script bug
* Fri Dec 13 2013 Tim Bielawa <[email protected]> - 1.0.1-1
- Bug fixes and useability improvements
- CLI options parsed before plugin loading
- JSON output is sorted
- Facter plugin uses puppet only if available
- Packaging correctly adds/removes jsonstatsd user
- More unit tests
* Wed Nov 27 2013 Tim Bielawa <[email protected]> - 1.0.0-2
- Make log files named consistently
* Wed Nov 20 2013 Tim Bielawa <[email protected]> - 1.0.0-1
- Ready for 1.0.0
* Sun Nov 17 2013 Tim Bielawa <[email protected]> - 0.6.0-1
- Now daemonizes and has proper init scripts
* Mon Nov 4 2013 Tim Bielawa <[email protected]> - 0.5.0-2
- First functional release and RPM distribution.