Skip to content

Commit

Permalink
Load proxy config on service start
Browse files Browse the repository at this point in the history
Add startup script to load proxy config from rhsm.conf
Add script to spec file
Modify ExecStart param of systemd service
  • Loading branch information
F-X64 committed Aug 28, 2024
1 parent bd83d03 commit 1459866
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions contrib/rpm/host-metering.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions contrib/systemd/host-metering-proxy-setup.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions contrib/systemd/host-metering.service
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1459866

Please sign in to comment.