diff --git a/contrib/rpm/host-metering.spec.in b/contrib/rpm/host-metering.spec.in index 06de450..1709c11 100644 --- a/contrib/rpm/host-metering.spec.in +++ b/contrib/rpm/host-metering.spec.in @@ -78,6 +78,7 @@ install -m 0755 -vd %{buildroot}%{_bindir} install -m 0755 -vp $(pwd)/bin/* %{buildroot}%{_bindir}/ install -m 0755 -vd %{buildroot}%{_unitdir} install -m 644 contrib/systemd/host-metering.service %{buildroot}%{_unitdir}/%{name}.service +install -m 0755 contrib/systemd/host-metering-proxy-setup.sh %{buildroot}%{_bindir}/host-metering-proxy-setup.sh install -m 0755 -vd %{buildroot}%{_presetdir} install -m 644 contrib/systemd/80-host-metering.preset %{buildroot}%{_presetdir}/80-%{name}.preset install -m 0755 -vd %{buildroot}%{_mandir}/man1 diff --git a/contrib/systemd/host-metering-proxy-setup.sh b/contrib/systemd/host-metering-proxy-setup.sh new file mode 100755 index 0000000..06e90c9 --- /dev/null +++ b/contrib/systemd/host-metering-proxy-setup.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +HTTP_PROXY="" +HTTPS_PROXY="" + +if [ -f /etc/rhsm/rhsm.conf ]; then + PROXY_HOSTNAME=$(grep -E '^proxy_hostname\s*=' /etc/rhsm/rhsm.conf | awk -F= '{print $2}' | xargs) + PROXY_PORT=$(grep -E '^proxy_port\s*=' /etc/rhsm/rhsm.conf | awk -F= '{print $2}' | xargs) + + if [ -n "$PROXY_HOSTNAME" ] && [ -n "$PROXY_PORT" ]; then + HTTP_PROXY="http://$PROXY_HOSTNAME:$PROXY_PORT" + HTTPS_PROXY="http://$PROXY_HOSTNAME:$PROXY_PORT" + fi +fi + +[ -n "$HTTP_PROXY" ] && export HTTP_PROXY +[ -n "$HTTPS_PROXY" ] && export HTTPS_PROXY + +exec /usr/bin/host-metering daemon \ No newline at end of file diff --git a/contrib/systemd/host-metering.service b/contrib/systemd/host-metering.service index d0cf99a..c4055bc 100644 --- a/contrib/systemd/host-metering.service +++ b/contrib/systemd/host-metering.service @@ -6,10 +6,10 @@ After=network-online.target [Service] Type=simple Environment=LC_ALL=C.UTF-8 -ExecStart=/usr/bin/host-metering daemon +ExecStart=/usr/bin/host-metering-proxy-setup.sh ExecReload=/usr/bin/kill -HUP $MAINPID Restart=always [Install] -WantedBy=multi-user.target +WantedBy=multi-user.target \ No newline at end of file