How do you rerun dnx. Kestrel command on any file changes?

How can I restart the kestrel server on every file change? and not just stop?

I tried

dnx --watch . kestrel

      

but the server just stops and I need to rerun the command

I also tried using the npm watch command, but it seems like a simple walkthrough

watch 'dnx --watch . kestrel' .

      

+3


source to share


5 answers


I found the following work using nodemon from

https://github.com/johnpapa/aspnet5-starter-demo#dnxmon



nodemon --ext "cs,json" --exec "dnx . kestrel"

      

+1


source


You can use the dnx-watch command for this. It did not exist when the original question was asked, but was added in beta 8 in September 2015. You install it with

dnu commands install Microsoft.Dnx.Watcher

      

Start it by simply giving it the command you would give dnx. So, replace

dnx web

      



from

dnx-watch web

      

You can read more here: http://ardalis.com/get-started-with-dnx-watch

+5


source


This is by design. Today there is no out-of-the-box solution for automatically restarting the server after it stops due to the file watcher.

Visual Studio has special code that monitors the process and restarts it.

However, we are tracking this issue and we plan to address it in a future iteration.

0


source


Although the selected solution is shorter, here is what I am doing in an angular application that is managed from grunt

The application has an interface and a server-side api.

First there is a task shell

to start the api:

shell: {
  api:{
    options: {
      execOptions : {
        cwd: '..\\$working_directory'
      },
      callback : function (err, stdout, stderr, cb) {
        restartServer('shell:api',err,cb);
      }
    },
    command: function() {
      return 'dnx --watch localfarm';
    }
  },

      

at the top of mine gruntfile

I define a function that restarts the server:

var restartServer = function (task, err, cb) {   

var timeoutInSec = 30;
if (err === null)
  timeoutInSec = 2;

grunt.log.write(task + ' Task ended. Retrying in ' + timeoutInSec + ' seconds');

setTimeout(function() {
  grunt.log.write('retrying ' + task );
  grunt.task.run(task);
  cb();
}, timeoutInSec*1000);   };

      

Every time something changes in the code, the process dnx --watch

is killed automatically. grunt

then waits 2 seconds and restarts the process dnx

. If it dnx

doesn't work, it waits 30 seconds until it tries again. This gives me time to fix the code. (In my version of the code, I also use the beep

api to get notification on reload.)

To start the farm (frontend and backend), I added a parallel task that starts multiple threads:

concurrent: {
...
  farm: {
    tasks: ['shell:api', 'serve'],
    options: { logConcurrentOutput: true, limit: 10 }
  }
...
}

      

0


source


this command works better on windows (if you have kestrel command installed):

nodemon --ext "cs, json" --exec "dnx --watch kestrel"

> Blockquote
C:\Users\name\YoWebApp>**nodemon --ext "cs,json" --exec "dnx . kestrel"**
6 Oct 14:46:13 - [nodemon] 1.7.1
6 Oct 14:46:13 - [nodemon] to restart at any time, enter `rs`
6 Oct 14:46:13 - [nodemon] watching: *.*
6 Oct 14:46:13 - [nodemon] starting `dnx . kestrel`
System.InvalidOperationException: Unable to load application or execute command '.'. Available commands: kestrel, web, ef, mon.
   at Microsoft.Dnx.ApplicationHost.Program.ThrowEntryPointNotfoundException(DefaultHost host, String applicationName, Exception innerException)
   at Microsoft.Dnx.ApplicationHost.Program.ExecuteMain(DefaultHost host, String applicationName, String[] args)
   at Microsoft.Dnx.ApplicationHost.Program.Main(String[] args)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
   at Microsoft.Dnx.Host.Bootstrapper.RunAsync(List`1 args, IRuntimeEnvironment env, FrameworkName targetFramework)
   at Microsoft.Dnx.Host.RuntimeBootstrapper.ExecuteAsync(String[] args, FrameworkName targetFramework)
   at Microsoft.Dnx.Host.RuntimeBootstrapper.Execute(String[] args, FrameworkName targetFramework)
6 Oct 14:46:14 - [nodemon] app crashed - waiting for file changes before starting...
6 Oct 14:46:44 - [nodemon] restarting due to changes...
6 Oct 14:46:44 - [nodemon] starting `dnx . kestrel`
System.InvalidOperationException: Unable to load application or execute command '.'. Available commands: kestrel, web, ef, mon.
   at Microsoft.Dnx.ApplicationHost.Program.ThrowEntryPointNotfoundException(DefaultHost host, String applicationName, Exception innerException)
   at Microsoft.Dnx.ApplicationHost.Program.ExecuteMain(DefaultHost host, String applicationName, String[] args)
   at Microsoft.Dnx.ApplicationHost.Program.Main(String[] args)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
   at Microsoft.Dnx.Host.Bootstrapper.RunAsync(List`1 args, IRuntimeEnvironment env, FrameworkName targetFramework)
   at Microsoft.Dnx.Host.RuntimeBootstrapper.ExecuteAsync(String[] args, FrameworkName targetFramework)
   at Microsoft.Dnx.Host.RuntimeBootstrapper.Execute(String[] args, FrameworkName targetFramework)

      

0


source







All Articles