### BEGIN INIT INFO # Provides: vmx # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start vMX router on boot # Description: Start the Juniper vMX router when the server boots ### END INIT INFO # The directory where the vMX is installed. This must have the trailing '/'. DIR="/home/vMX-17.4R1/" # The vMX shell script location. You should not have to change this. SCRIPT="${DIR}/vmx.sh" case "$1" in boot) # Ensure that the directory for the vMX exists and the vmx.sh script exists if [[ -d "$DIR" && -f "$SCRIPT" ]]; then # Start the vMX cd "$DIR" && $SCRIPT --start else # Shell script or directory could not be found echo "Error: The vMX directory or shell script could not be found" >&2 exit 3 fi ;; start) # Ensure that the directory for the vMX exists and the vmx.sh script exists if [[ -d "$DIR" && -f "$SCRIPT" ]]; then # Check if the vMX is already started cd "$DIR" OUTPUT=`$SCRIPT --status 2>&1 | grep "Check if vMX is running"` if [[ $? -eq 0 ]]; then echo "$OUTPUT | grep Yes" if [[ $? -eq 0 ]]; then echo "Error: The vMX appears to already be running; please stop it first" >&2 exit 3 fi fi # Start the vMX # I have had to add unload then load the i40e module as sometimes my Intel X710 NIC's get stuck modprobe -r i40e && modprobe i40e $SCRIPT --start else # Shell script or directory could not be found echo "Error: The vMX directory or shell script could not be found" >&2 exit 3 fi ;; stop) # Ensure that the directory for the vMX exists and the vmx.sh script exists if [[ -d "$DIR" && -f "$SCRIPT" ]]; then # Check if the vMX is running cd "$DIR" OUTPUT=`$SCRIPT --status 2>&1 | grep "Check if vMX is running"` if [[ $? -eq 0 ]]; then echo "$OUTPUT | grep Yes" if [[ $? -eq 0 ]]; then $SCRIPT --stop else echo "Error: The vMX does not appear to be currently running" >&2 exit 3 fi fi else # Shell script or directory could not be found echo "Error: The vMX directory or shell script could not be found" >&2 exit 3 fi ;; restart) # Ensure that the directory for the vMX exists and the vmx.sh script exists if [[ -d "$DIR" && -f "$SCRIPT" ]]; then # Check if the vMX is running cd "$DIR" OUTPUT=`$SCRIPT --status 2>&1 | grep "Check if vMX is running"` if [[ $? -eq 0 ]]; then echo "$OUTPUT | grep Yes" if [[ $? -eq 0 ]]; then $SCRIPT --stop echo "Sleeping for 5 seconds after stopping vMX...." sleep 5 fi fi # Start the vMX # I have had to add unload then load the i40e module as sometimes my Intel X710 NIC's get stuck modprobe -r i40e && modprobe i40e $SCRIPT --start else # Shell script or directory could not be found echo "Error: The vMX directory or shell script could not be found" >&2 exit 3 fi ;; status) # Ensure that the directory for the vMX exists and the vmx.sh script exists if [[ -d "$DIR" && -f "$SCRIPT" ]]; then $SCRIPT --status else # Shell script or directory could not be found echo "Error: The vMX directory or shell script could not be found" >&2 exit 3 fi ;; *) echo "Usage: /etc/init.d/vmx {start|stop|restart|status}" exit 1 esac exit 0