Skip to content

Commit 3573475

Browse files
committed
feat: Systemd service to mount/umount buckets
Service is available when installed from deb,rpm packages sudo systemctl enable geesefs@{bucket} sudo systemctl start geesefs@{bucket} sudo systemctl status geesefs@{bucket} sudo systemctl stop geesefs@{bucket} Standard AWS SDK config location is used or can be configured in /etc/default/geesefs /etc/default/geesefs-{bucket} bucket is mounted at /mnt/geesefs/{bucket} to run as regular user: systemctl --user enable geesefs@{bucket} systemctl --user start geesefs@{bucket} systemctl --user status geesefs@{bucket} systemctl --user stop geesefs@{bucket} bucket is mounted at ${HOME}/mnt/geesefs/{bucket}
1 parent edced17 commit 3573475

File tree

17 files changed

+112
-788
lines changed

17 files changed

+112
-788
lines changed

.goreleaser.yaml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ version: 2
22
builds:
33
- env:
44
- CGO_ENABLED=0
5+
- ENDPOINT="https://fly.storage.tigris.dev"
56
goos:
67
- linux
78
- windows
@@ -12,7 +13,8 @@ builds:
1213
binary: geesefs
1314
ldflags:
1415
- -w -extldflags '-static'
15-
- -X 'github.com/tigrisdata/geesefs/main.Version={{.Version}}'
16+
- -X 'github.com/yandex-cloud/geesefs/main.Version={{.Version}}'
17+
- -X 'github.com/yandex-cloud/geesefs/main.Endpoint={{.Env.ENDPOINT}}'
1618

1719
archives:
1820
- format_overrides:
@@ -26,9 +28,19 @@ signs:
2628
- artifacts: checksum
2729

2830
nfpms:
29-
- formats:
31+
- maintainer: "Tigrisdata Support <[email protected]>"
32+
formats:
3033
- apk
3134
- deb
3235
- rpm
3336
file_name_template: "geesefs_tigris_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
34-
maintainer: Yevgeniy Firsov <[email protected]>
37+
contents:
38+
- src: pkg/[email protected]
39+
dst: /lib/systemd/system/[email protected]
40+
- src: pkg/[email protected]
41+
dst: /lib/systemd/user/[email protected]
42+
- src: pkg/defaults
43+
dst: /etc/default/geesefs
44+
scripts:
45+
postinstall: pkg/postinst
46+

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
VERSION=$(shell git describe --tags --always)
2+
ENDPOINT ?= "https://fly.storage.tigris.dev"
3+
4+
BUILD_PARAM=-ldflags "-X github.com/yandex-cloud/geesefs/core/cfg.Version=$(VERSION) -X github.com/yandex-cloud/geesefs/core/cfg.DefaultEndpoint=$(ENDPOINT)"
25

36
run-test: s3proxy.jar build-debug
47
./test/run-tests.sh
@@ -22,13 +25,13 @@ get-deps: s3proxy.jar
2225
/bin/bash scripts/install_test_deps.sh
2326

2427
build:
25-
go build -ldflags "github.com/tigrisdata/geesefs/core/cfg.Version=$(VERSION)"
28+
go build $(BUILD_PARAM)
2629

2730
build-debug:
28-
CGO_ENABLED=1 go build -race -ldflags "-X main.Version=`git rev-parse HEAD`"
31+
CGO_ENABLED=1 go build -race $(BUILD_PARAM)
2932

3033
install:
31-
go install -ldflags "github.com/tigrisdata/geesefs/core/cfg.Version=$(VERSION)"
34+
go install $(BUILD_PARAM)
3235

3336
# Setup local development environment.
3437
setup: get-deps

core/backend_s3.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,9 @@ func (s *S3Backend) detectBucketLocationByHEAD() (err error, isAws bool) {
276276
Path: s.bucket,
277277
}
278278

279-
if s.awsConfig.Endpoint != nil {
280-
endpoint, err := url.Parse(*s.awsConfig.Endpoint)
279+
e := s.awsConfig.Endpoint
280+
if e != nil && *e != "" {
281+
endpoint, err := url.Parse(*e)
281282
if err != nil {
282283
return err, false
283284
}
@@ -402,16 +403,9 @@ func (s *S3Backend) Init(key string) error {
402403
if err == nil {
403404
// we detected a region header, this is probably AWS S3,
404405
// or we can use anonymous access, or both
405-
s.newS3()
406-
} else if err == syscall.ENXIO {
407-
return fmt.Errorf("bucket %v does not exist", s.bucket)
408-
} else {
409-
// this is NOT AWS, we expect the request to fail with 403 if this is not
410-
// an anonymous bucket
411-
if err != syscall.EACCES {
412-
s3Log.Errorf("Unable to access '%v': %v", s.bucket, err)
413-
}
414406
}
407+
// if region still not set let SDK config and service decide whether it needed
408+
s.newS3()
415409
}
416410

417411
// try again with the credential to make sure

core/cfg/conf_s3.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"encoding/base64"
2222
"fmt"
2323
"net/http"
24+
"os"
2425
"time"
2526

2627
"github.com/aws/aws-sdk-go/aws"
@@ -104,7 +105,26 @@ func (c *S3Config) Init() *S3Config {
104105
return c
105106
}
106107

108+
func (c *S3Config) logSourceOfCredentials(flags *FlagStorage) {
109+
if c.AccessKey != "" {
110+
log.Infof("internal config %v", c.AccessKey)
111+
} else if os.Getenv("AWS_ACCESS_KEY") != "" {
112+
log.Infof("env AWS_ACCESS_KEY = %v", os.Getenv("AWS_ACCESS_KEY"))
113+
} else if os.Getenv("AWS_PROFILE") != "" {
114+
log.Infof("env AWS_PROFILE = %v", os.Getenv("AWS_PROFILE"))
115+
}
116+
if flags.Endpoint != "" {
117+
log.Infof("command line endpoint: %v", flags.Endpoint)
118+
} else if os.Getenv("AWS_ENDPOINT_URL") != "" {
119+
log.Infof("env AWS_ENDPOINT_URL = %v", os.Getenv("AWS_ENDPOINT_URL"))
120+
} else if DefaultEndpoint != "" {
121+
log.Infof("default endpoint = %v", DefaultEndpoint)
122+
}
123+
}
124+
107125
func (c *S3Config) ToAwsConfig(flags *FlagStorage) (*aws.Config, error) {
126+
c.logSourceOfCredentials(flags)
127+
108128
tr := &defaultHTTPTransport
109129
if flags.NoVerifySSL {
110130
if tr.TLSClientConfig != nil {
@@ -134,6 +154,10 @@ func (c *S3Config) ToAwsConfig(flags *FlagStorage) (*aws.Config, error) {
134154
}
135155
if flags.Endpoint != "" {
136156
awsConfig.Endpoint = &flags.Endpoint
157+
} else if os.Getenv("AWS_ENDPOINT_URL") != "" {
158+
awsConfig.Endpoint = aws.String(os.Getenv("AWS_ENDPOINT_URL"))
159+
} else {
160+
awsConfig.Endpoint = &DefaultEndpoint
137161
}
138162

139163
awsConfig.S3ForcePathStyle = aws.Bool(!c.Subdomain)

core/cfg/flags.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ import (
3030
"github.com/urfave/cli"
3131
)
3232

33-
var Version = "0.42.4"
33+
var (
34+
Version string // set by build system
35+
DefaultEndpoint string // set by build system
36+
)
3437

3538
var flagCategories map[string]string
3639

@@ -159,9 +162,9 @@ MISC OPTIONS:
159162

160163
cli.StringFlag{
161164
Name: "endpoint",
162-
Value: "https://storage.yandexcloud.net",
165+
Value: "",
163166
Usage: "The S3 endpoint to connect to." +
164-
" Possible values: http://127.0.0.1:8081/, https://s3.amazonaws.com",
167+
" Examples: http://127.0.0.1:8081/, " + DefaultEndpoint,
165168
},
166169

167170
cli.StringFlag{
@@ -1078,7 +1081,7 @@ func DefaultFlags() *FlagStorage {
10781081
Gid: uint32(gid),
10791082
Setuid: uid,
10801083
Setgid: gid,
1081-
Endpoint: "https://storage.yandexcloud.net",
1084+
Endpoint: "",
10821085
Backend: (&S3Config{}).Init(),
10831086
MemoryLimit: 1000 * 1024 * 1024,
10841087
EntryLimit: 100000,

0 commit comments

Comments
 (0)