How to Run Servicestack on Linux/Mono

What is the best way to run ServiceStack on Linux / Mono?


Update for Linux

From the v4.5.2 Release ServiceStack now supports .NET Core which offers significant performance and stability improvements over Mono that’s derived from a shared cross-platform code-base and supported by Microsoft's well-resourced, active and responsive team. If you’re currently running ServiceStack on Mono, we strongly recommend upgrading to .NET Core to take advantage of its superior performance, stability and its top-to-bottom supported Technology Stack.

Update for Mono

Our recommended Setup for hosting ASP .NET sites on Linux and Mono is to use nginx/HyperFastCgi. We've published a step-by-step guide going through creating an Ubuntu VM from scratch complete with deploy / install / conf / init scripts at mono-server-config.

We're no longer recommending MonoFastCGI after noticing several stability and performance issues. This blog post provides a good analysis of the performance, memory usage and stability of the different ASP.NET Hosting options in Mono.


Development

XSP is similar to VS.NET WebDev server - a simple standalone ASP.NET WebServer written in C#. This is suitable for development or small work loads. You just run it from the root directory of your ServiceStack ASP.NET host which will make it available at http://localhost:8080.

Production

For external internet services you generally want to host ServiceStack web services as part of a full-featured Web Server. The 2 most popular full-featured web servers for Linux are:

Nginx

Use Mono FastCGI to host ServiceStack ASP.NET hosts in Nginx.

Apache

Use mod_mono to host ServiceStack ASP.NET hosts in an Apache HTTP Server.

Self Hosting

ServiceStack also supports self-hosting which lets you run your ServiceStack webservices on its own in a standalone Console application (i.e. without a web server). This is a good idea when you don't need the services of a full-featured web server (e.g: you just need to host web services internally on an Intranet).

By default the same ServiceStack Console app binary runs on both Windows/.NET and Mono/Linux as-is. Although if you wish, you can easily daemonize your application to run as a Linux daemon as outlined here. The wiki page also includes instructions for configuring your self-hosted web service to run behind an Nginx or Apache reverse proxy.

Since it provides a good fit for Heroku's Concurrency model as detailed in their 12 factor app self-hosting will be an area we'll be looking to provide increased support around in the near future.

ServiceStack.net Nginx / Mono FastCGI configuration

The servicestack.net website itself (inc. all live demos) runs on an Ubuntu hetzner vServer using Nginx + Mono FastCGI.

This command is used to start the FastCGI background process:

fastcgi-mono-server4 --appconfigdir /etc/rc.d/init.d/mono-fastcgi 
/socket=tcp:127.0.0.1:9000 /logfile=/var/log/mono/fastcgi.log &

Which hosts all applications defined in *.webapp files in the /etc/rc.d/init.d/mono-fastcgi folder specified using XSP's WebApp File Format, e.g:

ServiceStack.webapp:

<apps>
<web-application>
<name>ServiceStack.Northwind</name>
<vhost>*</vhost>
<vport>80</vport>
<vpath>/ServiceStack.Northwind</vpath>
<path>/home/mythz/src/ServiceStack.Northwind</path>
</web-application>
</apps>

This runs the FastCGI Mono process in the background which you can get Nginx to connect to by adding this rule to nginx.conf:

location ~ /(ServiceStack|RedisAdminUI|RedisStackOverflow|RestFiles)\.* {  
root /usr/share/nginx/mono/servicestack.net/;
index index.html index.htm index.aspx default.htm Default.htm;
fastcgi_index /default.htm;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /usr/share/servicestack.net$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}

Which will forward any route starting with /ServiceStack or /RedisAdminUI, etc to the FastCGI mono server process for processing. Some example apps hosted this way:

  • http://www.servicestack.net/ServiceStack.Northwind/
  • http://www.servicestack.net/ServiceStack.Hello/
  • http://www.servicestack.net/RedisAdminUI/AjaxClient/
  • http://www.servicestack.net/RedisStackOverflow/

For those interested the full Nginx + FastCGI configuration files for servicestack.net are available for download.

Hosting SeviceStack on Mono without a webserver

I have successful done this. I have done that to run on heroku. If you are interested project is hosted over github. Code currently in F# but you can easily convert that to C#. And it is port of Razor project you find out at servicestack github . It work with mono. If you want any specific details please let me know.

Run ServiceStack Console as Daemon on DigitalOcean

This worked. I added a user geoapiconsole and added the -S and -c switches, then I followed with initctrl start GeoAPIConsole

# ServiceStack Example Application

description "ServiceStack Example"
author "ServiceStack"

start on started rc
stop on stopping rc

respawn

exec start-stop-daemon -S -c geoapiconsole --exec /usr/bin/mono /var/console/GeoAPIConsole.exe

Host ServiceStack, MVC3 or MVC4 on mono or windows and what is the state of mono


ServiceStack.net has always run on Linux/Mono

Note all live demos hosted on servicestack.net are running on an Ubuntu linux vServer. servicestack.net has always been hosted on Linux/Mono for years, in-fact before moving to an Ubuntu vServer from hetzner our old CentOS server had an up-time of 480 days. We consider Mono an increasingly important platform to support as we expect the advent of linux-only clouds to be an important competitive advantage since it allows you to scale at $0 software licensing cost.

Developing on Windows with VS.NET and deploying to Mono/Linux

For all of ServiceStack live demos we develop on Windows with VS.NET but we git-deploy and build and host on Linux. As outlined in our Release Notes we take special care to support Mono as a first-class citizen where we apply normalizing behaviour as much as possible so porting an existing IIS/ASP.NET site remains trivial (i.e. you should be able to copy and run the binaries as-is!) - this extends to the external dependencies we adopt which are influenced by their support of Mono.

All demos including the Razor Live demo is hosted on Mono/Linux

All ServiceStack demos are hosted on Linux, this includes the Razor example which has 2 versions deployed and hosted on Mono, i.e.

  • razor.servicestack.net - ASP.NET Hosted live demo powered by Linux / Nginx / MonoFastCGI
  • razor-console.servicestack.net - Self-Hosted Console App hosted behind Nginx Reverse Proxy

You may want to look at this question for different ways to host ServiceStack on Linux.

Servicestack self host app System.TypeloadException when using mono in ubuntu

Try setting MONO_LOG_LEVEL and optionally MONO_LOG_MASK such as:
MONO_LOG_LEVEL=debug MONO_LOG_MASK=asm mono --debug appname.exe
and see whether the output helps troubleshoot the problem.

HTTP performance on linux/mono


v4.5.2 Update

ServiceStack added support for .NET Core in its v4.5.2 Release which is now the recommended and supported option for running ServiceStack on Linux.


Are there any known performance issues with a Servicestack self host service (or indeed any http listener) running on linux/mono?

Mono's HTTP Stack is slow and unstable for heavy workloads, it's fine for small workloads but we don't recommend it for production workloads. We've documented the most reliable setup we've found to run on Mono using HyperFastCI + nginx, e.g:

  • https://github.com/ServiceStackApps/mono-server-config
  • https://github.com/ServiceStackApps/mono-docker-config

The future of hosting ServiceStack and .NET on Linux is .NET Core which is fast, stable and well supported. ServiceStack's support for .NET Core will be announced in the next v4.5.2 Release Notes to be announced later this week.



Related Topics



Leave a reply



Submit