mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-24 06:28:13 +01:00
Use zoneinfo from Go (#202)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -4,7 +4,6 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- '**'
|
- '**'
|
||||||
- 'v*'
|
|
||||||
tags:
|
tags:
|
||||||
- 'v*'
|
- 'v*'
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
@@ -23,7 +22,6 @@ on:
|
|||||||
- 'mkdocs.yml'
|
- 'mkdocs.yml'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
go:
|
go:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ LABEL maintainer="CrazyMax"
|
|||||||
RUN apk --update --no-cache add \
|
RUN apk --update --no-cache add \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
libressl \
|
libressl \
|
||||||
tzdata \
|
|
||||||
&& rm -rf /tmp/* /var/cache/apk/*
|
&& rm -rf /tmp/* /var/cache/apk/*
|
||||||
|
|
||||||
COPY --from=builder /app/diun /usr/local/bin/diun
|
COPY --from=builder /app/diun /usr/local/bin/diun
|
||||||
|
|||||||
11
cmd/main.go
11
cmd/main.go
@@ -7,7 +7,6 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/alecthomas/kong"
|
"github.com/alecthomas/kong"
|
||||||
"github.com/crazy-max/diun/v4/internal/app"
|
"github.com/crazy-max/diun/v4/internal/app"
|
||||||
@@ -54,14 +53,8 @@ func main() {
|
|||||||
Summary: true,
|
Summary: true,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// Load timezone location
|
|
||||||
location, err := time.LoadLocation(cli.Timezone)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal().Err(err).Msgf("Cannot load timezone %s", cli.Timezone)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init
|
// Init
|
||||||
logging.Configure(&cli, location)
|
logging.Configure(&cli)
|
||||||
log.Info().Str("version", version).Msgf("Starting %s", meta.Name)
|
log.Info().Str("version", version).Msgf("Starting %s", meta.Name)
|
||||||
|
|
||||||
// Handle os signals
|
// Handle os signals
|
||||||
@@ -82,7 +75,7 @@ func main() {
|
|||||||
log.Debug().Msg(cfg.String())
|
log.Debug().Msg(cfg.String())
|
||||||
|
|
||||||
// Init
|
// Init
|
||||||
if diun, err = app.New(meta, cli, cfg, location); err != nil {
|
if diun, err = app.New(meta, cli, cfg); err != nil {
|
||||||
log.Fatal().Err(err).Msgf("Cannot initialize %s", meta.Name)
|
log.Fatal().Err(err).Msgf("Cannot initialize %s", meta.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
docs/faq.md
12
docs/faq.md
@@ -1,5 +1,17 @@
|
|||||||
# FAQ
|
# FAQ
|
||||||
|
|
||||||
|
## Timezone
|
||||||
|
|
||||||
|
By default, all interpretation and scheduling is done with your local timezone (`TZ` environment variable).
|
||||||
|
|
||||||
|
Cron schedule may also override the timezone to be interpreted in by providing an additional space-separated field
|
||||||
|
at the beginning of the cron spec, of the form `CRON_TZ=<timezone>`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
watch:
|
||||||
|
schedule: "CRON_TZ=Asia/Tokyo 0 */6 * * *"
|
||||||
|
```
|
||||||
|
|
||||||
## Test notifications
|
## Test notifications
|
||||||
|
|
||||||
Through the [command line](usage/cli.md) with:
|
Through the [command line](usage/cli.md) with:
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ and [File](providers/file.md) providers available
|
|||||||
* Get notified through Gotify, Mail, Slack, Telegram and [more](config/index.md#reference)
|
* Get notified through Gotify, Mail, Slack, Telegram and [more](config/index.md#reference)
|
||||||
* [Healthchecks support](config/watch.md#healthchecks) to monitor Diun watcher
|
* [Healthchecks support](config/watch.md#healthchecks) to monitor Diun watcher
|
||||||
* Enhanced logging
|
* Enhanced logging
|
||||||
* Timezone can be changed
|
|
||||||
* Official [Docker image available](install/docker.md)
|
* Official [Docker image available](install/docker.md)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ User=diun
|
|||||||
Group=diun
|
Group=diun
|
||||||
ExecStart=/usr/local/bin/diun --config /etc/diun/diun.yml --log-level info
|
ExecStart=/usr/local/bin/diun --config /etc/diun/diun.yml --log-level info
|
||||||
Restart=always
|
Restart=always
|
||||||
|
#Environment=TZ=Europe/Paris
|
||||||
Environment=DIUN_DB_PATH=/var/lib/diun/diun.db
|
Environment=DIUN_DB_PATH=/var/lib/diun/diun.db
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ Flags:
|
|||||||
--help Show context-sensitive help.
|
--help Show context-sensitive help.
|
||||||
--version
|
--version
|
||||||
--config=STRING Diun configuration file ($CONFIG).
|
--config=STRING Diun configuration file ($CONFIG).
|
||||||
--timezone="UTC" Timezone assigned to Diun ($TZ).
|
|
||||||
--log-level="info" Set log level ($LOG_LEVEL).
|
--log-level="info" Set log level ($LOG_LEVEL).
|
||||||
--log-json Enable JSON logging output ($LOG_JSON).
|
--log-json Enable JSON logging output ($LOG_JSON).
|
||||||
--log-caller Add file:line of the caller to log output ($LOG_CALLER).
|
--log-caller Add file:line of the caller to log output ($LOG_CALLER).
|
||||||
@@ -32,7 +31,6 @@ Following environment variables can be used in place:
|
|||||||
| Name | Default | Description |
|
| Name | Default | Description |
|
||||||
|--------------------|---------------|---------------|
|
|--------------------|---------------|---------------|
|
||||||
| `CONFIG` | | Diun configuration file |
|
| `CONFIG` | | Diun configuration file |
|
||||||
| `TZ` | `UTC` | Timezone assigned |
|
|
||||||
| `LOG_LEVEL` | `info` | Log level output |
|
| `LOG_LEVEL` | `info` | Log level output |
|
||||||
| `LOG_JSON` | `false` | Enable JSON logging output |
|
| `LOG_JSON` | `false` | Enable JSON logging output |
|
||||||
| `LOG_CALLER` | `false` | Enable to add `file:line` of the caller |
|
| `LOG_CALLER` | `false` | Enable to add `file:line` of the caller |
|
||||||
|
|||||||
@@ -39,14 +39,14 @@ type Diun struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New creates new diun instance
|
// New creates new diun instance
|
||||||
func New(meta model.Meta, cli model.Cli, cfg *config.Config, location *time.Location) (*Diun, error) {
|
func New(meta model.Meta, cli model.Cli, cfg *config.Config) (*Diun, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
diun := &Diun{
|
diun := &Diun{
|
||||||
meta: meta,
|
meta: meta,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
cron: cron.New(cron.WithLocation(location), cron.WithParser(cron.NewParser(
|
cron: cron.New(cron.WithParser(cron.NewParser(
|
||||||
cron.SecondOptional|cron.Minute|cron.Hour|cron.Dom|cron.Month|cron.Dow|cron.Descriptor),
|
cron.SecondOptional | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,14 +13,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Configure configures logger
|
// Configure configures logger
|
||||||
func Configure(cli *model.Cli, location *time.Location) {
|
func Configure(cli *model.Cli) {
|
||||||
var err error
|
var err error
|
||||||
var w io.Writer
|
var w io.Writer
|
||||||
|
|
||||||
zerolog.TimestampFunc = func() time.Time {
|
|
||||||
return time.Now().In(location)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !cli.LogJSON {
|
if !cli.LogJSON {
|
||||||
w = zerolog.ConsoleWriter{
|
w = zerolog.ConsoleWriter{
|
||||||
Out: os.Stdout,
|
Out: os.Stdout,
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import "github.com/alecthomas/kong"
|
|||||||
type Cli struct {
|
type Cli struct {
|
||||||
Version kong.VersionFlag
|
Version kong.VersionFlag
|
||||||
Cfgfile string `kong:"name='config',env='CONFIG',help='Diun configuration file.'"`
|
Cfgfile string `kong:"name='config',env='CONFIG',help='Diun configuration file.'"`
|
||||||
Timezone string `kong:"name='timezone',env='TZ',default='UTC',help='Timezone assigned to Diun.'"`
|
|
||||||
LogLevel string `kong:"name='log-level',env='LOG_LEVEL',default='info',help='Set log level.'"`
|
LogLevel string `kong:"name='log-level',env='LOG_LEVEL',default='info',help='Set log level.'"`
|
||||||
LogJSON bool `kong:"name='log-json',env='LOG_JSON',default='false',help='Enable JSON logging output.'"`
|
LogJSON bool `kong:"name='log-json',env='LOG_JSON',default='false',help='Enable JSON logging output.'"`
|
||||||
LogCaller bool `kong:"name='log-caller',env='LOG_CALLER',default='false',help='Add file:line of the caller to log output.'"`
|
LogCaller bool `kong:"name='log-caller',env='LOG_CALLER',default='false',help='Add file:line of the caller to log output.'"`
|
||||||
|
|||||||
Reference in New Issue
Block a user