Skip to content

Commit

Permalink
issue: 2368612 Improve systemd support
Browse files Browse the repository at this point in the history
This changes are done to be aligned with last Fedora requirements.

Signed-off-by: Igor Ivanov <[email protected]>
  • Loading branch information
igor-ivanov committed Feb 20, 2021
1 parent 1086516 commit 2879148
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 41 deletions.
3 changes: 0 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ mydoc_DATA = README.txt journal.txt VMA_VERSION

install-exec-hook:
if type systemctl >/dev/null 2>&1; then \
cp $(top_builddir)/contrib/scripts/vma.init $(DESTDIR)$(sbindir)/vma; \
chmod 755 $(DESTDIR)$(sbindir)/vma; \
mkdir -p $(DESTDIR)$(prefix)/lib/systemd/system/; \
cp $(top_builddir)/contrib/scripts/vma.service $(DESTDIR)$(prefix)/lib/systemd/system/vma.service; \
chmod 644 $(DESTDIR)$(prefix)/lib/systemd/system/vma.service; \
Expand All @@ -35,7 +33,6 @@ install-exec-hook:

uninstall-hook:
if type systemctl >/dev/null 2>&1; then \
rm -rf $(DESTDIR)$(sbindir)/vma; \
rm -rf $(DESTDIR)$(prefix)/lib/systemd/system/vma.service; \
else \
rm -rf $(DESTDIR)$(sysconfdir)/init.d/vma; \
Expand Down
58 changes: 39 additions & 19 deletions contrib/jenkins_tests/tool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,49 @@ function check_daemon()
rm -rf ${out_log}
sudo pkill -9 vmad

echo "daemon check output: ${service}" > ${out_log}

if type systemctl >/dev/null 2>&1; then
service=${install_dir}/sbin/vma
service=${install_dir}/sbin/vmad
service_arg=${install_dir}/lib/systemd/system/vma.service

if [ $(sudo systemd-analyze verify ${service_arg} >>${out_log} 2>&1 || echo $?) ]; then
ret=1
fi
sleep 3
if [ $(sudo ${service} >>${out_log} 2>&1 || echo $?) ]; then
ret=1
fi
sleep 3
if [ "0" == "$ret" -a "" == "$(pgrep vmad)" ]; then
ret=1
fi
sudo pkill -9 vmad >>${out_log} 2>&1
sleep 3
if [ "0" == "$ret" -a "" != "$(pgrep vmad)" ]; then
ret=1
fi
else
service=${install_dir}/etc/init.d/vma
fi
service_arg=""

echo "daemon check output: ${service}" > ${out_log}
if [ $(sudo ${service} start >>${out_log} 2>&1 || echo $?) ]; then
ret=1
fi
sleep 3
if [ "0" == "$ret" -a "" == "$(pgrep vmad)" ]; then
ret=1
fi
if [ $(sudo ${service} status >>${out_log} 2>&1 || echo $?) ]; then
ret=1
fi
if [ $(sudo ${service} stop >>${out_log} 2>&1 || echo $?) ]; then
ret=1
fi
sleep 3
if [ "0" == "$ret" -a "" != "$(pgrep vmad)" ]; then
ret=1
if [ $(sudo ${service} start ${service_arg} >>${out_log} 2>&1 || echo $?) ]; then
ret=1
fi
sleep 3
if [ "0" == "$ret" -a "" == "$(pgrep vmad)" ]; then
ret=1
fi
if [ $(sudo ${service} status ${service_arg} >>${out_log} 2>&1 || echo $?) ]; then
ret=1
fi
if [ $(sudo ${service} stop ${service_arg} >>${out_log} 2>&1 || echo $?) ]; then
ret=1
fi
sleep 3
if [ "0" == "$ret" -a "" != "$(pgrep vmad)" ]; then
ret=1
fi
fi

sudo pkill -9 vmad
Expand Down
40 changes: 32 additions & 8 deletions contrib/scripts/libvma.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ BuildRequires: systemd-rpm-macros
BuildRequires: pkgconfig(libnl-3.0)
BuildRequires: pkgconfig(libnl-route-3.0)
%endif
BuildRequires: make

%description
libvma is a LD_PRELOAD-able library that boosts performance of TCP and
Expand Down Expand Up @@ -82,24 +83,34 @@ cp -f src/vma/.libs/%{name}.so %{name}-debug.so
%endif

%configure --docdir=%{_pkgdocdir} \
%{?configure_options}
%{?configure_options}
%{make_build}

%install
%{make_install}
%{make_build} DESTDIR=${RPM_BUILD_ROOT} install

find $RPM_BUILD_ROOT%{_libdir} -name '*.la' -delete
%if "%{use_systemd}" == "1"
install -D -m 644 contrib/scripts/vma.service $RPM_BUILD_ROOT/%{_prefix}/lib/systemd/system/vma.service
%endif

%if %{use_rel} > 0
install -m 755 ./%{name}-debug.so $RPM_BUILD_ROOT/%{_libdir}/%{name}-debug.so
%endif

%post
%if 0%{?fedora} || 0%{?rhel} > 7
# https://fedoraproject.org/wiki/Changes/Removing_ldconfig_scriptlets
%else
%{run_ldconfig}

%endif
if [ $1 = 1 ]; then
if type systemctl >/dev/null 2>&1; then
systemctl --no-reload enable vma.service >/dev/null 2>&1 || true
%if 0%{?suse_version}
%service_add_post vma.service
%else
%systemd_post vma.service
%endif
elif [ -e /sbin/chkconfig ]; then
/sbin/chkconfig --add vma
elif [ -e /usr/sbin/update-rc.d ]; then
Expand All @@ -112,8 +123,11 @@ fi
%preun
if [ $1 = 0 ]; then
if type systemctl >/dev/null 2>&1; then
systemctl --no-reload disable vma.service >/dev/null 2>&1 || true
systemctl stop vma.service || true
%if 0%{?suse_version}
%service_del_preun vma.service
%else
%systemd_preun vma.service
%endif
elif [ -e /sbin/chkconfig ]; then
%{_sysconfdir}/init.d/vma stop
/sbin/chkconfig --del vma
Expand All @@ -127,9 +141,17 @@ if [ $1 = 0 ]; then
fi

%postun
%if 0%{?fedora} || 0%{?rhel} > 7
# https://fedoraproject.org/wiki/Changes/Removing_ldconfig_scriptlets
%else
%{run_ldconfig}
%endif
if type systemctl >/dev/null 2>&1; then
systemctl --system daemon-reload >/dev/null 2>&1 || true
%if 0%{?suse_version}
%service_del_postun vma.service
%else
%systemd_postun_with_restart vma.service
%endif
fi

%files
Expand All @@ -142,7 +164,6 @@ fi
%{_sbindir}/vmad
%if "%{use_systemd}" == "1"
%{_prefix}/lib/systemd/system/vma.service
%{_sbindir}/vma
%else
%{_sysconfdir}/init.d/vma
%endif
Expand All @@ -164,6 +185,9 @@ fi
%{_mandir}/man8/vma_stats.*

%changelog
* Mon Nov 23 2020 Igor Ivanov <[email protected]> 9.2.1-1
- Improve systemd support

* Fri Apr 17 2020 Igor Ivanov <[email protected]> 9.0.2-1
- Align with Fedora guidelines

Expand Down
9 changes: 3 additions & 6 deletions contrib/scripts/vma.service.in
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
[Unit]
Description=VMA Daemon. Version: @VERSION@-@VMA_LIBRARY_RELEASE@
After=network.target syslog.target
Requires=network.target
Description=VMA Daemon
After=network.target

[Service]
Type=forking
Restart=on-failure
ExecStart=@prefix@/sbin/vma start
ExecStop=@prefix@/sbin/vma stop
ExecReload=@prefix@/sbin/vma restart
ExecStart=@prefix@/sbin/vmad
RestartForceExitStatus=1 SIGTERM

[Install]
Expand Down
5 changes: 0 additions & 5 deletions tools/daemon/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ int main(int argc, char *argv[])
/* Setup syslog logging */
openlog(MODULE_NAME, LOG_PID, LOG_LOCAL5);

/* already a daemon */
if (getppid() == 1) {
return 0;
}

/* command line parsing... */
config_def();
log_info("Starting\n");
Expand Down

0 comments on commit 2879148

Please sign in to comment.