All Projects → Code-Hex → golet

Code-Hex / golet

Licence: MIT license
*.go file as a mini supervisor

Programming Languages

go
31211 projects - #10 most used programming language
perl
6916 projects

Projects that are alternatives of or similar to golet

Immortal
⭕ A *nix cross-platform (OS agnostic) supervisor
Stars: ✭ 701 (+1068.33%)
Mutual labels:  supervisor
Earl
Service Objects for Crystal (Agents, Artists, Supervisors, Pools, ...)
Stars: ✭ 89 (+48.33%)
Mutual labels:  supervisor
Reconfigure
Config-file-to-Python mapping library (ORM).
Stars: ✭ 136 (+126.67%)
Mutual labels:  supervisor
Horde
Horde is a distributed Supervisor and Registry backed by DeltaCrdt
Stars: ✭ 834 (+1290%)
Mutual labels:  supervisor
X Proxies
Usable ip proxies, crawling from some proxy websites.
Stars: ✭ 53 (-11.67%)
Mutual labels:  supervisor
Multivisor
Centralized supervisor WebUI and CLI
Stars: ✭ 104 (+73.33%)
Mutual labels:  supervisor
Littleboss
littleboss: supervisor construction kit
Stars: ✭ 624 (+940%)
Mutual labels:  supervisor
Supervisor
PHP library for managing Supervisor through XML-RPC API
Stars: ✭ 163 (+171.67%)
Mutual labels:  supervisor
Docker Laravel Queue Worker
A docker image for working with queues being monitored by supervisor as recommended by laravel.
Stars: ✭ 60 (+0%)
Mutual labels:  supervisor
Ssr Manyuser glzjin shell
sspanel v3 魔改版 后端一键安装配置管理脚本
Stars: ✭ 133 (+121.67%)
Mutual labels:  supervisor
Supervisord
Async first supervisord HTTP API Client for PHP 7
Stars: ✭ 14 (-76.67%)
Mutual labels:  supervisor
Svsh
Process supervision shell for daemontools, perp, s6 and runit
Stars: ✭ 46 (-23.33%)
Mutual labels:  supervisor
Graceful
graceful reload golang http server, zero downtime, compatible with systemd, supervisor
Stars: ✭ 129 (+115%)
Mutual labels:  supervisor
React Native Full Example
第一个完整的react-native项目。包括服务端和移动端两部分。服务端使用express+bootstrap进行搭建,主要功能有登录、退出、模块选择、查看、修改、删除、分页等后台管理的基本功能;移动端主要用到组件View、Text、Image、ScrollView、ListView等常用的组件,也使用了第三方的地图服务(高德地图),作为初学者。是一个很好的学习案例。
Stars: ✭ 809 (+1248.33%)
Mutual labels:  supervisor
Homebridge Config Ui X
The Homebridge UI. Monitor, configure and backup Homebridge from a browser.
Stars: ✭ 1,967 (+3178.33%)
Mutual labels:  supervisor
Akka Essentials
Java/Scala Examples from the book - Akka Essentials
Stars: ✭ 700 (+1066.67%)
Mutual labels:  supervisor
Supervisor Event Listener
Supervisor事件通知, 支持邮件, Slack, WebHook
Stars: ✭ 95 (+58.33%)
Mutual labels:  supervisor
Cedardeploy
cedardeploy:发布系统基于python,flask,mysql,git,ssh-key,supervisor.支持多类型,上线,回滚,监控,报警
Stars: ✭ 248 (+313.33%)
Mutual labels:  supervisor
Flask Easy Template
A template web app with Flask. Features: latest bootstrap, user registry, login, forgot password. Secured admin panel, pagination, config files for Nginx and Supervisor and much more.
Stars: ✭ 154 (+156.67%)
Mutual labels:  supervisor
Monexec
Light supervisor on Go (with optional Consul autoregistration)
Stars: ✭ 132 (+120%)
Mutual labels:  supervisor

Golet

Build Status GoDoc Go Report Card

Golet can manage many services with goroutine from one golang program. It's like a supervisor.
It supports go version 1.7 or higher. Golet is based on the idea of Proclet.
Proclet is a great module in Perl.

Synopsis

package main

import (
    "context"
    "fmt"
    "net/http"
    "strings"
    "syscall"
    "time"

    "github.com/Code-Hex/golet"
)

func main() {
    p := golet.New(context.Background())
    p.EnableColor()
    // Execution interval
    p.SetInterval(time.Second * 1)

    p.Env(map[string]string{
        "NAME":  "codehex",
        "VALUE": "121",
    })

    p.Add(
        golet.Service{
            Exec: "plackup --port $PORT",
            Tag:  "plack",
        },
        golet.Service{
            Exec:   "echo 'This is cron!!'",
            Every:  "30 * * * * *",
            Worker: 2,
            Tag:    "cron",
        },
    )

    p.Add(golet.Service{
        Code: func(ctx context.Context) error {
            c := ctx.(*golet.Context)
            c.Println("Hello golet!! Port:", c.Port())
            mux := http.NewServeMux()
            mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
                fmt.Fprintf(w, "Hello, World")
                buf := strings.NewReader("This is log string\nNew line1\nNew line2\nNew line3\n")
                c.Copy(buf)
            })
            go http.ListenAndServe(c.ServePort(), mux)
            for {
                select {
                // You can notify signal received.
                case <-c.Recv():
                    signal, err := c.Signal()
                    if err != nil {
                        c.Println(err.Error())
                        return err
                    }
                    switch signal {
                    case syscall.SIGTERM, syscall.SIGHUP, syscall.SIGINT:
                        c.Println(signal.String())
                        return nil
                    }
                case <-ctx.Done():
                    return nil
                }
            }
        },
        Worker: 3,
    })

    p.Run()
}

See more example.

Logging

In case to run code of synopsis. I send INT signal to golet. Logging

Usage

Basic

Make sure to generate a struct from the New(context.Context) function.

p := golet.New(context.Background())

Next, We can add the service using the Service struct.
Add(services ...Service) error method is also possible to pass multiple Service struct arguments.

p.Add(
    golet.Service{
        // Replace $PORT and automatically assigned port number.
        Exec: "plackup --port $PORT",
        Tag:  "plack", // Keyword for log.
    },
    golet.Service{
        Exec:   "echo 'This is cron!!'",
        // Crontab like format. 
        Every:  "30 * * * * *", // See https://godoc.org/github.com/robfig/cron#hdr-CRON_Expression_Format
        Worker: 2,              // Number of goroutine. The maximum number of workers is 100.
        Tag:    "cron",
    },
)

Finally, You can run many services. use Run() error

p.Run()

Option

The default option is like this.

interval:   0
color:      false
logger:     colorable.NewColorableStderr()
logWorker:  true
execNotice: true
cancelSignal: -1

By using the go-colorable, colored output is also compatible with windows.
You can change these options by using the following method.

// SetInterval can specify the interval at which the command is executed.
func (c *config) SetInterval(t time.Duration) { c.interval = t }

// EnableColor can output colored log.
func (c *config) EnableColor() { c.color = true }

// SetLogger can specify the *os.File
// for example in https://github.com/lestrrat/go-file-rotatelogs
/*
      logf, _ := rotatelogs.New(
          "/path/to/access_log.%Y%m%d%H%M",
          rotatelogs.WithLinkName("/path/to/access_log"),
          rotatelogs.WithMaxAge(24 * time.Hour),
          rotatelogs.WithRotationTime(time.Hour),
      )

      golet.New(context.Background()).SetLogger(logf)
*/
func (c *config) SetLogger(f io.Writer) { c.logger = f }

// DisableLogger is prevent to output log
func (c *config) DisableLogger() { c.logWorker = false }

// DisableExecNotice is disable execute notifications
func (c *config) DisableExecNotice() { c.execNotice = false }

// SetCtxCancelSignal can specify the signal to send processes when context cancel.
// If you do not set, golet will not send the signal when context cancel.
func (c *config) SetCtxCancelSignal(signal syscall.Signal) { c.cancelSignal = signal }

Environment variables

You can use temporary environment variables in golet program.

p.Env(map[string]string{
    "NAME":  "codehex",
    "VALUE": "121",
})

and, If you execute service as command, you can get also PORT env variable.

golet.Context

See, https://godoc.org/github.com/Code-Hex/golet#Context

golet.Context can be to context.Context, io.Writer also io.Closer.

So, you can try to write strange code like this.

golet.Service{
    Code: func(ctx context.Context) error {
        // die program
        c := ctx.(*golet.Context)
        fmt.Fprintf(c, "Hello, World!!\n")
        c.Printf("Hello, Port: %d\n", c.Port())
        time.Sleep(time.Second * 1)
        select {
        case <-c.Recv():
            signal, err := c.Signal()
            if err != nil {
                c.Println(err.Error())
                return err
            }
            switch signal {
            case syscall.SIGTERM, syscall.SIGHUP:
                c.Println(signal.String())
                return fmt.Errorf("die message")
            case syscall.SIGINT:
                return nil
            }
            return nil
        }
    },
}

Installation

go get -u github.com/Code-Hex/golet

Contribution

  1. Fork https://github.com/Code-Hex/golet/fork
  2. Commit your changes
  3. Create a new Pull Request

I'm waiting for a lot of PR.

Future

  • Create like foreman command
  • Support better windows
  • Write a test for signals for some distribution

Author

codehex

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].