Last active
January 13, 2019 02:55
-
-
Save ridingintraffic/49e446b39e2da297be0f63a57808a6a3 to your computer and use it in GitHub Desktop.
openvpn as a systemd service with PS1 alerting
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
username | |
Password |
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
[Unit] | |
Description=cryptostorm vpn | |
Wants=network-online.target | |
After=network-online.target | |
[Service] | |
WorkingDirectory=/home/linuxuser/ | |
User=root | |
Group=root | |
PermissionsStartOnly=true | |
ExecStart=/usr/sbin/openvpn —-config /home/linuxuser/git/openvpn_client_configuration_files/linux/hidden.ovpn | |
# Let systemd restart this service only if it has ended with the clean exit code or signal. | |
Restart=always | |
# time to sleep before restarting a service | |
RestartSec=15 | |
StandardOutput=journal | |
StandardError=inherit | |
# Specifies the maximum file descriptor number that can be opened by this process | |
LimitNOFILE=65536 | |
# Disable timeout logic and wait until process is stopped | |
TimeoutStopSec=0 | |
# SIGTERM signal is used to stop Minio | |
KillSignal=SIGTERM | |
SendSIGKILL=no | |
SuccessExitStatus=0 | |
[Install] | |
WantedBy=multi-user.target |
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
vi /etc/systemd/system/vpn.service (copy paste from above) | |
sudo systemctl daemon-reload | |
sudo systemctl enable vpn.service | |
sudo systemctl start vpn | |
sudo systemctl status vpn | |
## if PS1 is working terminal will turn green if vpn service is running red if it is not |
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
#openvpn prompt color | |
# when my vpn is connected the first hop on traceroute to a specific address will always be 10.* | |
prompt_command () { | |
if [ "$(traceroute -m 1 somehost.com |grep 10 |awk 'BEGIN{} {print $2}'| cut -d . -f 1)" == 10 ]; then | |
export PS1="${debian_chroot:+($debian_chroot)}\e[0;32m[\u@\h:\w\$ " | |
else | |
export PS1="${debian_chroot:+($debian_chroot)}\e[0;31m[\u@\h:\w\$ " | |
fi | |
} | |
## alternative apporach checking the service state instead | |
prompt_command () { | |
if [ "$(sudo systemctl status vpn | grep Active: |awk 'BEGIN{} {print $3}')" == "(running)" ]; then | |
export PS1="${debian_chroot:+($debian_chroot)}\e[0;32m[\u@\h:\w\$ " | |
else | |
export PS1="${debian_chroot:+($debian_chroot)}\e[0;31m[\u@\h:\w\$ " | |
fi | |
} | |
PROMPT_COMMAND=prompt_command | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment