How to start a BAT file through nodejs? - node.js

I want to restart mongodb(the code is in a .bat file) by nodejs , if it was stopped by accident.
Is there any module can do this job?

Based on your latest two comments, there's a few things that you should take note of.
You are unable to restart the mongo windows service because there is a lock file. The CPU increases because mongod is attempting an automatic restart.
When the mongod process/service is uncleanly shutdown, there will be a lock file under your data path. Perform a dir on the data directory and I believe that you will find the lock file mongod.lock there.
You do not need to reboot your PC, simply remove the lock file (you may need to disable the service to do that) and restart the service.
There two SERVER tickets that are related to the restart behaviour on Windows -
Ticket 3582 - this fix (where an automatic restart of mongod no longer occurs) is from version 2.1.0 onwards. 2.1.x is the development branch.
MongoDB 2.2.0-rc0 was recently released and is ready for testing. It is the culmination of the 2.1.x development series.
2.2 Release Notes: http://docs.mongodb.org/manual/release-notes/2.2
Downloads: http://www.mongodb.org/downloads
Change Log: https://jira.mongodb.org/browse/SERVER/fixforversion/11218
Ticket 2, which is currently in the planning stage and will be a longer-term fix.

It would be much better to install MongoDB as a Windows Service instead of running from a .bat file.
Then you can use the normal service features such as automatic startup and recovery.

Related

MongoDB runs FTDC

So I just installed mongoDB and when i activate run it, it runs fine, but it gives me this warning or error:
2017-07-24T12:48:44.119-0700 I FTDC [ftdc] Unclean full-time diagnostic data capture shutdown detected, found interim file, some metrics may have been lost. OK
mongoDB warning
Now I have my PATH going to the right place:
C:\Program Files\MongoDB\Server\3.4\bin
I also have my data file in the right place as well: C:\data\db
The folder is full of different files from mongoDB.
I looked into my DBs and everything is still saved and no files have been corrupted or missing.
If anyone can help, that would be greatly appreciated. Thanks!
This error means that your MongoDB deployment was not shutdown cleanly. This is also shown in the screenshot of the log you posted, where it said Detected unclean shutdown. Typically this is the result of using kill -9 in UNIX environment, force killing the mongod process. This could also be the result of a hard crash of the OS.
CTRL-C should result in a clean shutdown, but it may be possible that something interferes with mongod during its shutdown process, or there is an OS hard restart during the shutdown process. To shutdown your mongod cleanly, it's usually best to send a db.shutdownServer() command inside the mongo shell connected to the server in question.
FTDC is diagnostic data that is recorded by MongoDB for troubleshooting purposes, and can be safely removed to avoid the FTDC startup warning you are seeing. In your deployment, the diagnostics data should be located in C:\data\db\diagnostics.data directory.
The WiredTiger storage engine is quite resilient and were designed to cope with hard crashes like this. However, if it's a hardware/OS crash, it's best to check your disk integrity to ensure that there is no hardware-level storage corruption. Please refer to your OS documentation for instructions on how to check for storage integrity, as methods differ from OS to OS on how to perform this.

Keep node in running state even after user log-off

How to keep a node application running in windows even when user logs off?
Also how to keep running a node http-server even after user log-off?
You have 2 great options. One is as mentioned in comments above Forever.
The other is PM2 which is easy to install and offers an incredible amount of options. I use this in all projects, but I cannot attest to the Windows version as I am on Linux & Ubuntu servers and work on a Mac. You can daemonize your node process, follow logs, cluster it and make sure the process reboots even with a server shutdown (it is a service).
windows task scheduler: execute node.exe: start in project folder: and argument (app.js)

What's the process of updating a NodeJS running in production?

I am working on a webapp that will be published in production and then updated on regular basis as features and bug fixes are coming.
I run it like node app.js which loads config, connects to database, starts web server.
I wonder, what's the process of updating the app when I have next version?
I suppose, I have to kill the process and start after update and deploy? It means, that there will be some downtime?
Should I collect stats on the least use during the week/month and apply the update during that period? Or should I start the current version on another machine, redirect all requests to it and update the main one, then switch back?
I think the second approach is better.
The first one won't prevent downtime, it will just make sure it impacts the least number of users, while the second one creates no down-time at all.
Moreover, I think you should keep the old version running in the other machine for some time in case you will find out the new version must be reverted due to whatever reason. In that case you will just have to redirect traffic to the old node without any downtime.
Also, if you're setting up production environment I would recommend that instead of just running your process with "node" command, you will use something like forever or pm2 in order to do automatic restarts and some other advanced features.

OpenOffice Daemon Problem

I'm using OpenOffice as a daemon. Sometimes, when the daemon is running a long time, CPU use spikes very high and then openoffice crash. At this point, the open office applicattion don't work and the documents don't be generated.
How can I restart automatically the openoffice daemon when this problem happens? Is there any way to monitor the service or to program a watchdog to handle it?
Thanks in advance, regards.
You may wish to use your distribution's services mechanism; Ubuntu and Fedora, for example, use upstart. Writing an upstart configuration file for your service probably wouldn't be too difficult.
If your distribution doesn't use upstart, you could either run it directly out of your /etc/inittab or use daemontools to monitor your service. (The linux-ha project also has some service monitoring tools, but may have more setup-requirements than you're interested in.)

How can I write a script to keep HSQLDB running in case the process is killed

I'm running HSQLDB in server mode on a Linux server and finding that it occasionally gets killed. I'd like to be able to detect that it's stopped running and then kick off a process that starts it up again.
The DB isn't running very often, so polling would have to be very frequent--once every five minutes.
Look at Monit:
Monit is a free open source utility for managing and monitoring, processes, files, directories and filesystems on a UNIX system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations.
If you are using soem type of Debian, you might try installing HSQLDB using "apt-get install hsqldb-server. That will give you a nice install and the ability to start with "/etc/init.d/hsqldb-server start"
This will also take care of restarting it if your machine reboots. If you get everything installed correctly the problem of it getting killed may just go away.
I was running into some weird issues starting and stopping hsqldb, but once I got it installed correctly everything took care of itself.

Resources