How to run Node.JS Loopback + Forever? - loopbackjs

How do I run StrongLoop's Loopback with Forever so that the app is automatically restarted after ever change?
So far just running forever server/server.js doesn't seem to work...

Maybe you should run it with the watch flag like
forever -w entrypoint.js

Thanks. I have found that the best script is this:
"scripts": {
"start": "forever --verbose --uid \"myapp\" --watch --watchDirectory ./server server/server.js"
},
Each part means:
--verbose: Log all details (useful when developing new routes)
--uid \"myapp\": So that "myapp" will appear when you do a forever list
--watch: Watch for file changes
--watchDirectory ./server: The folder to watch for changes
server/server.js: The app entry point
Additionally I open it with like nohup npm start & so that the process will keep running in the background and the output will be appended to a nohup.out file.

Related

How to make GCP start script to start multiple processes?

So, I'm using Google Cloud Platform and set below startup script
#! /bin/bash
cd /home/user
sudo ./process1
sudo ./process2
I worried about this script because process1 blocks shell and prevent to run sudo ./process2. And it really was. process1 was started successfully but process2 was not started.
I checked that script has no problem with starting process1 and process2. Execute ./process2 via SSH worked but after I close the SSH shell and process2 was stopped too.
How can I start both process in booting time(or even after)?
I tried testing your startup script in my environment,it seems the script works well.
1.You can please try checking process1 and process2 scripts.
2.If you want your process to run in the background even after the SSH session is closed, you can use “&” { your_command & }at the end of your command.
To run a command in the background, add the ampersand symbol (&) at the end of the command:
your_command &
then the script execution continues and isn't blocked. Or use linux internal means to auto run processes on boot.

How can I use a batch file to run Vagrant commands, but leave me connected to Vagrant once finished?

Here's what I have in the batch file so far:
set root="C:\Users\esohlberg\lwebsite"
cd %root%
vagrant up
vagrant ssh -- -t "source lw/bin/activate && cd /vagrant/; ./manage.py runserver 0.0.0.0:8000"
cmd /k
Once Vagrant is up, I activate a virtualenv, cd into the right place, and run a server. Executing this takes me all the way to the server running, where I can see
System check identified no issues (0 silenced).
August 24, 2018 - 12:33:12
Django version 2.0.3, using settings 'lwebsite.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
However, as soon as I quit with CONTROL-C, I see
Connection to 127.0.0.1 closed.
and I'm no longer in Vagrant. Is it possible to set up the commands in such a way that once the server is quit, I stay in the /vagrant/ directory with the connection still up and Vagrant's virtualenv still active? This would allow me to manage the site or run the server again with less hassle.
I've already looked at https://www.vagrantup.com/docs/provisioning/shell.html, but the examples seem to show commands executed only during provisioning, which I don't want to do every single time I execute this file.
I created three .bat files to start, stop vagrant and connect over ssh.
For starting vagrant, also added this to auto run when Windows starting:
cd /d "C:\Homestead"
start vagrant up
For stoping vagrant:
#echo off
cd /d "C:\Homestead"
start vagrant halt
And for connecting to local server over ssh
cd /d "C:\Homestead"
vagrant ssh
I've already looked at https://www.vagrantup.com/docs/provisioning/shell.html, but the examples seem to show commands executed only during provisioning, which I don't want to do every single time I execute this file.
You've been looking at the right place, what you want is to run the command when the VM starts so you can do the following:
config.vm.provision "shell", :inline => "source lw/bin/activate && cd /vagrant/; ./manage.py runserver 0.0.0.0:8000", :run => 'always', :privileged => false
That will make sure that every time you're calling vagrant up from your host, it will start your python server (as vagrant user)
This way you do not need the script anymore and can just start your VM normally using vagrant up

npm run and kill background porcess synchronously

Currently I'm setting up some integration/api test's for my nodejs express application. The routes I'm testing does require a connection to AWS-DynamoDB for some CRUD operations on the tables.
Now for the purpose of not messing around with my current table data, I have decided to run the tests on a local db. AWS offers a way to run DynamoDB locally. After installing (extracting) the tar/zip to the correct location, I just have to run a command which does start a local server on port 8000.
command:
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar
-sharedDb -inMemory
Now I want to preapare a script in my package.json file to do the following tasks.
start the local db by the given command
wait some seconds so the server is setup and ready (timeout 2 seconds)
run the tests (which also does create the necessary tables with entries)
shut down the local db (kill the process of "1.")
My attempt looks like the following:
"scripts": {
"test:int": "npm run db:setup && npm run test:int:run && npm run db:kill",
"test:int:run": "./node_modules/mocha/bin/mocha test/integration/**.spec.js",
"db:setup": "java -Djava.library.path=~/opt/DynamoDBLocal_lib -jar ~/opt/DynamoDBLocal.jar -sharedDb -inMemory",
"db:kill" : "dont know what to do here"
}
My Problems here:
Now I dont know exactly how to run the processes synchronously including the timeout of 2 seconds so the local db is ready to handle the requests.
I also need a way to consistently shut down the local db at the end ("4." / "db:kill")

How can I curl 127.0.0.1/8000 while django development server is running?

I have never ran into this before because I can always just run the dev server, open up a new tab in terminal and curl from there. I can't do this now because I am running the Django Development server from a Docker container and so if I open a new tab, I will be in the local shell and not the docker container.
How can I leave the development server running and still be able to curl or run other commands?
When I run the development server I'm left with this message:
Django version 1.10.3, using settings 'test.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
and so unable to type any commands.
You can use & to run the server as a background job in the current shell:
$ python manage.py runserver &
[1] <pid>
$
You can use the fg command to get back direct control over the runserver process, then you can stop it as usual using Ctrl+C.
To set a foreground process as a background job, you can pause it using Ctrl+Z, and run the bg command. You can see a list of running backgrounds job in the current shell using the jobs command.
The difference with screen is that this will run the server in the current shell. If you exit the shell, the server will stop as well, while screen uses a separate process that will continue after you exit the current shell.
In a development environment you can do following also.
Let the server run in one terminal window.
Open a new terminal window/tab and run
docker exec -it <Container ID/Name> /bin/bash
It will give you interactive access to your container, i.e. you can execute any command in your container rather than in your local shell.
Type exit to come out container shell to local shell.

Hyperledger: 'membersrvc' not Responding

My Development Environment has already started after all the pre-requisites needed:
vagrant up
vagrant ssh
make membersrvc
make peer
But when trying to Start the membersrvc by doing membersrvc after coming into the folder $ cd $GOPATH/src/github.com/hyperledger/fabric, It is not Responding!
No Response even after One Hour!
Any suggestions?
This is exactly how membersrvc supposed to behave. when you execute membersrvc command you don't see any output whatsoever, however you can verify that it is running by opening a separate terminal window and running
ps -a | grep membersrvc
command.
Besides, as Sergey Balashevich commented, you also need to make sure that membersrvc is started and running beforepeer process will be able to get a valid certificate, which means that you need to start both membersrvc and peer process in separate terminal windows simultaneously.
If you want to run all the processes in a single terminal window you can execute them in background asmembersrvc > result 2>&1 & it will start the process and redirect both stdout and stderr to a result file which you can specify. If you don't care about the output at all - you can use /dev/null instead of specifying the file.