#!/bin/bash # Start/stop/restart the ocserv vpn server # This script uses the occtl tool start_ocserv() { if [ -S /var/run/occtl.socket ]; then echo "ocserv is already running" exit 0 fi echo "Starting ocserv" /usr/sbin/ocserv 2>/dev/null } stop_ocserv() { /usr/bin/occtl stop now } restart_ocserv() { stop_ocserv sleep 1 start_ocserv } reload_ocserv() { /usr/bin/occtl reload } status_ocserv() { if [ -S /var/run/occtl.socket ]; then /usr/bin/occtl show status else echo "ocserv is stopped" exit 1 fi } case "$1" in 'start') start_ocserv ;; 'stop') stop_ocserv ;; 'restart') restart_ocserv ;; 'reload') reload_ocserv ;; 'status') status_ocserv ;; *) echo "usage $0 start|stop|restart|reload|status" esac