Starting the application with CLI command
This commit is contained in:
parent
de52702f8d
commit
759c338657
2 changed files with 61 additions and 4 deletions
42
README.md
42
README.md
|
@ -20,7 +20,9 @@ Service is built with Python, FastAPI and is using Redis for data storage.
|
||||||
|
|
||||||
### How to install
|
### How to install
|
||||||
|
|
||||||
The recommended installation method is with the [pipx](https://pipx.pypa.io/stable/)
|
#### Quick way
|
||||||
|
|
||||||
|
If you don't need to configure a lot of things, you can install from [pipx](https://pipx.pypa.io/stable/)
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ pipx install pssecret-server
|
$ pipx install pssecret-server
|
||||||
|
@ -32,12 +34,48 @@ For better performance, install application with [hiredis](https://github.com/re
|
||||||
$ pipx install pssecret-server[hiredis]
|
$ pipx install pssecret-server[hiredis]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
After that just run the app with
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ pssecret-server
|
||||||
|
```
|
||||||
|
|
||||||
|
This will start the [uvicorn](https://www.uvicorn.org/) server on `127.0.0.1:8000`.
|
||||||
|
Available configuration options:
|
||||||
|
|
||||||
|
```
|
||||||
|
--host TEXT Bind socket to this host. [default: 127.0.0.1]
|
||||||
|
--port INTEGER Bind socket to this port. If 0, an available port will be
|
||||||
|
picked. [default: 8000]
|
||||||
|
--uds TEXT Bind to a UNIX domain socket.
|
||||||
|
--workers INTEGER Number of worker processes. Defaults to the
|
||||||
|
$WEB_CONCURRENCY environment variable if available, or 1.
|
||||||
|
--help Show this message and exit.
|
||||||
|
```
|
||||||
|
|
||||||
|
#### If you'd like more control
|
||||||
|
|
||||||
|
Create virtual environment, install application, run using [uvicorn](https://www.uvicorn.org/) directly.
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ python -m venv .venv
|
||||||
|
$ source .venv/bin/activate
|
||||||
|
$ pip install pssecret-server
|
||||||
|
$ uvicorn pssecret_server.main:app --workers 4 --uds /path/to/socket.sock
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also run [uvicorn](https://www.uvicorn.org/) without activating virtualenv, e.g. from SystemD service
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ /path/to/your/.venv/bin/python -m uvicorn pssecret_server.main:app --workers 4 --uds /path/to/socket.sock
|
||||||
|
```
|
||||||
|
|
||||||
### Running Pssecret server
|
### Running Pssecret server
|
||||||
|
|
||||||
Make sure you have the Redis service running.
|
Make sure you have the Redis service running.
|
||||||
|
|
||||||
After installation is done, you can start pssecret server with `pssecret-server` command.
|
After installation is done, you can start pssecret server with `pssecret-server` command.
|
||||||
The web server will be started with `uvicorn` ASGI web server.
|
The web server will be started with [uvicorn](https://www.uvicorn.org/) ASGI web server.
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ pssecret-server
|
$ pssecret-server
|
||||||
|
|
|
@ -1,6 +1,25 @@
|
||||||
import click
|
import click
|
||||||
|
import uvicorn
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
def cli():
|
@click.option(
|
||||||
print("Hello, world")
|
"--host", default="127.0.0.1", show_default=True, help="Bind socket to this host."
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--port",
|
||||||
|
default=8000,
|
||||||
|
show_default=True,
|
||||||
|
help="Bind socket to this port. If 0, an available port will be picked.",
|
||||||
|
)
|
||||||
|
@click.option("--uds", help="Bind to a UNIX domain socket.")
|
||||||
|
@click.option(
|
||||||
|
"--workers",
|
||||||
|
help=(
|
||||||
|
"Number of worker processes. "
|
||||||
|
"Defaults to the $WEB_CONCURRENCY environment variable if available, or 1."
|
||||||
|
),
|
||||||
|
type=int,
|
||||||
|
)
|
||||||
|
def cli(**kwargs) -> None:
|
||||||
|
uvicorn.run("pssecret_server.main:app", **kwargs)
|
||||||
|
|
Loading…
Reference in a new issue