我有一个systemd服务,它调用some服务来定期(每分钟)执行一些维护。该服务如下所示:
[Service]
Type=oneshot
ExecStart=/usr/bin/kinit -kt user.keytab user@DOMAIN
ExecStart=/usr/bin/curl --tlsv1.2 --cacert cert.pem --negotiate --user user: --url https://website/maintenance现在,每次都会销毁并重新初始化我的kerberos票据。kinit可能需要2-3分钟。
我想避免这一步,如果需要的话,只使用kinit。有什么想法吗?
发布于 2019-03-27 10:11:22
经过更多的研究,我意识到在systemd服务中包含逻辑似乎不是一个好主意。所以我决定遵循Elliott Frisch的建议,为它创建一个脚本:
#!/bin/bash
# check if ticket is present and not expired
if [[ $(klist -l | awk 'tolower($0) ~ /user/ && tolower($0) !~ /expired/') ]]; then
echo "using ticket cache"
else
echo "no cache authentication for user, kinit needed"
/usr/bin/kinit -kt /user.keytab user@DOMAIN
fi
/usr/bin/curl --tlsv1.2 --cacert cert.pem --negotiate --user user: --url https://website/maintenance然后在我的systemd服务中调用这个脚本。
发布于 2019-03-27 09:55:44
尝试HTTP请求,并使用状态码来决定是否需要尝试kinit。您可以像这样对curl的输出进行grep:
curl -s -i http://www.example.com | grep "HTTP/" | tail -1如果是“HTTP/1.1401未授权”,请运行kinit并重试。(如果您愿意,请参阅here了解如何解析出响应的数字部分)
"tail -1“部分是为了确保您只获得最后的代码;由于协商协议,您通常会从grep命令中获得多行代码,如下所示:
HTTP/1.1 401 Unauthorized
HTTP/1.1 200 OK第一个是来自服务器的初始挑战;第二个是最终响应代码。
https://stackoverflow.com/questions/55367815
复制相似问题