# lxstartplus

Microservice Install and Run Tool

## Getting Started
Install the module with: `npm install --global lxstartplus`

## Documentation

### lxclone

In order to pull all of the appropriate microservice folders, run
`lxclone`. The command pulls from the Lanetix GitHub repository and does an
`npm install` on each of the folders.

  Note: The included microservice.json file must be updated when microservices
  are added to the GitHub repo otherwise the microservice will not be pulled.
  Please double-check your formatting in the json file when you add another
  microservice -- thanks!

### lxcreatestack

see [`lxstack`](#lxstack)

### lxinfo

Use `lxinfo -p PORT -s SERVICE` get information about what port a service might
be running on or what service a particular port is listening on. Pass no args
to get a list of all of the services contained in `microservice.json`

### lxngrok

`lxngrok` starts ngrok, loading all the tunnels configured by `lxngrokmk`.

### lxngrokmk

```
lxngrokmk lx-apechimp
```

Generates an ngrok config with the specified namespace, e.g., `lx-apechimp`. In
order for the services to run, you should run `lxsetenv -n <namespace>` to get
everything to use the correct urls.

### lxrestart

Use `lxrestart [service]` to restart a given service. Uses `lxkill` and `lxservice`
under the covers.

### lxservice

Once you've pulled down all of the services that you may need from GitHub,
use `lxservice [profile]` to get them running en masse for your local server.

Currently, there are two profiles available for users:

* default -- Starts 'api', 'auth', 'search', 'ui', 'records-views', 'gateway', 'records', 'layouts', 'stream', 'stagegate'

Without specification, `lxservice` defaults to the default profile.

You can also specify your own custom defaults via:

* `LXSERVICE_DEFAULT`: override the defaults (comma-delimited)
* `LXSERVICE_DEFAULT_ADD`: add additional defaults (comma-delimited)

You can also specify specific services. For more information, `lxservice -h`

### lxstart

Alias for [`lxservice`](#lxservice)

### lxports

`lxports` shows you what's running, their relevant ports and PIDs. Useful if
you want to stop services or you need to know more about what's running.

**NEW:** Add `-w` to see workers processes.

### lxkill

`lxkill <service> [<second-service> ...]` or `lxkill all`

kills the specified service(s). `lxkill all` will kill all lanetix services

### lxpsql

`lxpsql`

starts psql but for the lanetix database. It's just `psql -d lanetix` 😝

### lxpullall

`lxpullall`

pulls latest versions of all services, `npm install`s and `npm run migrate-up`s.

### lxrevdep

```
lxrevdep <npm-package>
```

rev an npm-package to the latest version for all the services. It'll make
a branch with the updated `package.json`, `update-<npm-package>` and push it to
github for you, so all you have to do is open a bunch of PRs or
```
lgit push origin update-<npm-package>:master
```
if you like to live on the edge.

### lxrmqstart / lxrmqstop

`lxrmqstart`, `lxrmqstop`

starts / stops RabbitMQ

### lxrejiggerhomunculi

```
lxrejiggerhomunculi
```

Stash all your code, checks out and pulls master, runs npm install/migrate and
then restarts all of them.

### lxsetenv

```
lxsetenv -d ec2-52-90-35-212.compute-1.amazonaws.com
```
or
```
lxsetenv -n lx-apechimp
```
or, to reset to local,
```
lxsetenv -r
```

Write a configuration of all the environment variables for the microservice
uris when you need to talk to a non-local Lanetix.

### lxstack

```
lxstack <name>
```

Creates (or updates) a stack with `name` from the cloudformation template in
`~/env/dev`.  Once the stack has been created, this stores the output of the
stack in `~/.lx.aws.env`.

### lxdynamocp

```
lxdynamocp -s production-InboxTable-797DECO4Q2X3 -t lxsandbochs-InboxTable-1EDC04QF427PC
```

Copies source DynamoDB table to target table. Production tables cannot be defined as target tables.
Table names can be listed by running `lxdynamols`. If copying is slow, you will need to increase
the target table's write capacity in the DyanmoDB AWS control panel.

### lxdyanmols

```
lxdynamols
```

Lists all DynamoDB table names in the Lanetix AWS account.

### starting workers with your service

```
...
"records": {
  "port": 5025,
  "workers": [ // script name of worker to start (eg npm run start-import-worker)
    "start-export-worker",
    "start-import-worker",
    "start-stagegate-worker"
  ]
},
...
```

###If your Postgres server won't start when you restart
Try:
```
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
```

If that doesn't work, and restarting again doesn't fix the issue, then and ONLY then run the following command. WARNING: This may corrupt existing data so use only as a last resort, and make sure that Postgres isn't running before executing (the below command will do this automatically):
```
ps -ef | grep -v grep | ( ! grep postgres ) && rm /usr/local/var/postgres/postmaster.pid
```
