コンテンツにスキップ

gtc start

gtc start コマンドは Greentic runtime server を起動します。HTTP server、NATS bus、flow executor を含む必要なすべてのサービスを開始します。

Terminal window
gtc start [OPTIONS] <BUNDLE_PATH>
Option説明Default
--host <HOST>bind address0.0.0.0
--port <PORT>HTTP port8080
--cloudflared <on/off>Cloudflare tunnel を有効にするon
--ngrok <on/off>ngrok tunnel を有効にするoff
--nats <on/off>組み込み NATS を有効にするon
--skip-setupprovider の setup flows をスキップするfalse
--force-setupsetup flows を強制的に再実行するfalse
-v, --verboseverbose/debug logging を有効にするfalse
-q, --quiet最小限の出力にするfalse
Terminal window
gtc start ./my-bundle

これにより次が起動します:

  • 0.0.0.0:8080 上の HTTP server
  • 組み込み NATS server
  • Cloudflared tunnel(利用可能な場合)
Terminal window
# Use ngrok instead of cloudflared
gtc start ./my-bundle --cloudflared off --ngrok on
# With verbose logging
gtc start ./my-bundle --verbose
# Skip setup (if already configured)
gtc start ./my-bundle --skip-setup
Terminal window
# No tunnels, external NATS
gtc start ./my-bundle --cloudflared off --ngrok off
# Custom port
gtc start ./my-bundle --port 3000 --cloudflared off

Cloudflared は Cloudflare の network への安全な tunnel を作成します:

Terminal window
gtc start ./my-bundle --cloudflared on
# Output:
# Cloudflare tunnel started: https://random-words.trycloudflare.com
# Webhook URLs will use: https://random-words.trycloudflare.com

開発中に安定した URL が必要な場合は ngrok を使います:

Terminal window
gtc start ./my-bundle --ngrok on
# Output:
# ngrok tunnel started: https://abc123.ngrok-free.app
# Webhook URLs will use: https://abc123.ngrok-free.app

公開ドメインを使う本番環境では:

Terminal window
gtc start ./my-bundle --cloudflared off --ngrok off
# Make sure your server is publicly accessible
# and update provider webhooks with your domain
Terminal window
gtc start ./my-bundle --nats on
# Starts embedded NATS on localhost:4222
Terminal window
# Disable embedded, use external
gtc start ./my-bundle --nats off
# Set NATS URL via environment
GREENTIC_NATS_URL=nats://nats.example.com:4222 gtc start ./my-bundle --nats off

デフォルトでは、providers がまだ設定されていない場合に gtc start は setup flows を実行します:

Terminal window
gtc start ./my-bundle
# Runs setup flows for unconfigured providers

既存の設定を使って setup flows を完全にスキップします:

Terminal window
gtc start ./my-bundle --skip-setup

すべての setup flows を強制的に再実行します(URL 変更後に便利です):

Terminal window
gtc start ./my-bundle --force-setup

実行中、server は次を公開します:

Endpoint用途
GET /healthヘルスチェック
GET /readyreadiness probe
POST /webhook/{provider}/{tenant}/{team}provider webhooks
GET /api/v1/sessionssession 管理
POST /api/v1/messagesメッセージ送信
GET /auth/configOAuth 設定 endpoint
POST /oauth/token-exchangeserver-side OIDC token exchange proxy
Terminal window
curl http://localhost:8080/health
# {"status": "healthy"}

runtime は、ユーザー認証を必要とする messaging providers(WebChat や Teams など)との OAuth/OIDC 統合のために 2 つの endpoints を公開します。

secrets store から OAuth 設定を読み込み、client に返します。clients はこの endpoint を使って、認可フローを開始するために必要な identity provider の設定を取得します。

Terminal window
curl http://localhost:8080/auth/config
# {
# "authority": "https://login.microsoftonline.com/{tenant-id}/v2.0",
# "client_id": "your-client-id",
# "redirect_uri": "https://your-public-url/auth/callback",
# "scope": "openid profile"
# }

OIDC の authorization code exchange を行う server-side token exchange proxy です。この endpoint により、frontend から直接 identity provider の token endpoint を呼び出す際に発生する browser の CORS 制約を回避して、clients が authorization code を tokens に交換できます。

Terminal window
curl -X POST http://localhost:8080/oauth/token-exchange \
-H "Content-Type: application/json" \
-d '{"code": "authorization_code_here", "redirect_uri": "https://your-public-url/auth/callback"}'

Static routes(ヘルスチェックや OAuth endpoints など)は、明示的な public base URL がなくても設定できます。これにより、tunnel や公開 URL が確立される前でも、server の起動直後からこれらの endpoints を利用できます。

Terminal window
# Debug (most verbose)
GREENTIC_LOG_LEVEL=debug gtc start ./my-bundle
# Info (default)
GREENTIC_LOG_LEVEL=info gtc start ./my-bundle
# Warning
GREENTIC_LOG_LEVEL=warn gtc start ./my-bundle
Terminal window
gtc start ./my-bundle --verbose
# Equivalent to GREENTIC_LOG_LEVEL=debug
Terminal window
# JSON format (for production)
GREENTIC_LOG_FORMAT=json gtc start ./my-bundle
# Pretty format (for development, default)
GREENTIC_LOG_FORMAT=pretty gtc start ./my-bundle
Signal挙動
SIGTERMgraceful shutdown
SIGINT (Ctrl+C)graceful shutdown
SIGHUP設定を再読み込みする
Variable説明
GREENTIC_HOSTbind address
GREENTIC_PORTHTTP port
GREENTIC_LOG_LEVELログの詳細度
GREENTIC_LOG_FORMATログ形式(json/pretty)
GREENTIC_NATS_URL外部 NATS URL
GREENTIC_REDIS_URLsessions 用の Redis URL
Error: Address already in use (os error 48)

別の process が port 8080 を使用しています。停止するか、別の port を使ってください:

Terminal window
gtc start ./my-bundle --port 3000
Error: Failed to connect to NATS

外部 NATS を使っている場合は、実行中でアクセス可能か確認してください。そうでない場合は、組み込み版を有効にします:

Terminal window
gtc start ./my-bundle --nats on
Error: Failed to start cloudflared tunnel

cloudflared をインストールするか、代わりに ngrok を使ってください:

Terminal window
# Install cloudflared
brew install cloudflared
# Or use ngrok
gtc start ./my-bundle --cloudflared off --ngrok on
Error: Setup flow failed for messaging-telegram

回答ファイル内の認証情報を確認し、公開 URL にアクセスできることを確認してください:

Terminal window
# Re-run setup
gtc start ./my-bundle --force-setup --verbose
Dockerfile
FROM rust:1.90 as builder
WORKDIR /app
COPY . .
RUN cargo build --release
FROM debian:bookworm-slim
COPY --from=builder /app/target/release/gtc /usr/local/bin/
COPY my-bundle /app/bundle
WORKDIR /app
EXPOSE 8080
CMD ["gtc", "start", "/app/bundle", "--cloudflared", "off"]
Terminal window
docker build -t my-worker .
docker run -p 8080:8080 my-worker