Skip to content

Commit

Permalink
Merge pull request #1178 from bersace/systemd
Browse files Browse the repository at this point in the history
Improve systemd handling in packaging
  • Loading branch information
bersace authored Oct 31, 2022
2 parents 8910d3f + 1908178 commit eb01490
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 48 deletions.
18 changes: 5 additions & 13 deletions agent/packaging/rpm/temboard-agent.spec
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ useradd -M -n -g postgres -o -r -d /var/lib/pgsql -s /bin/bash \
# pidfile directory
%{__install} -d %{buildroot}/var/run/temboard-agent

%post
if [ -x /usr/share/temboard-agent/restart-all.sh ] ; then
/usr/share/temboard-agent/restart-all.sh
elif systemctl is-system-running &>/dev/null ; then
systemctl daemon-reload
if systemctl is-active temboard-agent &>/dev/null; then
systemctl restart temboard-agent
fi
fi

%files
%config(noreplace) %attr(-,postgres,postgres) %{_sysconfdir}/temboard-agent
%{python3_sitelib}/*
Expand All @@ -79,11 +69,13 @@ fi

%attr(-,postgres,postgres) /var/lib/temboard-agent

%post
/usr/share/temboard-agent/restart-all.sh

%preun
if systemctl is-system-running &>/dev/null ; then
systemctl stop temboard-agent*
systemctl disable $(systemctl --plain list-units temboard-agent@* | grep -Po temboard-agent.*\\.service)
systemctl reset-failed temboard-agent*
systemctl disable --now temboard-agent@*
systemctl reset-failed temboard-agent@*
fi


Expand Down
2 changes: 1 addition & 1 deletion agent/packaging/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Group=postgres
Environment="SYSTEMD=1"
ExecStart=/usr/bin/temboard-agent -c /etc/temboard-agent/%I/temboard-agent.conf
# Increase OOM Score to ensure agent is killed before Postgres.
OOMAdjustScore=15
OOMScoreAdjust=15

[Install]
WantedBy=multi-user.target
5 changes: 2 additions & 3 deletions agent/share/auto_configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ sudo -Eu "${SYSUSER}" $(type -p temboard-agent) -c "$conf" discover >/dev/null
# systemd
if grep -q systemd /proc/1/cmdline && [ -w /etc/systemd/system ] ; then
unit="temboard-agent@$(systemd-escape "${name}").service"
log "Enabling systemd unit ${unit}."
log "Configuring systemd unit ${unit}."
if [ "${SYSUSER}" != "postgres" ] ; then
mkdir -p "/etc/systemd/system/$unit.d/"
cat > "/etc/systemd/system/$unit.d/user.conf" <<-EOF
Expand All @@ -365,8 +365,7 @@ if grep -q systemd /proc/1/cmdline && [ -w /etc/systemd/system ] ; then
Group=${SYSGROUP}
EOF
fi
systemctl enable "$unit"
start_cmd="systemctl start $unit"
start_cmd="systemctl enable --now $unit"
else
start_cmd="sudo -u ${SYSUSER} temboard-agent -c $conf"
fi
Expand Down
19 changes: 1 addition & 18 deletions agent/share/restart-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,4 @@ fi

systemctl daemon-reload

prefix=temboard-agent@
active_units="$(systemctl --plain list-units ${prefix}* | grep -Po ${prefix}.*\\.service ||:)"

if [ -z "${active_units}" ] ; then
echo No units found for temboard-agent. >&2
exit 0;
fi

exit_code=0
for unit in ${active_units} ; do
echo Restarting $unit >&2
if ! systemctl restart $unit ; then
echo Failed to restart $unit >&2
exit_code=1
fi
done

exit $exit_code
systemctl restart --state=ACTIVE temboard-agent@*
2 changes: 1 addition & 1 deletion docs/agent_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Now start the agent using the command suggested by `auto_configure.sh`.
On most systems now, it\'s a systemd service:

``` console
# systemctl start temboard-agent@14-main
# systemctl enable --now temboard-agent@14-main
```

Check that it has started successfully:
Expand Down
2 changes: 1 addition & 1 deletion docs/server_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ the certificate and the cookie secret key.
By default, temBoard is set up with a dumb `admin` user with password `admin`. This
is totally unsecured. It is **strongly recommended to change default password**! See below.

First, start temboard using `systemctl start temboard`.
First, start temboard using `systemctl enable --now temboard`.
Then point your browser to <https://temboard_server_host:8888>, log in as
`admin:admin` and change the password.

Expand Down
8 changes: 2 additions & 6 deletions ui/packaging/deb/postinst.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash -eu

error() {
echo -e "\e[1;31m$*\e[0m" >&2
}

if systemctl is-active temboard >&/dev/null ; then
systemctl restart temboard
if systemctl daemon-reload &>/dev/null ; then
systemctl restart --state=ACTIVE temboard
fi
9 changes: 6 additions & 3 deletions ui/packaging/rpm/temboard.spec
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ This packages holds the web user interface

%post
systemctl daemon-reload &>/dev/null || :
systemctl restart --state=ACTIVE temboard

if systemctl is-active temboard >&/dev/null ; then
systemctl restart temboard
%preun
if systemctl is-system-running &>/dev/null ; then
systemctl disable --now temboard
systemctl reset-failed temboard
fi

%postun
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
/bin/systemctl daemon-reload &>/dev/null || :

%install
PATH=$PATH:%{buildroot}%{python_sitelib}/%{pkgname}
Expand Down
3 changes: 1 addition & 2 deletions ui/share/auto_configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,9 @@ fi
TEMBOARD_CONFIGFILE="$ETCDIR/temboard.conf" "${run_as_temboard[@]}" temboard generate-key

if grep -q systemd /proc/1/cmdline && [ -w /etc/systemd/system ] ; then
start_cmd="systemctl start temboard"
start_cmd="systemctl enable-now temboard"
if systemctl is-system-running &>/dev/null ; then
systemctl daemon-reload
systemctl enable temboard
fi
else
start_cmd="sudo -iu $SYSUSER temboard -c ${ETCDIR}/temboard.conf"
Expand Down

0 comments on commit eb01490

Please sign in to comment.