Juniper vMX – Starting the vMX on boot

NOTE: I originally published this page in 2018; instructions may now be out of date.

The Juniper vMX product doesn’t include any init scripts or systemd unit files. You cannot also just set the VM’s to autostart with virsh since the VM’s are added and started with the vmx.sh shell script that Juniper provides.

SysV init (eg. Ubuntu 14.04)

You will need to add your own init script.

  1. Download a copy of the init script from here.
  2. Edit the init script and fix the DIR variable. In my case I am deploying Juniper vMX 17.4R1 which is installed in /home/vMX-17.4R1/. The trailing / must be added.
  3. Copy the modified init script to /etc/init.d/vmx.
  4. Make the init script executable: chmod +x /etc/init.d/vmx
  5. Enable the script to start on boot: update-rc.d vmx defaults update-rc.d vmx enable Test to make sure that the status output works, it will discover if you have any errors with the script before you reboot: /etc/init.d/vmx status

You can now reboot the host to verify that it starts on boot correctly.

systemd (eg. CentOS 7, Ubuntu 16.04)

I am using CentOS 7.4 which means that a systemd service file is used instead of the init script like for Ubuntu 14.04. If you are using this systemd service file with other distributions you may need to correct the PATH variable to suite your environment – on CentOS 7.4 Python 2.7 must be used to start the vMX.

Note: To get the systemd service file working on CentOS I found that SELINUX needs to be disabled. I didn’t have time to debug it further to find out what needs to be allowed in order to leave it running.

  1. Download a copy of the systemd service file from here
  2. Edit the file and set the correct path for WorkingDirectory. This path must contain the vmx.sh script. On CentOS 7 you will need to uncomment the PATH environment variable as well.
  3. Copy the modified service file to /etc/systemd/system/vmx.service.
  4. Reload systemd daemons to pick up the new service: systemctl daemon-reload
  5. Check the status of the service to make sure that there is no error (eg. invalid syntax for the service file): systemctl status vmx.service
  6. Enable the service so that it will be started on boot: systemctl enable vmx

SELINUX needs to be disabled otherwise the systemd unit will fail. Run this to disable SELINUX:

sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/sysconfig/selinux

After changing the SELINUX policy reboot the server and the vMX should start automatically.

Errors like this are caused by the SELINUX policy blocking it:

vmx_service.sh[25484]: Find configured management interface..............vlan51
vmx_service.sh[25484]: Find existing management gateway..................vlan50
vmx_service.sh[25484]: Check if vlan51 is already enslaved to br-ext.....[No]
vmx_service.sh[25484]: Gateway interface needs change....................[No]
vmx_service.sh[25484]: Flush vlan51......................................[OK]
vmx_service.sh[25484]: Bind vlan51 to br-ext.............................[Failed]
vmx_service.sh[25484]: bridge br-ext does not exist!
vmx_service.sh[25484]: Log file........................................../dev/null
vmx_service.sh[25484]: ==================================================
vmx_service.sh[25484]:  Aborted!. 1 error(s) and 0 warning(s)
vmx_service.sh[25484]: ==================================================
systemd[1]: vmx.service: main process exited, code=exited, status=2/INVALIDARGUMENT
systemd[1]: Failed to start Juniper vMX Router.

Leave a Reply

Your email address will not be published. Required fields are marked *