We are using iisnode with IIS 7.5 on a Windows 2008R2 Server. The node.js app loads some config data when it starts. From time to time the config data changes and the app needs to be restarted.
When restarting the IIS site instance by the Windows System Manager console everything works fine.
When restarting the IIS by appcmd stop
and appcmd start
commands the node.js-app is not launched again. It looks like iisnode does not recognize the restart of the IIS.
How can a node.js application in an iisnode environment be restarted by a command (i.e. via the command line)?
You can automatically recycle the site through IISNode using the watchedFiles
attribute on the iisnode
element in your Web.config
file. I know this isn't through the command line but from your question it seems like this would also solve the problem and not require any manual intervention from someone.
Using the below info, you can set IISNode to watch your config file(s) and whenever they changes IISNode will recycle the site.
Comment from IISNode Sample Config
watchedFiles - semi-colon separated list of files that will be watched for changes; a change to a file causes the application to recycle;
each entry consists of an optional directory name plus required file name which are relative to the directory where the main application entry point is located;
wild cards are allowed in the file name portion only; for example: "*.js;node_modules\foo\lib\options.json;app_data*.config.json"
Example iisnode
element from Web.config that will recylce the site whenever the Web.config changes or any .js files in the top level folder of the app.
<iisnode
node_env="%node_env%"
nodeProcessCountPerApplication="1"
maxConcurrentRequestsPerProcess="1024"
maxNamedPipeConnectionRetry="100"
namedPipeConnectionRetryDelay="250"
maxNamedPipeConnectionPoolSize="512"
maxNamedPipePooledConnectionAge="30000"
asyncCompletionThreadCount="0"
initialRequestBufferSize="4096"
maxRequestBufferSize="65536"
uncFileChangesPollingInterval="5000"
gracefulShutdownTimeout="60000"
loggingEnabled="true"
logDirectory="iisnode"
debuggingEnabled="true"
debugHeaderEnabled="false"
debuggerPortRange="5058-6058"
debuggerPathSegment="debug"
maxLogFileSizeInKB="128"
maxTotalLogFileSizeInKB="1024"
maxLogFiles="20"
devErrorsEnabled="true"
flushResponse="false"
enableXFF="false"
promoteServerVars=""
configOverrides="iisnode.yml"
watchedFiles="web.config;*.js"
nodeProcessCommandLine="C:\Program Files (x86)\nodejs\node.exe" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With