fix no config panic & wingmate.yaml doc

This commit is contained in:
Suyono 2024-09-22 10:51:24 +10:00
parent 3c0816f5f3
commit bcb6435b4a
8 changed files with 110 additions and 5 deletions

View File

@ -28,7 +28,7 @@ func main() {
wingmate.Log().Info().Msgf("starting wingmate version %s", viper.GetString(config.WingmateVersion)) wingmate.Log().Info().Msgf("starting wingmate version %s", viper.GetString(config.WingmateVersion))
if cfg, err = config.Read(); err != nil { if cfg, err = config.Read(); err != nil {
wingmate.Log().Error().Msgf("failed to read config %#v", err) wingmate.Log().Fatal().Err(err).Msg("failed to read config")
} }
initCfg := convert(cfg) initCfg := convert(cfg)

View File

@ -0,0 +1,59 @@
service:
# one:
# command: [ "wmstarter" ]
# environ: [ "DUMMY_PATH=/workspace/wingmate/cmd/experiment/dummy/dummy" ]
spawner:
command: [ "wmspawner" ]
user: "1200"
bgtest:
command:
- "wmstarter"
- "--no-wait"
- "--"
- "wmexec"
- "--setsid"
- "--"
- "wmbg"
- "--name"
- "test-run"
- "--pause"
- "10"
- "--log-path"
- "/var/log/wmbg.log"
- "--pid-file"
- "/var/run/wmbg.pid"
pidfile: "/var/run/wmbg.pid"
cron:
cron1:
command:
- "wmoneshot"
- "--"
- "sleep"
- "5"
schedule: "*/5 * * * *"
environ:
- "WINGMATE_LOG=/var/log/cron1.log"
- "WINGMATE_LOG_MESSAGE=cron executed in minute 5,10,15,20,25,30,35,40,45,50,55"
cron2:
command:
- "wmoneshot"
- "--"
- "sleep"
- "5"
schedule: "17,42 */2 * * *"
environ:
- "WINGMATE_LOG=/var/log/cron2.log"
- "WINGMATE_LOG_MESSAGE=cron scheduled using 17,42 */2 * * *"
cron3:
command:
- "wmoneshot"
- "--"
- "sleep"
- "5"
schedule: "7,19,23,47 22 * * *"
environ:
- "WINGMATE_LOG=/var/log/cron3.log"
- "WINGMATE_LOG_MESSAGE=cron scheduled using 7,19,23,47 22 * * *"

View File

@ -1,4 +1,4 @@
FROM golang:1.22-bookworm as builder FROM golang:1.22-bookworm AS builder
ADD . /root/wingmate ADD . /root/wingmate
WORKDIR /root/wingmate/ WORKDIR /root/wingmate/
@ -13,8 +13,8 @@ RUN ln -sf /usr/share/zoneinfo/Australia/Sydney /etc/localtime && \
apt update && apt install -y procps && \ apt update && apt install -y procps && \
useradd -m -s /bin/bash user1 useradd -m -s /bin/bash user1
COPY --from=builder /usr/local/bin/wingmate/ /usr/local/bin/ COPY --from=builder /usr/local/bin/wingmate/ /usr/local/bin/
ADD --chmod=755 docker/bookworm-newconfig/entry.sh /usr/local/bin/entry.sh ADD --chmod=755 docker/bookworm/entry.sh /usr/local/bin/entry.sh
ADD --chmod=755 docker/bookworm-newconfig/etc /etc ADD --chmod=755 docker/bookworm/etc /etc
ENTRYPOINT [ "/usr/local/bin/entry.sh" ] ENTRYPOINT [ "/usr/local/bin/entry.sh" ]
CMD [ "/usr/local/bin/wingmate" ] CMD [ "/usr/local/bin/wingmate" ]

View File

@ -0,0 +1,8 @@
FROM suyono/wingmate:test AS source
FROM alpine:3.20
COPY --from=source /usr/local/bin/ /usr/local/bin/
ENTRYPOINT [ "/usr/local/bin/entry.sh" ]
CMD [ "/usr/local/bin/wingmate" ]

View File

@ -0,0 +1,8 @@
FROM suyono/wingmate:test AS source
FROM debian:bookworm
COPY --from=source /usr/local/bin/ /usr/local/bin/
ENTRYPOINT [ "/usr/local/bin/entry.sh" ]
CMD [ "/usr/local/bin/wingmate" ]

View File

@ -46,6 +46,10 @@ func (w *wrapper) Error() logger.Content {
return (*eventWrapper)(w.log.Error().Time(timeTag, time.Now())) return (*eventWrapper)(w.log.Error().Time(timeTag, time.Now()))
} }
func (w *wrapper) Fatal() logger.Content {
return (*eventWrapper)(w.log.Fatal().Time(timeTag, time.Now()))
}
type eventWrapper zerolog.Event type eventWrapper zerolog.Event
func (w *eventWrapper) Msg(msg string) { func (w *eventWrapper) Msg(msg string) {
@ -60,3 +64,8 @@ func (w *eventWrapper) Str(key, value string) logger.Content {
rv := (*zerolog.Event)(w).Str(key, value) rv := (*zerolog.Event)(w).Str(key, value)
return (*eventWrapper)(rv) return (*eventWrapper)(rv)
} }
func (w *eventWrapper) Err(err error) logger.Content {
rv := (*zerolog.Event)(w).Err(err)
return (*eventWrapper)(rv)
}

View File

@ -4,12 +4,14 @@ type Content interface {
Msg(string) Msg(string)
Msgf(string, ...any) Msgf(string, ...any)
Str(string, string) Content Str(string, string) Content
Err(error) Content
} }
type Level interface { type Level interface {
Info() Content Info() Content
Warn() Content Warn() Content
Error() Content Error() Content
Fatal() Content
} }
type Log interface { type Log interface {

View File

@ -154,11 +154,30 @@ configuration depends on the [wmpidproxy](README.md#wingmate-pid-proxy-binary).
`cron` is a top-level element that hosts the definition of crones to run by `wingmate` on the specified schedule. `cron` is a top-level element that hosts the definition of crones to run by `wingmate` on the specified schedule.
Cron shares almost all configuration elements with Service, except `schedule` and `pidfile`. For the following Cron shares almost all configuration elements with Service, except `schedule` and `pidfile`. For the following
elements, please refer to the Service section elements, please refer to the [Service](#service) section
- [Command](#command) - [Command](#command)
- [Environ](#environ) - [Environ](#environ)
- [Working Directory](#working-directory) - [Working Directory](#working-directory)
- [setsid](#setsid) - [setsid](#setsid)
- [User and Group](#user-and-group) - [User and Group](#user-and-group)
`pidfile` is an invalid config parameter for cron because `wingmate` cannot start cron in background mode. This
limitation is intentionally built into `wingmate` because it doesn't make any sense to run a periodic cron process
in background.
### Schedule ### Schedule
The schedule configuration field uses a format similar to the one described in the [README.md](README.md).
```shell
┌───────────── minute (059)
│ ┌───────────── hour (023)
│ │ ┌───────────── day of the month (131)
│ │ │ ┌───────────── month (112)
│ │ │ │ ┌───────────── day of the week (06) (Sunday to Saturday)
│ │ │ │ │
│ │ │ │ │
│ │ │ │ │
* * * * *
```