Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop detached strongloop application

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?

like image 981
Ran Hassid Avatar asked Jan 09 '23 19:01

Ran Hassid


1 Answers

To stop a --detached 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).

Using 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.

Using 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.

General Best Practices

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.

Disclaimer

I work at StrongLoop and primarily work on these tools.

like image 195
Ryan Graham Avatar answered Feb 19 '23 18:02

Ryan Graham