service
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseService Management
服务管理
Check status, update properties, and advanced service creation.
查看状态、更新属性以及高级服务创建。
When to Use
使用场景
- User asks about service status, health, or deployments
- User asks "is my service deployed?"
- User wants to rename a service or change service icon
- User wants to link a different service
- User wants to deploy a Docker image as a new service (advanced)
Note: For creating services with local code (the common case), prefer the skill which handles project setup, scaffolding, and service creation together.
newFor GitHub repo sources: Use skill to create empty service, then skill to configure source.repo via staged changes API.
newenvironment- 用户询问服务状态、健康状况或部署情况
- 用户提问“我的服务是否已部署?”
- 用户想要重命名服务或更改服务图标
- 用户想要链接其他服务
- 用户想要将Docker镜像部署为新服务(高级操作)
注意: 对于使用本地代码创建服务的常见场景,请优先使用 Skill,它会一并处理项目设置、脚手架搭建和服务创建。
new对于GitHub仓库源: 使用 Skill创建空服务,然后使用 Skill通过分阶段变更API配置source.repo。
newenvironmentCreate Service
创建服务
Create a new service via GraphQL API. There is no CLI command for this.
通过GraphQL API创建新服务。目前没有对应的CLI命令。
Get Context
获取上下文
bash
railway status --jsonExtract:
- - for creating the service
project.id - - for staging the instance config
environment.id
bash
railway status --json提取:
- - 用于创建服务
project.id - - 用于暂存实例配置
environment.id
Create Service Mutation
创建服务的Mutation
graphql
mutation serviceCreate($input: ServiceCreateInput!) {
serviceCreate(input: $input) {
id
name
}
}graphql
mutation serviceCreate($input: ServiceCreateInput!) {
serviceCreate(input: $input) {
id
name
}
}ServiceCreateInput Fields
ServiceCreateInput字段
| Field | Type | Description |
|---|---|---|
| String! | Project ID (required) |
| String | Service name (auto-generated if omitted) |
| String | Docker image (e.g., |
| String | GitHub repo (e.g., |
| String | Git branch for repo source |
| String | If set and is a fork, only creates in that env |
| 字段 | 类型 | 描述 |
|---|---|---|
| String! | 项目ID(必填) |
| String | 服务名称(如果省略则自动生成) |
| String | Docker镜像(例如: |
| String | GitHub仓库(例如: |
| String | 仓库源的Git分支 |
| String | 如果设置且为分支环境,仅在该环境中创建服务 |
Example: Create empty service
示例:创建空服务
bash
bash <<'SCRIPT'
scripts/railway-api.sh \
'mutation createService($input: ServiceCreateInput!) {
serviceCreate(input: $input) { id name }
}' \
'{"input": {"projectId": "PROJECT_ID"}}'
SCRIPTbash
bash <<'SCRIPT'
scripts/railway-api.sh \
'mutation createService($input: ServiceCreateInput!) {
serviceCreate(input: $input) { id name }
}' \
'{"input": {"projectId": "PROJECT_ID"}}'
SCRIPTExample: Create service with image
示例:使用镜像创建服务
bash
bash <<'SCRIPT'
scripts/railway-api.sh \
'mutation createService($input: ServiceCreateInput!) {
serviceCreate(input: $input) { id name }
}' \
'{"input": {"projectId": "PROJECT_ID", "name": "my-service", "source": {"image": "nginx:latest"}}}'
SCRIPTbash
bash <<'SCRIPT'
scripts/railway-api.sh \
'mutation createService($input: ServiceCreateInput!) {
serviceCreate(input: $input) { id name }
}' \
'{"input": {"projectId": "PROJECT_ID", "name": "my-service", "source": {"image": "nginx:latest"}}}'
SCRIPTConnecting a GitHub Repo
连接GitHub仓库
Do NOT use serviceCreate with source.repo - use staged changes API instead.
Flow:
- Create empty service:
serviceCreate(input: {projectId: "...", name: "my-service"}) - Use skill to configure source via staged changes API
environment - Apply to trigger deployment
请勿使用serviceCreate搭配source.repo - 请改用分阶段变更API。
流程:
- 创建空服务:
serviceCreate(input: {projectId: "...", name: "my-service"}) - 使用Skill通过分阶段变更API配置源
environment - 应用变更以触发部署
After Creating: Configure Instance
创建后:配置实例
Use skill to configure the service instance:
environmentjson
{
"services": {
"<serviceId>": {
"isCreated": true,
"source": { "image": "nginx:latest" },
"variables": {
"PORT": { "value": "8080" }
}
}
}
}Critical: Always include for new service instances.
isCreated: trueThen use skill to apply and deploy.
environmentFor variable references, see reference/variables.md.
使用 Skill配置服务实例:
environmentjson
{
"services": {
"<serviceId>": {
"isCreated": true,
"source": { "image": "nginx:latest" },
"variables": {
"PORT": { "value": "8080" }
}
}
}
}关键提示: 对于新服务实例,务必包含。
isCreated: true然后使用 Skill应用变更并部署。
environment有关变量参考,请查看reference/variables.md。
Check Service Status
查看服务状态
bash
railway service status --jsonReturns current deployment status for the linked service.
bash
railway service status --json返回当前链接服务的部署状态。
Deployment History
部署历史
bash
railway deployment list --json --limit 5bash
railway deployment list --json --limit 5Present Status
当前状态展示
Show:
- Service: name and current status
- Latest Deployment: status (SUCCESS, FAILED, DEPLOYING, CRASHED, etc.)
- Deployed At: when the current deployment went live
- Recent Deployments: last 3-5 with status and timestamps
展示内容:
- 服务:名称和当前状态
- 最新部署:状态(SUCCESS、FAILED、DEPLOYING、CRASHED等)
- 部署时间:当前部署上线的时间
- 近期部署:最近3-5次部署的状态和时间戳
Deployment Statuses
部署状态说明
| Status | Meaning |
|---|---|
| SUCCESS | Deployed and running |
| FAILED | Build or deploy failed |
| DEPLOYING | Currently deploying |
| BUILDING | Build in progress |
| CRASHED | Runtime crash |
| REMOVED | Deployment removed |
| 状态 | 含义 |
|---|---|
| SUCCESS | 已部署且运行中 |
| FAILED | 构建或部署失败 |
| DEPLOYING | 正在部署中 |
| BUILDING | 构建进行中 |
| CRASHED | 运行时崩溃 |
| REMOVED | 部署已移除 |
Update Service
更新服务
Update service name or icon via GraphQL API.
通过GraphQL API更新服务名称或图标。
Get Service ID
获取服务ID
bash
railway status --jsonExtract from the response.
service.idbash
railway status --json从响应中提取。
service.idUpdate Name
更新名称
bash
bash <<'SCRIPT'
scripts/railway-api.sh \
'mutation updateService($id: String!, $input: ServiceUpdateInput!) {
serviceUpdate(id: $id, input: $input) { id name }
}' \
'{"id": "SERVICE_ID", "input": {"name": "new-name"}}'
SCRIPTbash
bash <<'SCRIPT'
scripts/railway-api.sh \
'mutation updateService($id: String!, $input: ServiceUpdateInput!) {
serviceUpdate(id: $id, input: $input) { id name }
}' \
'{"id": "SERVICE_ID", "input": {"name": "new-name"}}'
SCRIPTUpdate Icon
更新图标
Icons can be image URLs or animated GIFs.
| Type | Example |
|---|---|
| Image URL | |
| Animated GIF | |
| Devicons | |
Railway Devicons: Query for common developer icons (e.g., , , , ). Browse all at https://devicons.railway.app
https://devicons.railway.app/{query}githubpostgresredisnodejsbash
bash <<'SCRIPT'
scripts/railway-api.sh \
'mutation updateService($id: String!, $input: ServiceUpdateInput!) {
serviceUpdate(id: $id, input: $input) { id icon }
}' \
'{"id": "SERVICE_ID", "input": {"icon": "https://devicons.railway.app/github"}}'
SCRIPT图标可以是图片URL或动画GIF。
| 类型 | 示例 |
|---|---|
| 图片URL | |
| 动画GIF | |
| Devicons | |
Railway Devicons: 查询获取常见开发者图标(例如:、、、)。可访问https://devicons.railway.app浏览所有图标。
https://devicons.railway.app/{query}githubpostgresredisnodejsbash
bash <<'SCRIPT'
scripts/railway-api.sh \
'mutation updateService($id: String!, $input: ServiceUpdateInput!) {
serviceUpdate(id: $id, input: $input) { id icon }
}' \
'{"id": "SERVICE_ID", "input": {"icon": "https://devicons.railway.app/github"}}'
SCRIPTServiceUpdateInput Fields
ServiceUpdateInput字段
| Field | Type | Description |
|---|---|---|
| String | Service name |
| String | Emoji or image URL (including animated GIFs) |
| 字段 | 类型 | 描述 |
|---|---|---|
| String | 服务名称 |
| String | 表情符号或图片URL(包括动画GIF) |
Link Service
链接服务
Switch the linked service for the current directory:
bash
railway service linkOr specify directly:
bash
railway service link <service-name>切换当前目录的链接服务:
bash
railway service link或直接指定:
bash
railway service link <service-name>Composability
组合使用
- Create service with local code: Use skill (handles scaffolding + creation)
new - Configure service: Use skill (variables, commands, image, etc.)
environment - Delete service: Use skill with
environmentisDeleted: true - Apply changes: Use skill
environment - View logs: Use skill
deployment - Deploy local code: Use skill
deploy
- 使用本地代码创建服务:使用Skill(处理脚手架搭建+创建)
new - 配置服务:使用Skill(变量、命令、镜像等)
environment - 删除服务:使用Skill并设置
environmentisDeleted: true - 应用变更:使用Skill
environment - 查看日志:使用Skill
deployment - 部署本地代码:使用Skill
deploy
Error Handling
错误处理
No Service Linked
未链接服务
No service linked. Run `railway service link` to link a service.No service linked. Run `railway service link` to link a service.No Deployments
无部署记录
Service exists but has no deployments yet. Deploy with `railway up`.Service exists but has no deployments yet. Deploy with `railway up`.Service Not Found
服务未找到
Service "foo" not found. Check available services with `railway status`.Service "foo" not found. Check available services with `railway status`.Project Not Found
项目未找到
User may not be in a linked project. Check .
railway status用户可能未处于链接的项目中。请查看。
railway statusPermission Denied
权限不足
User needs at least DEVELOPER role to create services.
用户至少需要DEVELOPER角色才能创建服务。
Invalid Image
无效镜像
Docker image must be accessible (public or with registry credentials).
Docker镜像必须可访问(公开或已配置仓库凭证)。