Skip to content

Commit 68049b1

Browse files
authored
Merge pull request #54 from funbox/develop
Version 0.21.0
2 parents c9e3f9f + bd198a1 commit 68049b1

File tree

14 files changed

+102
-43
lines changed

14 files changed

+102
-43
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
sudo: required
2-
31
language: go
42

53
go:

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ uninstall: ## Uninstall binaries
2323

2424
deps: ## Download dependencies
2525
git config --global http.https://pkg.re.followRedirects true
26-
go get -d -v pkg.re/essentialkaos/ek.v9
26+
go get -d -v pkg.re/essentialkaos/ek.v10
2727
go get -d -v pkg.re/essentialkaos/go-simpleyaml.v1
2828

2929
deps-test: ## Download dependencies for tests
3030
git config --global http.https://pkg.re.followRedirects true
3131
go get -d -v pkg.re/check.v1
32-
go get -d -v pkg.re/essentialkaos/ek.v9
32+
go get -d -v pkg.re/essentialkaos/ek.v10
3333

3434
test: ## Run tests
3535
go test -covermode=count ./...

cli/cli.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import (
1313
"os"
1414
"runtime"
1515

16-
"pkg.re/essentialkaos/ek.v9/env"
17-
"pkg.re/essentialkaos/ek.v9/fmtc"
18-
"pkg.re/essentialkaos/ek.v9/fsutil"
19-
"pkg.re/essentialkaos/ek.v9/knf"
20-
"pkg.re/essentialkaos/ek.v9/log"
21-
"pkg.re/essentialkaos/ek.v9/options"
22-
"pkg.re/essentialkaos/ek.v9/system"
23-
"pkg.re/essentialkaos/ek.v9/usage"
24-
"pkg.re/essentialkaos/ek.v9/usage/update"
16+
"pkg.re/essentialkaos/ek.v10/env"
17+
"pkg.re/essentialkaos/ek.v10/fmtc"
18+
"pkg.re/essentialkaos/ek.v10/fsutil"
19+
"pkg.re/essentialkaos/ek.v10/knf"
20+
"pkg.re/essentialkaos/ek.v10/log"
21+
"pkg.re/essentialkaos/ek.v10/options"
22+
"pkg.re/essentialkaos/ek.v10/system"
23+
"pkg.re/essentialkaos/ek.v10/usage"
24+
"pkg.re/essentialkaos/ek.v10/usage/update"
2525

2626
"github.com/funbox/init-exporter/export"
2727
"github.com/funbox/init-exporter/procfile"
@@ -32,7 +32,7 @@ import (
3232
// App props
3333
const (
3434
APP = "init-exporter"
35-
VER = "0.20.3"
35+
VER = "0.21.0"
3636
DESC = "Utility for exporting services described by Procfile to init system"
3737
)
3838

common/init-exporter.spec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
Summary: Utility for exporting services described by Procfile to init system
4444
Name: init-exporter
45-
Version: 0.20.3
45+
Version: 0.21.0
4646
Release: 0%{?dist}
4747
Group: Development/Tools
4848
License: MIT
@@ -111,6 +111,10 @@ rm -rf %{buildroot}
111111
################################################################################
112112

113113
%changelog
114+
* Wed Jan 09 2019 Anton Novojilov <andyone@fun-box.ru> - 0.21.0-0
115+
- Migrated to ek.v10
116+
- Added support of memlock limit configuration
117+
114118
* Mon Oct 29 2018 Anton Novojilov <andyone@fun-box.ru> - 0.20.3-0
115119
- Fixed bug with parsing v1 procfile (found by go-fuzz)
116120

export/export_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515

1616
"github.com/funbox/init-exporter/procfile"
1717

18-
"pkg.re/essentialkaos/ek.v9/fsutil"
19-
"pkg.re/essentialkaos/ek.v9/log"
18+
"pkg.re/essentialkaos/ek.v10/fsutil"
19+
"pkg.re/essentialkaos/ek.v10/log"
2020

2121
. "pkg.re/check.v1"
2222
)
@@ -155,6 +155,7 @@ func (s *ExportSuite) TestUpstartExport(c *C) {
155155
"",
156156
"limit nofile 1024 1024",
157157
"",
158+
"limit memlock unlimited unlimited",
158159
"",
159160
"script",
160161
" touch /var/log/test_application/serviceA.log",
@@ -179,6 +180,7 @@ func (s *ExportSuite) TestUpstartExport(c *C) {
179180
"",
180181
"limit nofile 1024 1024",
181182
"",
183+
"limit memlock unlimited unlimited",
182184
"",
183185
"script",
184186
" touch /var/log/test_application/serviceA.log",
@@ -204,6 +206,7 @@ func (s *ExportSuite) TestUpstartExport(c *C) {
204206
"limit nofile 4096 4096",
205207
"limit nproc 4096 4096",
206208
"",
209+
"",
207210
"script",
208211
" touch /var/log/test_application/serviceB.log",
209212
" chown service /var/log/test_application/serviceB.log",
@@ -364,6 +367,7 @@ func (s *ExportSuite) TestSystemdExport(c *C) {
364367
"",
365368
"LimitNOFILE=1024",
366369
"",
370+
"LimitMEMLOCK=infinity",
367371
"",
368372
"",
369373
"ExecStartPre=/bin/touch /var/log/test_application/serviceA.log",
@@ -398,6 +402,7 @@ func (s *ExportSuite) TestSystemdExport(c *C) {
398402
"",
399403
"LimitNOFILE=1024",
400404
"",
405+
"LimitMEMLOCK=infinity",
401406
"",
402407
"",
403408
"ExecStartPre=/bin/touch /var/log/test_application/serviceA.log",
@@ -433,6 +438,7 @@ func (s *ExportSuite) TestSystemdExport(c *C) {
433438
"LimitNOFILE=4096",
434439
"LimitNPROC=4096",
435440
"",
441+
"",
436442
"CPUWeight=50",
437443
"StartupCPUWeight=50",
438444
"CPUQuota=35%",
@@ -519,6 +525,7 @@ func createTestApp(helperDir, targetDir string) *procfile.Application {
519525
RespawnCount: 15,
520526
IsRespawnEnabled: true,
521527
LimitFile: 1024,
528+
LimitMemlock: -1,
522529
},
523530
}
524531

export/exporter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
"os"
1313
"strconv"
1414

15-
"pkg.re/essentialkaos/ek.v9/fsutil"
16-
"pkg.re/essentialkaos/ek.v9/log"
17-
"pkg.re/essentialkaos/ek.v9/path"
15+
"pkg.re/essentialkaos/ek.v10/fsutil"
16+
"pkg.re/essentialkaos/ek.v10/log"
17+
"pkg.re/essentialkaos/ek.v10/path"
1818

1919
"github.com/funbox/init-exporter/procfile"
2020
)

export/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"fmt"
1212
"text/template"
1313

14-
"pkg.re/essentialkaos/ek.v9/log"
14+
"pkg.re/essentialkaos/ek.v10/log"
1515

1616
"github.com/funbox/init-exporter/procfile"
1717
)

export/systemd.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"strings"
1414
"time"
1515

16-
"pkg.re/essentialkaos/ek.v9/system/exec"
17-
"pkg.re/essentialkaos/ek.v9/timeutil"
16+
"pkg.re/essentialkaos/ek.v10/system/exec"
17+
"pkg.re/essentialkaos/ek.v10/timeutil"
1818

1919
"github.com/funbox/init-exporter/procfile"
2020
)
@@ -81,6 +81,7 @@ TimeoutStopSec={{.Service.Options.KillTimeout}}
8181
8282
{{ if .Service.Options.IsFileLimitSet }}LimitNOFILE={{.Service.Options.LimitFile}}{{ end }}
8383
{{ if .Service.Options.IsProcLimitSet }}LimitNPROC={{.Service.Options.LimitProc}}{{ end }}
84+
{{ if .Service.Options.IsMemlockLimitSet }}LimitMEMLOCK={{.GetMemlockLimit}}{{ end }}
8485
8586
{{ if .Service.Options.IsResourcesSet }}{{.ResourcesAsString}}{{ end }}
8687
ExecStartPre=/bin/touch /var/log/{{.Application.Name}}/{{.Service.Name}}.log
@@ -279,6 +280,17 @@ func (sp *SystemdProvider) RenderHelperTemplate(service *procfile.Service) (stri
279280

280281
// ////////////////////////////////////////////////////////////////////////////////// //
281282

283+
// GetMemlockLimit return formatted memlock value
284+
func (d *systemdServiceData) GetMemlockLimit() string {
285+
if d.Service.Options.LimitMemlock == -1 {
286+
return "infinity"
287+
}
288+
289+
return fmt.Sprintf("%d", d.Service.Options.LimitMemlock)
290+
}
291+
292+
// ////////////////////////////////////////////////////////////////////////////////// //
293+
282294
// renderLevel convert level number to upstart level name
283295
func (sp *SystemdProvider) renderLevel(level int) string {
284296
switch level {

export/upstart.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"fmt"
1111
"time"
1212

13-
"pkg.re/essentialkaos/ek.v9/timeutil"
13+
"pkg.re/essentialkaos/ek.v10/timeutil"
1414

1515
"github.com/funbox/init-exporter/procfile"
1616
)
@@ -66,6 +66,7 @@ kill timeout {{.Service.Options.KillTimeout}}
6666
6767
{{ if .Service.Options.IsFileLimitSet }}limit nofile {{.Service.Options.LimitFile}} {{.Service.Options.LimitFile}}{{ end }}
6868
{{ if .Service.Options.IsProcLimitSet }}limit nproc {{.Service.Options.LimitProc}} {{.Service.Options.LimitProc}}{{ end }}
69+
{{ if .Service.Options.IsMemlockLimitSet }}limit memlock {{.GetMemlockLimit}} {{.GetMemlockLimit}}{{ end }}
6970
7071
script
7172
touch /var/log/{{.Application.Name}}/{{.Service.Name}}.log
@@ -162,3 +163,14 @@ func (up *UpstartProvider) RenderHelperTemplate(service *procfile.Service) (stri
162163

163164
return renderTemplate("upstart-helper-template", TEMPLATE_UPSTART_HELPER, data)
164165
}
166+
167+
// ////////////////////////////////////////////////////////////////////////////////// //
168+
169+
// GetMemlockLimit return formatted memlock value
170+
func (d *upstartServiceData) GetMemlockLimit() string {
171+
if d.Service.Options.LimitMemlock == -1 {
172+
return "unlimited"
173+
}
174+
175+
return fmt.Sprintf("%d", d.Service.Options.LimitMemlock)
176+
}

procfile/procfile.go

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import (
1313
"sort"
1414
"strings"
1515

16-
"pkg.re/essentialkaos/ek.v9/errutil"
17-
"pkg.re/essentialkaos/ek.v9/fsutil"
18-
"pkg.re/essentialkaos/ek.v9/log"
19-
"pkg.re/essentialkaos/ek.v9/path"
20-
"pkg.re/essentialkaos/ek.v9/sliceutil"
21-
"pkg.re/essentialkaos/ek.v9/strutil"
16+
"pkg.re/essentialkaos/ek.v10/errutil"
17+
"pkg.re/essentialkaos/ek.v10/fsutil"
18+
"pkg.re/essentialkaos/ek.v10/log"
19+
"pkg.re/essentialkaos/ek.v10/path"
20+
"pkg.re/essentialkaos/ek.v10/sliceutil"
21+
"pkg.re/essentialkaos/ek.v10/strutil"
2222
)
2323

2424
// ////////////////////////////////////////////////////////////////////////////////// //
@@ -43,6 +43,7 @@ type Config struct {
4343
KillTimeout int // Global kill timeout in seconds
4444
LimitProc int // Global processes limit
4545
LimitFile int // Global descriptors limit
46+
LimitMemlock int // Global max locked memory limit
4647
}
4748

4849
type Service struct {
@@ -70,6 +71,7 @@ type ServiceOptions struct {
7071
IsRespawnEnabled bool // Respawn enabled flag
7172
LimitProc int // Processes limit
7273
LimitFile int // Descriptors limit
74+
LimitMemlock int // Max locked memory limit
7375
Resources *Resources // Resources limits (systemd only)
7476
}
7577

@@ -291,57 +293,62 @@ func (s *Service) GetCommandExec(command string) string {
291293
return result
292294
}
293295

294-
// IsRespawnLimitSet return true if respawn options is set
296+
// IsRespawnLimitSet returns true if respawn options is set
295297
func (so *ServiceOptions) IsRespawnLimitSet() bool {
296298
return so.RespawnCount != 0 || so.RespawnInterval != 0
297299
}
298300

299-
// IsCustomLogEnabled return true if service have custom log
301+
// IsCustomLogEnabled returns true if service have custom log
300302
func (so *ServiceOptions) IsCustomLogEnabled() bool {
301303
return so.LogFile != ""
302304
}
303305

304-
// IsEnvSet return true if service have custom env vars
306+
// IsEnvSet returns true if service have custom env vars
305307
func (so *ServiceOptions) IsEnvSet() bool {
306308
return len(so.Env) != 0
307309
}
308310

309-
// IsEnvFileSet return true if service have file with env vars
311+
// IsEnvFileSet returns true if service have file with env vars
310312
func (so *ServiceOptions) IsEnvFileSet() bool {
311313
return so.EnvFile != ""
312314
}
313315

314-
// IsFileLimitSet return true if descriptors limit is set
316+
// IsFileLimitSet returns true if descriptors limit is set
315317
func (so *ServiceOptions) IsFileLimitSet() bool {
316318
return so.LimitFile != 0
317319
}
318320

319-
// IsProcLimitSet return true if processes limit is set
321+
// IsProcLimitSet returns true if processes limit is set
320322
func (so *ServiceOptions) IsProcLimitSet() bool {
321323
return so.LimitProc != 0
322324
}
323325

324-
// IsKillSignalSet return true if custom kill signal set
326+
// IsMemlockLimitSet returns true if max memory limit is set
327+
func (so *ServiceOptions) IsMemlockLimitSet() bool {
328+
return so.LimitMemlock != 0
329+
}
330+
331+
// IsKillSignalSet returns true if custom kill signal set
325332
func (so *ServiceOptions) IsKillSignalSet() bool {
326333
return so.KillSignal != ""
327334
}
328335

329-
// IsKillModeSet return true if custom kill mode set
336+
// IsKillModeSet returns true if custom kill mode set
330337
func (so *ServiceOptions) IsKillModeSet() bool {
331338
return so.KillMode != ""
332339
}
333340

334-
// IsReloadSignalSet return true if custom reload signal set
341+
// IsReloadSignalSet returns true if custom reload signal set
335342
func (so *ServiceOptions) IsReloadSignalSet() bool {
336343
return so.ReloadSignal != ""
337344
}
338345

339-
// IsResourcesSet return true if resources limits are set
346+
// IsResourcesSet returns true if resources limits are set
340347
func (so *ServiceOptions) IsResourcesSet() bool {
341348
return so.Resources != nil
342349
}
343350

344-
// EnvString return environment variables as string
351+
// EnvString returns environment variables as string
345352
func (so *ServiceOptions) EnvString() string {
346353
if len(so.Env) == 0 {
347354
return ""
@@ -491,6 +498,14 @@ func mergeServiceOptions(dst, src *ServiceOptions) {
491498
if dst.LimitProc == 0 {
492499
dst.LimitProc = src.LimitProc
493500
}
501+
502+
if dst.LimitProc == 0 {
503+
dst.LimitProc = src.LimitProc
504+
}
505+
506+
if dst.LimitMemlock == 0 {
507+
dst.LimitMemlock = src.LimitMemlock
508+
}
494509
}
495510

496511
// configureDefaults set options default values

0 commit comments

Comments
 (0)