Skip to content

Commit df8008c

Browse files
committed
feat: add email-unit-invocation-logs@.service
1 parent 9358fea commit df8008c

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

Containerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ RUN set -eux; \
66
apk add --no-cache dma msmtp s-nail tini; \
77
mv /etc/dma/dma.conf /etc/dma/dma.conf.default
88

9-
COPY entrypoint.sh sendmail-in-ctr.sh /
9+
COPY entrypoint.sh /
10+
COPY utils/ /utils/
1011

1112
ENTRYPOINT ["/entrypoint.sh"]
1213
CMD ["msmtpd"]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[Unit]
2+
Description=invocation log emailer for %i
3+
4+
[Service]
5+
Environment=EMAIL_TGTS=user@example.com
6+
Environment=EMAIL_SUBJ='Service %i on host %H entered state: $STATE'
7+
Environment=EMAIL_TPL='Logs for service %i:\n$LOGS'
8+
# Environment=SD_ARGS=--user
9+
10+
SyslogIdentifier=logmailer
11+
SyslogLevel=err
12+
Type=oneshot
13+
ExecStart=/bin/sh -euc '\
14+
inv=$(systemctl ${SD_ARGS} show -P InvocationID %i | grep ^.) \n\
15+
STATE=$(systemctl ${SD_ARGS} is-active %i || true) \n\
16+
LOGS=$(journalctl ${SD_ARGS} --all --no-hostname \
17+
INVOCATION_ID=$$inv \
18+
+ USER_INVOCATION_ID=$$inv \
19+
+ _SYSTEMD_INVOCATION_ID=$$inv) \n\
20+
sendmail -i "$1" <<_TPL_EOF\nSubject: ${EMAIL_SUBJ}\n\n${EMAIL_TPL}\n_TPL_EOF\n\
21+
' -- $EMAIL_TGTS

0 commit comments

Comments
 (0)