Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
openvpn as a systemd service with PS1 alerting
.....
.....
auth-user-pass /home/linuxuser/pass.txt
username
Password
[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
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
#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
You can’t perform that action at this time.