Created
April 9, 2020 12:38
-
-
Save sprytnyk/d29493676aa883f6b5ee656008e4d377 to your computer and use it in GitHub Desktop.
A simple script to turn on/off systemd-resolved.service from /etc/openvpn/update-resolv-conf.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
STATUS="$(sudo systemctl status systemd-resolved.service)" | |
# Stops the service if systemd-resolv.service is running. | |
if echo "${STATUS}" | grep -q "running" | |
then | |
sudo systemctl stop systemd-resolved.service > /dev/null 2>&1 | |
if sudo systemctl status systemd-resolved.service | grep -q "inactive" | |
then | |
echo -e "\e[44mThe systemd-resolved.service has been stopped.\e[0m" && exit 0 | |
else | |
echo -e "\e[41mThe service is still running.\e[0m" && exit 1 | |
fi | |
fi | |
# Starts the service if systemd-resolv.service is not running. | |
if echo "${STATUS}" | grep -q "inactive" | |
then | |
sudo systemctl start systemd-resolved.service > /dev/null 2>&1 | |
if sudo systemctl status systemd-resolved.service | grep -q "running" | |
then | |
echo -e "\e[42mThe systemd-resolved.service has been launched.\e[0m" && exit 0 | |
else | |
echo -e "\e[41mThe service is still inactive.\e[0m" && exit 1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment