supervisord golang 实现试用

supervisord 有一个golang 的实现,而且功能很强大,使用和python 版的基本一样
以下是一个简单的试用

环境准备

  • 项目
    简单golang demo
 
go mod github.com/rongfengliang/restapi
go get github.com/gin-gonic/gin
main.go
package main
import "github.com/gin-gonic/gin"
func main() {
    r := gin.Default()
    r.GET("/", func(context *gin.Context) {
        context.String(200, "ok")
    })
    r.Run(":8080")
}

Dockerfile

FROM golang:1.13-alpine AS build-env
WORKDIR /go/src/app
RUN  /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories
ENV  GO111MODULE=on
ENV  GOPROXY=https://goproxy.cn
COPY . .
RUN apk update && apk add git \
    && go build -o rest-api
FROM alpine:latest
WORKDIR /app
RUN  /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
COPY --from=ochinchina/supervisord:latest /usr/local/bin/supervisord /usr/local/bin/supervisord
COPY --from=build-env /go/src/app/rest-api /app/rest-api
COPY supervisor.conf /etc/supervisord.conf
EXPOSE 8080
CMD ["/usr/local/bin/supervisord"]
  • docker-compose 文件
version: "3"
services: 
   api: 
     build: ./
     image: dalongrong/golang-supervisord
     ports: 
     - "8080:8080"
 
 
  • supervisor 配置
    supervisor.conf
 
[program:restapi]
command = /app/rest-api
[inet_http_server]
port = :9001

启动&&效果

  • 构建镜像
docker-compose build
  • 启动
docker-compose up -d
  • 效果

restapi

 

 


管理ui

 

 

说明

supervisord 是一个不错的python 版本替换,轻量,简单,比较适合容器应用,同时也支持依赖管理

参考资料

https://github.com/ochinchina/supervisord
https://github.com/rongfengliang/golang-supervisord-learning

posted on   荣锋亮  阅读(961)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-06-10 circus web console 依赖tornado>3.2 无法访问的bug
2019-06-10 circus 做为批处理的守护进程
2019-06-10 circus 架构
2019-06-10 sphinx doc 文档生成脚手架工具
2019-06-10 circus docker image web 运行异常问题的解决
2019-06-10 circus 进程以及socket 管理工具&&docker运行
2019-06-10 a list of frequently asked questions about Circus

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示