MATLAB: Is there a way to run MATLAB Production Server as a Windows service

asMATLAB Production Servermpsservicewindows

I am running MATLAB Production Server (MPS) on a Windows server. I can create and start a server instance using the instructions in the User's Guide but the server instance stops when I log off the Windows server. I need the server instance to remain running even when I am not logged on to the server. Is there a way to run MPS as a Windows service?

Best Answer

This functionality was added in R2015a with the mps-service utility. See the documentation on mps-service for details.
For earlier releases, follow the instructions below to run MPS as Windows service:
1. If you have not done it already, install MPS, the MATLAB Compiler Runtime (MCR), and Network License Manager as you would during a normal setup.
2. Make a new MPS server instance if you have not done it already (with the mps-new command). If working with an existing instance, make sure it is stopped first.
3. Download the attached service wrapper. Make sure to download the correct version, when working with 32-bit MPS/MCR download the win32 package, when working with 64-bit MPS/MCR download the win64 package.
4. Make sure that Windows trusts the downloaded ZIP-file, to do so right-click on the file and select "Properties". This should show a dialog as below. If you see the "Unblock" button as marked in the screenshot, click on it and then click "OK". If you do not see the button the file should already be trusted and you can just close the dialog.
5. Unpack the contents of the "MPS_Service_Wrapper_win64" directory in the ZIP-file into your MPS instance directory (root level, alongside .mps_version, config, log, auto_deploy, etc.).
6. Edit mps_install.txt file such that it contains the full path (root directory) to your MPS installation, with no newline. For example:
C:\Program Files\MATLAB\MATLAB Production Server\R2013b
7. Using the Windows command prompt, run one of the following commands as Administrator from inside the instance directory.
When working with 32-bit MPS/MCR:
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" MPS_Service_Wrapper.exe
When working with 64-bit MPS/MCR:
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe" MPS_Service_Wrapper.exe
(NOTE 1: The framework version number may be slightly different on your system.)
(NOTE 2: If you ever need to uninstall the service use the same command but add the /u option.)
8. It should ask you for user credentials for the user that MPS will run as. Give the required login credentials.
9. This step is only required when working with 32-bit MPS/MCR on a 64-bit Windows system: create MPS_ARCH as a system environment variable with a value of win32. To do this:
Go to Control Panel > System and Security > System > Advanced System Settings > Environment Variables.
In the System variables section, add a new variable with MPS_ARCH as the name and with a value of win32.
10. Go to Start > Administrative Tools > Services.
11. You should see MATLAB Production Server listed as a service. Click start.
12. Your instance should be running, and should stay running even if you log off. You should be able to set the instance to start automatically when the system boots as well by right clicking and accessing the properties of the service. To do this, make sure to select the "Automatic (Delayed Start)" option instead of just the "Automatic" option.
13. Note that the Windows firewall may behave differently for services compared to normal applications and you may need to specifically open the port on which your MPS instance is running to allow external applications to connect.
Troubleshooting
- If you receive an error:
Exception occurred while initializing the installation:
System.IO.FileLoadException: Could not load file or assembly 'file:///C:\MPSInstance\MPS_Service_Wrapper.exe' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515).
While running InstallUtil.exe, please double check whether step 4 was performed correctly.
- If the service does not start correctly under step 11, please use the Windows "Event Viewer" and go to "Applications and Services Logs" -> "MPS_Service_Wrapper_Log" and have a look at the logged messages, these should offer a clue to what exactly went wrong. If you need help in interpreting the error messages please contact our Technical Support department.
Updates
Monday, June 8 2015
- Added mention of official support in R2015a with mps-service
Friday October 3 2014
- Added support for spaces in MPS instance paths.
- Errors are now logged in Error (instead of Information) category in Windows Event Log.