Skip to content

Commit

Permalink
Merge pull request #37 from funbox/develop
Browse files Browse the repository at this point in the history
Version 0.16.1
  • Loading branch information
andyone authored Oct 13, 2017
2 parents 76e11b7 + 87a4014 commit 303635d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
// App props
const (
APP = "init-exporter"
VER = "0.16.0"
VER = "0.16.1"
DESC = "Utility for exporting services described by Procfile to init system"
)

Expand Down
6 changes: 5 additions & 1 deletion common/init-exporter.spec
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

Summary: Utility for exporting services described by Procfile to init system
Name: init-exporter
Version: 0.16.0
Version: 0.16.1
Release: 0%{?dist}
Group: Development/Tools
License: MIT
Expand Down Expand Up @@ -111,6 +111,10 @@ rm -rf %{buildroot}
###############################################################################

%changelog
* Fri Oct 13 2017 Anton Novojilov <[email protected]> - 0.16.1-0
- Fixed bug with exporting multiple systemd units for command
- Fixed bug with generating Wants clause for systemd unit exceeding LINE_MAX

* Thu Sep 14 2017 Anton Novojilov <[email protected]> - 0.16.0-0
- Improved environment variables parsing in v1

Expand Down
2 changes: 1 addition & 1 deletion export/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (s *ExportSuite) TestSystemdExport(c *C) {
"",
"Description=Unit for test_application application",
"After=multi-user.target",
"Wants=test_application-serviceA.service test_application-serviceB.service",
"Wants=test_application-serviceA1.service test_application-serviceA2.service test_application-serviceB.service",
"",
"[Service]",
"Type=oneshot",
Expand Down
47 changes: 42 additions & 5 deletions export/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package export
// ////////////////////////////////////////////////////////////////////////////////// //

import (
"errors"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -40,7 +42,7 @@ const TEMPLATE_SYSTEMD_APP = `# This unit generated {{.ExportDate}} by init-expo
Description=Unit for {{.Application.Name}} application
After={{.StartLevel}}
Wants={{.Wants}}
{{.Wants}}
[Service]
Type=oneshot
Expand Down Expand Up @@ -123,12 +125,24 @@ func (sp *SystemdProvider) UnitName(name string) string {

// EnableService enable service with given name
func (sp *SystemdProvider) EnableService(appName string) error {
return exec.Run("systemctl", "enable", sp.UnitName(appName))
err := exec.Run("systemctl", "enable", sp.UnitName(appName))

if err != nil {
return errors.New("Can't enable service through systemctl")
}

return nil
}

// DisableService disable service with given name
func (sp *SystemdProvider) DisableService(appName string) error {
return exec.Run("systemctl", "disable", sp.UnitName(appName))
err := exec.Run("systemctl", "disable", sp.UnitName(appName))

if err != nil {
return errors.New("Can't disable service through systemctl")
}

return nil
}

// RenderAppTemplate render unit template data with given app data and return
Expand Down Expand Up @@ -192,10 +206,33 @@ func (sp *SystemdProvider) renderLevel(level int) string {
// renderWantsClause render list of services in application for upstart config
func (sp *SystemdProvider) renderWantsClause(app *procfile.Application) string {
var wants []string
var buffer string

for _, service := range app.Services {
wants = append(wants, sp.UnitName(app.Name+"-"+service.Name))
if service.Options.Count <= 0 {
unitName := sp.UnitName(app.Name+"-"+service.Name) + " "

if len(buffer)+len(unitName) >= 1536 {
wants = append(wants, strings.TrimSpace(buffer))
buffer = ""
}

buffer += unitName
} else {
for i := 1; i <= service.Options.Count; i++ {
unitName := sp.UnitName(app.Name+"-"+service.Name+strconv.Itoa(i)) + " "

if len(buffer)+len(unitName) >= 1536 {
wants = append(wants, "Wants="+strings.TrimSpace(buffer))
buffer = ""
}

buffer += unitName
}
}
}

return strings.Join(wants, " ")
wants = append(wants, "Wants="+strings.TrimSpace(buffer))

return strings.Join(wants, "\n")
}

0 comments on commit 303635d

Please sign in to comment.