I installed loopback on my server (ubuntu) and then created an app and use the command slc run to run... everything works as expected. Now i have 1 question and also 1 issue i am facing with:
The question: i need to use slc run command but to keep the app "alive" also after i close the terminal. For that i used the --detach option and it works, What i wanted to know if the --detach option is the best practice or i need to do it in a different way.
The issue: After i use the --detach i don't really know how to stop it. Is there a command that i can use to stop the process from running?
To stop a --detach
ed process, go to the same directory it was run from and do slc runctl stop
. There are a number of runctl
commands, but stop
is probably the one you are most interested in.
Best practices is a longer answer. The short version is: don't use --detach
ever and do use an init script to run your app and keep it running (probably Upstart, since you're on Ubuntu).
slc run
If you wan to run slc run
as an Upstart job you can install strong-service-install with npm install -g strong-service-install
. This will give you sl-svc-install
, a utility for creating Upstart and systemd services.
You'll end up running something like sudo sl-svc-install --name my-app --user youruser --cwd /path/to/app/root -- slc run .
which should create a Upstart job named my-app
which will run your app as your uid from the app's root. Your app's stdout/stderr will be sent to /var/log/upstart/my-app.log. If you are using a version of Ubuntu older than 12.04 you'll need to specify --upstart 0.6
and your logs will end up going to syslog instead.
slc pm
Another, possibly easier route, is to use slc pm
, which operates at a level above slc run
and happens to be easier to install as an OS service. For this route you already have everything installed. Run sudo slc pm-install
and a strong-pm
Upstart service will be installed as well as a strong-pm
user to run it as with a $HOME of /var/lib/strong-pm.
Where the PM approach gets slightly more complicated is that you have to deploy your app to it. Most likely this is just a matter of going to your app root and running slc deploy http://localhost:8701/
, but the specifics will depend on your app. You can configure environment variables for your app, deploy new versions, and your logs will show up in /var/log/upstart/strong-pm.log.
For either of the options above, I recommend not doing npm install -g strongloop
on your server since it includes things like yeoman generators and other tools that are more useful on a workstation than a server.
If you want to go the slc run
route, you would do npm install -g strong-supervisor strong-service-install
and replace your slc run
with sl-run
.
If you want to go the slc pm
route, you would do npm install -g strong-pm
and replace slc pm-install
with sl-pm-install
.
I work at StrongLoop and primarily work on these tools.
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