Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
465b5abc64 | ||
|
d0b8c75a9e | ||
|
f8a8344049 | ||
|
bad1cf3c23 | ||
|
1a84bb4286 |
@ -1,32 +0,0 @@
|
||||
image: golang:1.10.3
|
||||
|
||||
variables:
|
||||
REPO_NAME: novit.nc/direktil/inits
|
||||
|
||||
before_script:
|
||||
- mkdir -p $GOPATH/src/$(dirname $REPO_NAME)
|
||||
- ln -svf $CI_PROJECT_DIR $GOPATH/src/$REPO_NAME
|
||||
- cd $GOPATH/src/$REPO_NAME
|
||||
|
||||
stages:
|
||||
- test
|
||||
- build
|
||||
|
||||
format:
|
||||
stage: test
|
||||
script:
|
||||
- go fmt ./...
|
||||
- go vet ./...
|
||||
- go test -race ./...
|
||||
|
||||
compile:
|
||||
stage: build
|
||||
script:
|
||||
- go build ./cmd/dkl-apply-config
|
||||
- go build ./cmd/dkl-system-init
|
||||
- CGO_ENABLED=0 go build ./cmd/dkl-initrd-init
|
||||
artifacts:
|
||||
paths:
|
||||
- dkl-apply-config
|
||||
- dkl-system-init
|
||||
- dkl-initrd-init
|
@ -5,15 +5,17 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"novit.nc/direktil/inits/pkg/cmd/applyconfig"
|
||||
cmddynlay "novit.nc/direktil/inits/pkg/cmd/dynlay"
|
||||
cmdinit "novit.nc/direktil/inits/pkg/cmd/init"
|
||||
"novit.tech/direktil/inits/pkg/cmd/applyconfig"
|
||||
cmddynlay "novit.tech/direktil/inits/pkg/cmd/dynlay"
|
||||
cmdinit "novit.tech/direktil/inits/pkg/cmd/init"
|
||||
cmdlogger "novit.tech/direktil/inits/pkg/cmd/logger"
|
||||
)
|
||||
|
||||
func main() {
|
||||
root := &cobra.Command{}
|
||||
|
||||
root.AddCommand(cmdinit.Command())
|
||||
root.AddCommand(cmdlogger.Command())
|
||||
root.AddCommand(cmddynlay.Command())
|
||||
root.AddCommand(applyconfig.Command())
|
||||
|
||||
|
23
go.mod
23
go.mod
@ -1,22 +1,27 @@
|
||||
module novit.nc/direktil/inits
|
||||
module novit.tech/direktil/inits
|
||||
|
||||
go 1.21
|
||||
|
||||
require (
|
||||
github.com/antage/mntent v0.0.0-20141129103236-834970000c6c
|
||||
github.com/fsnotify/fsnotify v1.6.0
|
||||
github.com/fsnotify/fsnotify v1.7.0
|
||||
github.com/go-ping/ping v1.1.0
|
||||
github.com/spf13/cobra v1.6.1
|
||||
novit.nc/direktil/pkg v0.0.0-20220221171542-fd3ce3a1491b
|
||||
github.com/rs/zerolog v1.31.0
|
||||
github.com/spf13/cobra v1.8.0
|
||||
novit.tech/direktil/pkg v0.0.0-20240120131645-39b9b401ba38
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/google/uuid v1.5.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/ulikunitz/xz v0.5.10 // indirect
|
||||
golang.org/x/net v0.4.0 // indirect
|
||||
golang.org/x/sync v0.1.0 // indirect
|
||||
golang.org/x/sys v0.3.0 // indirect
|
||||
github.com/ulikunitz/xz v0.5.11 // indirect
|
||||
golang.org/x/net v0.20.0 // indirect
|
||||
golang.org/x/sync v0.6.0 // indirect
|
||||
golang.org/x/sys v0.16.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
|
85
go.sum
85
go.sum
@ -1,14 +1,16 @@
|
||||
github.com/antage/mntent v0.0.0-20141129103236-834970000c6c h1:6g5LfUYqDR1rEL54hKdK7edwAp2R4baYmtDpJgm6+5Q=
|
||||
github.com/antage/mntent v0.0.0-20141129103236-834970000c6c/go.mod h1:AsQhRqephGS4znB7Z793C63GgcW2I6xUsInepL9EOdE=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/cavaliergopher/cpio v1.0.1/go.mod h1:pBdaqQjnvXxdS/6CvNDwIANIFSP0xRKI16PX4xejRQc=
|
||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
github.com/go-ping/ping v1.1.0 h1:3MCGhVX4fyEUuhsfwPrsEdQw6xspHkv5zHsiSoDFZYw=
|
||||
github.com/go-ping/ping v1.1.0/go.mod h1:xIFjORFzTxqIV/tDVGO4eDy/bLuSyawEeojSm3GfRGk=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
|
||||
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
@ -16,34 +18,77 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
|
||||
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
|
||||
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
|
||||
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
|
||||
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
|
||||
github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8=
|
||||
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
|
||||
github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
|
||||
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
|
||||
golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU=
|
||||
golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
|
||||
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
|
||||
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
|
||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
|
||||
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
novit.nc/direktil/pkg v0.0.0-20220221171542-fd3ce3a1491b h1:4KIhYb83Qwe6I0BLr0bnRuFvWto7hfuBEGsnQ6HVG3U=
|
||||
novit.nc/direktil/pkg v0.0.0-20220221171542-fd3ce3a1491b/go.mod h1:zwTVO6U0tXFEaga73megQIBK7yVIKZJVePaIh/UtdfU=
|
||||
novit.tech/direktil/pkg v0.0.0-20240120131645-39b9b401ba38 h1:1Q1X91BwE1g1NFqeA9sJh7G9OS4D75QTWHNnzXZgY70=
|
||||
novit.tech/direktil/pkg v0.0.0-20240120131645-39b9b401ba38/go.mod h1:zjezU6tELE880oYHs/WAauGBupKIEQQ7KqWTB69RW10=
|
||||
|
@ -1,16 +0,0 @@
|
||||
#!/sbin/openrc-run
|
||||
|
||||
description="Direktil boot operations."
|
||||
|
||||
depend()
|
||||
{
|
||||
provide net
|
||||
before sysctl
|
||||
}
|
||||
|
||||
start()
|
||||
{
|
||||
ebegin "Running Direktil boot operations"
|
||||
/sbin/dkl init boot
|
||||
eend $? "Direktil boot operations failed"
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
#!/sbin/openrc-run
|
||||
|
||||
description="Direktil default operations."
|
||||
|
||||
depend()
|
||||
{
|
||||
# need anything?
|
||||
:
|
||||
}
|
||||
|
||||
start()
|
||||
{
|
||||
ebegin "Running Direktil default operations"
|
||||
/sbin/dkl init default
|
||||
eend $? "Direktil default operations failed"
|
||||
}
|
@ -1,30 +1,6 @@
|
||||
# Global OpenRC configuration settings
|
||||
rc_shell=/sbin/sulogin
|
||||
|
||||
# rc_logger launches a logging daemon to log the entire rc process to
|
||||
# /var/log/rc.log
|
||||
# NOTE: Linux systems require the devfs service to be started before
|
||||
# logging can take place and as such cannot log the sysinit runlevel.
|
||||
#rc_logger="NO"
|
||||
|
||||
# Through rc_log_path you can specify a custom log file.
|
||||
# The default value is: /var/log/rc.log
|
||||
#rc_log_path="/var/log/rc.log"
|
||||
|
||||
# By default we assume that all daemons will start correctly.
|
||||
# However, some do not - a classic example is that they fork and return 0 AND
|
||||
# then child barfs on a configuration error. Or the daemon has a bug and the
|
||||
# child crashes. You can set the number of milliseconds start-stop-daemon
|
||||
# waits to check that the daemon is still running after starting here.
|
||||
# The default is 0 - no checking.
|
||||
#rc_start_wait=100
|
||||
|
||||
# Set unicode to YES to turn on unicode support for keyboards and screens.
|
||||
unicode="YES"
|
||||
|
||||
##############################################################################
|
||||
# SERVICE CONFIGURATION VARIABLES
|
||||
|
||||
rc_tty_number=12
|
||||
|
||||
##############################################################################
|
||||
@ -35,7 +11,7 @@ rc_tty_number=12
|
||||
# cgroups version 1 on /sys/fs/cgroup.
|
||||
# "legacy" mounts cgroups version 1 on /sys/fs/cgroup
|
||||
# "unified" mounts cgroups version 2 on /sys/fs/cgroup
|
||||
rc_cgroup_mode="legacy"
|
||||
rc_cgroup_mode="hybrid"
|
||||
|
||||
# This switch controls whether or not cgroups version 1 controllers are
|
||||
# individually mounted under
|
||||
|
@ -1 +0,0 @@
|
||||
../../init.d/dkl-default
|
@ -1 +0,0 @@
|
||||
../../init.d/dkl-user-services
|
@ -1,6 +1,6 @@
|
||||
modd.conf {}
|
||||
|
||||
**/*.go layer/**/* test-vm update-test-data {
|
||||
**/*.go go.mod go.sum layer/**/* test-vm update-test-data {
|
||||
prep: go test ./...
|
||||
prep: mkdir -p dist
|
||||
prep: CGO_ENABLED=0 go build -o dist/ -trimpath ./...
|
||||
|
@ -1,94 +0,0 @@
|
||||
package apply
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"novit.nc/direktil/inits/pkg/vars"
|
||||
"novit.nc/direktil/pkg/config"
|
||||
)
|
||||
|
||||
const (
|
||||
authorizedKeysPath = "/root/.ssh/authorized_keys"
|
||||
)
|
||||
|
||||
// Files writes the files from the given config
|
||||
func Files(cfg *config.Config, filters ...string) (err error) {
|
||||
accept := func(n string) bool { return true }
|
||||
|
||||
if len(filters) > 0 {
|
||||
accept = func(n string) bool {
|
||||
for _, filter := range filters {
|
||||
if matched, err := filepath.Match(filter, n); err != nil {
|
||||
log.Printf("ERROR: bad filter ignored: %q: %v", filter, err)
|
||||
} else if matched {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.RootUser.AuthorizedKeys != nil && accept(authorizedKeysPath) {
|
||||
err = writeFile(
|
||||
authorizedKeysPath,
|
||||
[]byte(strings.Join(cfg.RootUser.AuthorizedKeys, "\n")),
|
||||
0600, 0700, cfg,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for _, file := range cfg.Files {
|
||||
if !accept(file.Path) {
|
||||
continue
|
||||
}
|
||||
|
||||
mode := file.Mode
|
||||
if mode == 0 {
|
||||
mode = 0644
|
||||
}
|
||||
|
||||
content := []byte(file.Content)
|
||||
|
||||
err = writeFile(
|
||||
file.Path,
|
||||
content,
|
||||
mode,
|
||||
0755,
|
||||
cfg,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
log.Print("failed to write file ", file.Path, ": ", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func writeFile(path string, content []byte, fileMode, dirMode os.FileMode, cfg *config.Config) (err error) {
|
||||
if err = os.MkdirAll(filepath.Dir(path), dirMode); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
content = vars.Substitute(content, cfg)
|
||||
|
||||
log.Printf("writing %q, mode %04o, %d bytes", path, fileMode, len(content))
|
||||
if err = ioutil.WriteFile(path, content, fileMode); err != nil {
|
||||
err = fmt.Errorf("failed to write %s: %v", path, err)
|
||||
}
|
||||
|
||||
if chmodErr := os.Chmod(path, fileMode); chmodErr != nil {
|
||||
log.Print("- failed chmod: ", chmodErr)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
@ -3,16 +3,17 @@ package applyconfig
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
"novit.nc/direktil/inits/pkg/apply"
|
||||
"novit.nc/direktil/pkg/config"
|
||||
|
||||
dlog "novit.nc/direktil/pkg/log"
|
||||
"novit.tech/direktil/pkg/config"
|
||||
"novit.tech/direktil/pkg/config/apply"
|
||||
)
|
||||
|
||||
var (
|
||||
filters []string
|
||||
log = dlog.Get("dkl")
|
||||
filters []string
|
||||
pathPrefix string
|
||||
)
|
||||
|
||||
func Command() (c *cobra.Command) {
|
||||
@ -26,11 +27,14 @@ func Command() (c *cobra.Command) {
|
||||
|
||||
flag := c.Flags()
|
||||
flag.StringArrayVarP(&filters, "filter", "F", []string{}, "glob filter to select files to apply")
|
||||
flag.StringVarP(&pathPrefix, "prefix", "P", "", "path prefix")
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func run(_ *cobra.Command, args []string) {
|
||||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
||||
|
||||
configPath := args[0]
|
||||
|
||||
var (
|
||||
@ -39,20 +43,19 @@ func run(_ *cobra.Command, args []string) {
|
||||
)
|
||||
|
||||
if configPath == "-" {
|
||||
log.Print("loading config from stdin")
|
||||
log.Info().Str("from", "stdin").Msg("loading config")
|
||||
cfg, err = config.Read(os.Stdin)
|
||||
|
||||
} else {
|
||||
log.Print("loading config from ", configPath)
|
||||
log.Info().Str("from", configPath).Msg("loading config")
|
||||
cfg, err = config.Load(configPath)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Print("failed to load config: ", err)
|
||||
log.Fatal().Err(err).Msg("failed to load config")
|
||||
}
|
||||
|
||||
if err = apply.Files(cfg /*log,*/, filters...); err != nil {
|
||||
log.Taint(dlog.Fatal, "failed to apply files: ", err)
|
||||
os.Exit(1)
|
||||
if err = apply.Files(cfg, pathPrefix, filters...); err != nil {
|
||||
log.Fatal().Err(err).Msg("failed to apply files")
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var urlPrefix = "https://dkl.novit.nc/dist/layers"
|
||||
var urlPrefix = "https://dkl.novit.io/dist/layers"
|
||||
|
||||
func Command() (c *cobra.Command) {
|
||||
c = &cobra.Command{
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
pconfig "novit.nc/direktil/pkg/config"
|
||||
pconfig "novit.tech/direktil/pkg/config"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
pconfig "novit.nc/direktil/pkg/config"
|
||||
pconfig "novit.tech/direktil/pkg/config"
|
||||
)
|
||||
|
||||
func listCommand() (cmd *cobra.Command) {
|
||||
|
@ -1,37 +0,0 @@
|
||||
package initboot
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"novit.nc/direktil/inits/pkg/sys"
|
||||
)
|
||||
|
||||
var (
|
||||
doNetwork bool
|
||||
)
|
||||
|
||||
func Command() (c *cobra.Command) {
|
||||
c = &cobra.Command{
|
||||
Use: "boot",
|
||||
Short: "boot stage",
|
||||
Run: run,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func run(c *cobra.Command, args []string) {
|
||||
step("files", setupFiles)
|
||||
step("modules", setupModules)
|
||||
step("network", setupNetworking)
|
||||
step("lvm", setupLVM)
|
||||
}
|
||||
|
||||
func setupModules() {
|
||||
for _, mod := range sys.Config().Modules {
|
||||
log.Print("loading module ", mod)
|
||||
sys.Run("modprobe", mod)
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
package initboot
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
||||
"novit.nc/direktil/inits/pkg/apply"
|
||||
"novit.nc/direktil/inits/pkg/sys"
|
||||
)
|
||||
|
||||
func setupFiles() {
|
||||
cfg := sys.Config()
|
||||
|
||||
// make root rshared (default in systemd, required by Kubernetes 1.10+)
|
||||
// equivalent to "mount --make-rshared /"
|
||||
// see kernel's Documentation/sharedsubtree.txt (search rshared)
|
||||
if err := syscall.Mount("", "/", "", syscall.MS_SHARED|syscall.MS_REC, ""); err != nil {
|
||||
log.Fatalf("FATAL: mount --make-rshared / failed: %v", err)
|
||||
}
|
||||
|
||||
// - setup root user
|
||||
if passwordHash := cfg.RootUser.PasswordHash; passwordHash == "" {
|
||||
sys.MustRun("/usr/bin/passwd", "-d", "root")
|
||||
} else {
|
||||
sys.MustRun("/bin/sh", "-c", "chpasswd --encrypted <<EOF\nroot:"+passwordHash+"\nEOF")
|
||||
}
|
||||
|
||||
// - groups
|
||||
for _, group := range cfg.Groups {
|
||||
opts := make([]string, 0)
|
||||
opts = append(opts, "-r")
|
||||
if group.Gid != 0 {
|
||||
opts = append(opts, "-g", strconv.Itoa(group.Gid))
|
||||
}
|
||||
opts = append(opts, group.Name)
|
||||
|
||||
sys.MustRun("groupadd", opts...)
|
||||
}
|
||||
|
||||
// - user
|
||||
for _, user := range cfg.Users {
|
||||
opts := make([]string, 0)
|
||||
opts = append(opts, "-r")
|
||||
if user.Gid != 0 {
|
||||
opts = append(opts, "-g", strconv.Itoa(user.Gid))
|
||||
}
|
||||
if user.Uid != 0 {
|
||||
opts = append(opts, "-u", strconv.Itoa(user.Uid))
|
||||
}
|
||||
opts = append(opts, user.Name)
|
||||
|
||||
sys.MustRun("useradd", opts...)
|
||||
}
|
||||
|
||||
// - files
|
||||
if err := apply.Files(cfg); err != nil {
|
||||
log.Fatal("FATAL: ", err)
|
||||
}
|
||||
}
|
@ -1,190 +0,0 @@
|
||||
package initboot
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"novit.nc/direktil/pkg/config"
|
||||
|
||||
"novit.nc/direktil/inits/pkg/sys"
|
||||
"novit.nc/direktil/inits/pkg/vars"
|
||||
)
|
||||
|
||||
func setupLVM() {
|
||||
if !dmInProc() {
|
||||
sys.MustRun("modprobe", "dm-mod")
|
||||
}
|
||||
|
||||
// start lvmetad
|
||||
if lvmetad, err := exec.LookPath("lvmetad"); err == nil {
|
||||
sys.Mkdir("/run/lvm", 0700)
|
||||
sys.Mkdir("/run/lock/lvm", 0700)
|
||||
sys.Run(lvmetad)
|
||||
|
||||
sys.WaitFile("/run/lvm/lvmetad.socket", time.After(30*time.Second))
|
||||
} else {
|
||||
log.Print("skipping lvmetad setup: ", err)
|
||||
}
|
||||
|
||||
// scan devices
|
||||
sys.Run("lvm", "pvscan")
|
||||
sys.Run("lvm", "vgscan", "--mknodes")
|
||||
sys.Run("lvm", "vgchange", "--sysinit", "-a", "ly")
|
||||
|
||||
cfg := sys.Config()
|
||||
|
||||
// setup storage
|
||||
log.Print("checking storage")
|
||||
if err := exec.Command("vgdisplay", "storage").Run(); err != nil {
|
||||
log.Print("- creating VG storage")
|
||||
setupVG(vars.BootArgValue("storage", cfg.Storage.UdevMatch))
|
||||
}
|
||||
|
||||
for _, name := range cfg.Storage.RemoveVolumes {
|
||||
dev := "/dev/storage/" + name
|
||||
|
||||
if _, err := os.Stat(dev); os.IsNotExist(err) {
|
||||
continue
|
||||
|
||||
} else if err != nil {
|
||||
log.Fatal("failed to stat ", dev, ": ", err)
|
||||
}
|
||||
|
||||
log.Print("- removing LV ", name)
|
||||
cmd := exec.Command("lvremove", "-f", "storage/"+name)
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
log.Fatal("failed to remove LV ", name)
|
||||
}
|
||||
}
|
||||
|
||||
// setup volumes
|
||||
for _, volume := range cfg.Storage.Volumes {
|
||||
if err := exec.Command("lvdisplay", "storage/"+volume.Name).Run(); err != nil {
|
||||
log.Print("- creating LV ", volume.Name)
|
||||
setupLV(volume)
|
||||
}
|
||||
|
||||
dev := "/dev/storage/" + volume.Name
|
||||
|
||||
sys.WaitFile(dev, time.After(30*time.Second))
|
||||
|
||||
log.Printf("checking filesystem on %s", dev)
|
||||
sys.MustRun("fsck", "-p", dev)
|
||||
|
||||
sys.Mount(dev, volume.Mount.Path, volume.FS,
|
||||
syscall.MS_NOATIME|syscall.MS_RELATIME,
|
||||
volume.Mount.Options)
|
||||
}
|
||||
}
|
||||
|
||||
func dmInProc() bool {
|
||||
for _, f := range []string{"devices", "misc"} {
|
||||
c, err := ioutil.ReadFile("/proc/" + f)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to read %s: %v", f, err)
|
||||
}
|
||||
if !bytes.Contains(c, []byte("device-mapper")) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func setupVG(udevMatch string) {
|
||||
const pDevName = "DEVNAME="
|
||||
|
||||
dev := ""
|
||||
try := 0
|
||||
|
||||
retry:
|
||||
paths, err := filepath.Glob("/sys/class/block/*")
|
||||
if err != nil {
|
||||
log.Fatal("failed to list block devices: ", err)
|
||||
}
|
||||
|
||||
for _, path := range paths {
|
||||
// ignore loop devices
|
||||
if strings.HasPrefix("loop", filepath.Base(path)) {
|
||||
continue
|
||||
}
|
||||
|
||||
// fetch udev informations
|
||||
out, err := exec.Command("udevadm", "info", "-q", "property", path).CombinedOutput()
|
||||
if err != nil {
|
||||
log.Printf("WARNING: udev query of %q failed: %v\n%s", path, err, string(out))
|
||||
continue
|
||||
}
|
||||
|
||||
propertyLines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
||||
|
||||
devPath := ""
|
||||
matches := false
|
||||
|
||||
for _, line := range propertyLines {
|
||||
if strings.HasPrefix(line, pDevName) {
|
||||
devPath = line[len(pDevName):]
|
||||
}
|
||||
|
||||
if matched, err := filepath.Match(udevMatch, line); err != nil {
|
||||
log.Fatalf("FATAL: invalid match: %q: %v", udevMatch, err)
|
||||
|
||||
} else if matched {
|
||||
matches = true
|
||||
}
|
||||
|
||||
if devPath != "" && matches {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if devPath != "" && matches {
|
||||
dev = devPath
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if dev == "" {
|
||||
time.Sleep(1 * time.Second)
|
||||
try++
|
||||
if try > 30 {
|
||||
log.Fatal("FATAL: storage device not found after 30s: ", udevMatch)
|
||||
}
|
||||
goto retry
|
||||
}
|
||||
|
||||
log.Print("found storage device at ", dev)
|
||||
|
||||
sys.MustRun("pvcreate", dev)
|
||||
sys.MustRun("vgcreate", "storage", dev)
|
||||
}
|
||||
|
||||
func setupLV(volume config.VolumeDef) {
|
||||
if volume.Extents != "" {
|
||||
sys.MustRun("lvcreate", "-l", volume.Extents, "-n", volume.Name, "storage")
|
||||
} else {
|
||||
sys.MustRun("lvcreate", "-L", volume.Size, "-n", volume.Name, "storage")
|
||||
}
|
||||
|
||||
// wait the device link
|
||||
devPath := "/dev/storage/" + volume.Name
|
||||
sys.WaitFile(devPath, time.After(30*time.Second))
|
||||
|
||||
args := make([]string, 0)
|
||||
|
||||
switch volume.FS {
|
||||
case "btrfs":
|
||||
args = append(args, "-f")
|
||||
case "ext4":
|
||||
args = append(args, "-F")
|
||||
}
|
||||
|
||||
sys.MustRun("mkfs."+volume.FS, append(args, devPath)...)
|
||||
}
|
@ -1,156 +0,0 @@
|
||||
package initboot
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/go-ping/ping"
|
||||
"novit.nc/direktil/pkg/config"
|
||||
|
||||
"novit.nc/direktil/inits/pkg/sys"
|
||||
"novit.nc/direktil/inits/pkg/vars"
|
||||
)
|
||||
|
||||
var networkStarted = map[string]bool{}
|
||||
|
||||
func setupNetworking() {
|
||||
cfg := sys.Config()
|
||||
for idx, network := range cfg.Networks {
|
||||
step(fmt.Sprintf("network:%d", idx), func() { setupNetwork(idx, network) })
|
||||
}
|
||||
}
|
||||
|
||||
func setupNetwork(idx int, network config.NetworkDef) {
|
||||
tries := 0
|
||||
retry:
|
||||
ifaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
log.Fatalf("FATAL: failed to get network interfaces: %v", err)
|
||||
}
|
||||
|
||||
match := false
|
||||
for _, iface := range ifaces {
|
||||
if networkStarted[iface.Name] {
|
||||
continue
|
||||
}
|
||||
|
||||
if network.Match.Name != "" {
|
||||
if ok, err := filepath.Match(network.Match.Name, iface.Name); err != nil {
|
||||
log.Fatalf("FATAL: network[%d] name match error: %v", idx, err)
|
||||
} else if !ok {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if network.Match.Ping != nil {
|
||||
log.Printf("network[%d] ping check on %s", idx, iface.Name)
|
||||
|
||||
if ok, err := networkPingCheck(iface.Name, network); err != nil {
|
||||
log.Printf("ERROR: network[%d] ping check failed: %v", idx, err)
|
||||
|
||||
} else if !ok {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("network[%d] matches interface %s", idx, iface.Name)
|
||||
match = true
|
||||
|
||||
startNetwork(iface.Name, idx, network)
|
||||
|
||||
if !network.Match.All {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if !match {
|
||||
log.Printf("WARNING: network[%d] did not match any interface", idx)
|
||||
|
||||
tries++
|
||||
if network.Optional && tries > 3 {
|
||||
return
|
||||
}
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
log.Printf("WARNING: network[%d] retrying (try: %d)", idx, tries)
|
||||
goto retry
|
||||
}
|
||||
}
|
||||
|
||||
func startNetwork(ifaceName string, idx int, network config.NetworkDef) {
|
||||
cfg := sys.Config()
|
||||
|
||||
log.Printf("starting network[%d]", idx)
|
||||
|
||||
script := vars.Substitute([]byte(network.Script), cfg)
|
||||
|
||||
c := exec.Command("/bin/sh")
|
||||
c.Stdin = bytes.NewBuffer(script)
|
||||
c.Stdout = os.Stdout
|
||||
c.Stderr = os.Stderr
|
||||
|
||||
// TODO doc
|
||||
c.Env = append(append(make([]string, 0), os.Environ()...), "IFNAME="+ifaceName)
|
||||
|
||||
if err := c.Run(); err != nil {
|
||||
links, _ := exec.Command("ip", "link", "ls").CombinedOutput()
|
||||
log.Fatalf("FATAL: network setup failed (link list below): %v\n%s", err, string(links))
|
||||
}
|
||||
|
||||
networkStarted[ifaceName] = true
|
||||
}
|
||||
|
||||
func networkPingCheck(ifName string, network config.NetworkDef) (b bool, err error) {
|
||||
check := network.Match.Ping
|
||||
|
||||
source := string(vars.Substitute([]byte(check.Source), sys.Config()))
|
||||
|
||||
if err = sys.Run("ip", "addr", "add", source, "dev", ifName); err != nil {
|
||||
return
|
||||
}
|
||||
if err = sys.Run("ip", "link", "set", ifName, "up"); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
sys.MustRun("ip", "link", "set", ifName, "down")
|
||||
sys.MustRun("ip", "addr", "del", source, "dev", ifName)
|
||||
}()
|
||||
|
||||
count := 3
|
||||
if check.Count != 0 {
|
||||
count = check.Count
|
||||
}
|
||||
|
||||
for n := 0; n < count; n++ {
|
||||
// TODO probably better to use golang.org/x/net/icmp directly
|
||||
pinger, e := ping.NewPinger(network.Match.Ping.Target)
|
||||
if e != nil {
|
||||
err = e
|
||||
return
|
||||
}
|
||||
|
||||
pinger.Count = 1
|
||||
|
||||
pinger.Timeout = 1 * time.Second
|
||||
if check.Timeout > 0 {
|
||||
pinger.Timeout = time.Duration(check.Timeout) * time.Second
|
||||
}
|
||||
|
||||
pinger.SetPrivileged(true)
|
||||
pinger.Run()
|
||||
|
||||
if pinger.Statistics().PacketsRecv > 0 {
|
||||
b = true
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package initboot
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
var stateFile = "/run/dkl-boot.state"
|
||||
|
||||
func readState() (state map[string]bool) {
|
||||
state = map[string]bool{}
|
||||
|
||||
ba, err := ioutil.ReadFile(stateFile)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return
|
||||
}
|
||||
log.Fatal("failed to read state: ", err)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(ba, &state)
|
||||
if err != nil {
|
||||
log.Fatal("failed to parse state: ", err)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func writeState(state map[string]bool) {
|
||||
ba, err := json.Marshal(state)
|
||||
if err != nil {
|
||||
log.Fatal("failed to serialize state: ", err)
|
||||
}
|
||||
|
||||
ioutil.WriteFile(stateFile, ba, 0600)
|
||||
}
|
||||
|
||||
func step(step string, operation func()) {
|
||||
state := readState()
|
||||
if !state[step] {
|
||||
operation()
|
||||
|
||||
state[step] = true
|
||||
writeState(state)
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package initdefault
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
func Command() (c *cobra.Command) {
|
||||
c = &cobra.Command{
|
||||
Use: "default",
|
||||
Short: "default stage",
|
||||
Run: run,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func run(c *cobra.Command, args []string) {
|
||||
}
|
@ -6,9 +6,7 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
initboot "novit.nc/direktil/inits/pkg/cmd/init/boot"
|
||||
initdefault "novit.nc/direktil/inits/pkg/cmd/init/default"
|
||||
initservice "novit.nc/direktil/inits/pkg/cmd/init/service"
|
||||
initservice "novit.tech/direktil/inits/pkg/cmd/init/service"
|
||||
)
|
||||
|
||||
func Command() (c *cobra.Command) {
|
||||
@ -26,8 +24,6 @@ func Command() (c *cobra.Command) {
|
||||
},
|
||||
}
|
||||
|
||||
c.AddCommand(initboot.Command())
|
||||
c.AddCommand(initdefault.Command())
|
||||
c.AddCommand(initservice.Command())
|
||||
|
||||
return
|
||||
|
@ -3,12 +3,13 @@ package initservices
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
plog "novit.nc/direktil/pkg/log"
|
||||
plog "novit.tech/direktil/pkg/log"
|
||||
|
||||
cmdlogger "novit.tech/direktil/inits/pkg/cmd/logger"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -58,18 +59,13 @@ func run(c *cobra.Command, args []string) {
|
||||
|
||||
func runService(svcPath string) {
|
||||
svc := filepath.Base(svcPath)
|
||||
|
||||
logger := plog.Get(svc)
|
||||
plog.EnableFiles()
|
||||
|
||||
n := 0
|
||||
for {
|
||||
lastStart := time.Now()
|
||||
|
||||
cmd := exec.Command(svcPath)
|
||||
cmd.Stdout = logger
|
||||
cmd.Stderr = logger
|
||||
err := cmd.Run()
|
||||
err := cmdlogger.Run("", svcPath)
|
||||
|
||||
if time.Since(lastStart) > crashForgiveDelay {
|
||||
n = 0
|
||||
|
49
pkg/cmd/logger/logger.go
Normal file
49
pkg/cmd/logger/logger.go
Normal file
@ -0,0 +1,49 @@
|
||||
package cmdlogger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
plog "novit.tech/direktil/pkg/log"
|
||||
)
|
||||
|
||||
func Command() (c *cobra.Command) {
|
||||
c = &cobra.Command{
|
||||
Use: "logger [--] <command> [args]",
|
||||
Short: "run a command through the dkl logger",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
Run: run,
|
||||
}
|
||||
c.Flags().StringP("name", "n", "", "log name")
|
||||
return
|
||||
}
|
||||
|
||||
func run(c *cobra.Command, args []string) {
|
||||
logName, _ := c.Flags().GetString("name")
|
||||
err := Run(logName, args[0], args[1:]...)
|
||||
if err == nil {
|
||||
os.Exit(0)
|
||||
} else if exitErr, ok := err.(*exec.ExitError); ok {
|
||||
os.Exit(exitErr.ExitCode())
|
||||
} else {
|
||||
fmt.Fprintln(os.Stderr, "failed to run command: "+err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func Run(logName, command string, args ...string) (err error) {
|
||||
if logName == "" {
|
||||
logName = filepath.Base(command)
|
||||
}
|
||||
|
||||
logger := plog.Get(logName)
|
||||
plog.EnableFiles()
|
||||
|
||||
cmd := exec.Command(command, args...)
|
||||
cmd.Stdout = logger
|
||||
cmd.Stderr = logger
|
||||
return cmd.Run()
|
||||
}
|
@ -4,7 +4,7 @@ import (
|
||||
"log"
|
||||
"sync"
|
||||
|
||||
"novit.nc/direktil/pkg/config"
|
||||
"novit.tech/direktil/pkg/config"
|
||||
)
|
||||
|
||||
const cfgPath = "/config.yaml"
|
||||
|
@ -3,7 +3,7 @@ package vars
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"novit.nc/direktil/pkg/config"
|
||||
"novit.tech/direktil/pkg/config"
|
||||
)
|
||||
|
||||
type Var struct {
|
||||
|
Loading…
Reference in New Issue
Block a user