Flushing the DNS cache is easy as:
sudo systemd-resolve --flush-caches
Commands
Must be done on change unit/timer files in /etc/systemd/system
systemctl daemon-reload
journalctl -u advanced.service
journalctl -u ale-monitoring -u ale-transformation -b --no-pager --since 2018-10-14
# in local time
timedatectl list-timezones
timedatectl set-timezone Europe/Sofia
journalctl --utc
journalctl -b < from last boot
journalctl -xef -n 0
journalctl --disk-usage
Retain only the past two days:
journalctl --vacuum-time=2d
Retain only the past 500 MB:
journalctl --vacuum-size=100M
The status of the unit/service
systemctl status advanced.service
systemctl status advanced.timer
Enable services
systemctl enable advanced@CLIENT
systemctl enable advanced@CLIENT.timer
Timers
You need to create a unit file.
Both timer and service/units must be enabled if you want to run them.
Timers need additional start command.
systemctl list-timers --all
How to override the timer
mkdir advanced@client_name.timer.d/
cat > advanced@client_name.timer.d/override.conf
[Unit]
Description=Trigger the advanced for clients %I
[Timer]
OnCalendar=Wed *-*-* 10:13:00
Persistent=true
# RandomizedDelaySec=5m
[Install]
WantedBy=timers.target
How to work with templates
This is an advanced@.service template
[Unit]
Description=Run advanced for clients - %I
Documentation=https://github.com/company/projectX
After=network.target
AssertPathExists=/opt/projectX
OnFailure=advanced-fail@.service
[Service]
Type=simple
Restart=no
Environment=ADVANCED_HOME=/opt/projectX
User=root
WorkingDirectory=/opt/projectX
ExecStart=/usr/bin/env ./pipeline/run_new.sh %I
ExecStartPre=-/opt/a1-slack.sh %I start-a1
ExecStopPost=-/opt/a1-slack.sh %I finish-a1
[Install]
WantedBy=multi-user.target
The advanced@.timer
[Unit]
Description=Trigger the advanced for clients %I
Persistent=true
# RandomizedDelaySec=5m
[Install]
WantedBy=timers.target
The failing handler advanced-fail@.service
[Unit]
Description=Notify falure for client - %I
AssertPathExists=/opt/projectX
[Service]
Type=simple
Environment=ADVANCED_HOME=/opt/
User=root
WorkingDirectory=/opt/
ExecStart=-/opt/a1-slack.sh %I failed-a1 %I
[Install]
WantedBy=multi-user.target
The slack notifier a1-slack.sh
!/usr/bin/env bash
/opt/slack.sh \
-u https://hooks.slack.com/services/********NXoqza8 \
-c ds-roduction -t "$1" -b "$2"
And the handler slack.sh
#!/usr/bin/env bash
function usage {
programName=$0
echo "description: use this program to post messages to Slack channel"
echo "usage: $programName [-t \"sample title\"] [-b \"message body\"] [-c \"mychannel\"] [-u \"slack url\"]"
echo " -t the title of the message you are posting"
echo " -b The message body"
echo " -c The channel you are posting to"
echo " -u The slack hook url to post to"
exit 1
}
while getopts ":t:b:c:u:h" opt; do
case ${opt} in
t) msgTitle="$OPTARG"
;;
u) slackUrl="$OPTARG"
;;
b) msgBody="$OPTARG"
;;
c) channelName="$OPTARG"
;;
h) usage
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done
if [[ ! "${msgTitle}" || ! "${slackUrl}" || ! "${msgBody}" || ! "${channelName}" ]]; then
echo "all arguments are required"
usage
fi
read -d '' payLoad << EOF
{
"channel": "#${channelName}",
"username": "$(hostname)",
"icon_emoji": ":sunglasses:",
"attachments": [
{
"fallback": "${msgTitle}",
"color": "good",
"title": "${msgTitle}",
"fields": [{
"title": "message",
"value": "${msgBody}",
"short": false
}]
}
]
}
EOF
statusCode=$(curl \
--write-out %{http_code} \
--silent \
--output /dev/null \
-X POST \
-H 'Content-type: application/json' \
--data "${payLoad}" ${slackUrl})
echo ${statusCode}