Skip to content

Commit

Permalink
Merge pull request #8 from funbox/develop
Browse files Browse the repository at this point in the history
Version 0.7.1
  • Loading branch information
andyone authored Feb 28, 2017
2 parents 8263088 + 209cbfd commit b79aa98
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
// App props
const (
APP = "init-exporter"
VER = "0.7.0"
VER = "0.7.1"
DESC = "Utility for exporting services described by Procfile to init system"
)

Expand Down
5 changes: 4 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.7.0
Version: 0.7.1
Release: 0%{?dist}
Group: Development/Tools
License: MIT
Expand Down Expand Up @@ -105,6 +105,9 @@ rm -rf %{buildroot}
###############################################################################

%changelog
* Thu Feb 23 2017 Anton Novojilov <[email protected]> - 0.7.1-0
- More secure helper output redirection

* Wed Feb 22 2017 Anton Novojilov <[email protected]> - 0.7.0-0
- Fixed bug with export to upstart
- Improved working with default values
Expand Down
14 changes: 7 additions & 7 deletions export/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (s *ExportSuite) TestUpstartExport(c *C) {
" chown service /var/log/test_application/service1.log",
" chgrp service /var/log/test_application/service1.log",
" chmod g+w /var/log/test_application/service1.log",
fmt.Sprintf(" exec sudo -u service /bin/bash %s/test_application-service1.sh >> /srv/service/service1-dir/custom.log >> /var/log/test_application/service1.log 2>&1", helperDir),
fmt.Sprintf(" exec sudo -u service /bin/bash %s/test_application-service1.sh &>>/var/log/test_application/service1.log", helperDir),
"end script", ""},
)

Expand All @@ -175,14 +175,14 @@ func (s *ExportSuite) TestUpstartExport(c *C) {
" chown service /var/log/test_application/service2.log",
" chgrp service /var/log/test_application/service2.log",
" chmod g+w /var/log/test_application/service2.log",
fmt.Sprintf(" exec sudo -u service /bin/bash %s/test_application-service2.sh >> /var/log/test_application/service2.log 2>&1", helperDir),
fmt.Sprintf(" exec sudo -u service /bin/bash %s/test_application-service2.sh &>>/var/log/test_application/service2.log", helperDir),
"end script", ""},
)

c.Assert(service1Helper[4:], DeepEquals,
[]string{
"[[ -r /etc/profile.d/rbenv.sh ]] && source /etc/profile.d/rbenv.sh", "",
"cd /srv/service/service1-dir && exec STAGING=true /bin/echo service1",
"cd /srv/service/service1-dir && exec STAGING=true /bin/echo service1 >>/srv/service/service1-dir/log/service1.log",
""},
)

Expand Down Expand Up @@ -331,7 +331,7 @@ func (s *ExportSuite) TestSystemdExport(c *C) {
"Group=service",
"WorkingDirectory=/srv/service/service1-dir",
"Environment=STAGING=true",
fmt.Sprintf("ExecStart=/bin/bash %s/test_application-service1.sh >> /srv/service/service1-dir/custom.log >> /var/log/test_application/service1.log 2>&1", helperDir),
fmt.Sprintf("ExecStart=/bin/bash %s/test_application-service1.sh &>>/var/log/test_application/service1.log", helperDir),
""},
)

Expand Down Expand Up @@ -362,14 +362,14 @@ func (s *ExportSuite) TestSystemdExport(c *C) {
"Group=service",
"WorkingDirectory=/srv/service/working-dir",
"",
fmt.Sprintf("ExecStart=/bin/bash %s/test_application-service2.sh >> /var/log/test_application/service2.log 2>&1", helperDir),
fmt.Sprintf("ExecStart=/bin/bash %s/test_application-service2.sh &>>/var/log/test_application/service2.log", helperDir),
""},
)

c.Assert(service1Helper[4:], DeepEquals,
[]string{
"[[ -r /etc/profile.d/rbenv.sh ]] && source /etc/profile.d/rbenv.sh", "",
"exec /bin/echo service1",
"exec /bin/echo service1 >>/srv/service/service1-dir/log/service1.log",
""},
)

Expand Down Expand Up @@ -412,7 +412,7 @@ func createTestApp(helperDir, targetDir string) *procfile.Application {
Options: &procfile.ServiceOptions{
Env: map[string]string{"STAGING": "true"},
WorkingDir: "/srv/service/service1-dir",
LogPath: "/srv/service/service1-dir/custom.log",
LogPath: "log/service1.log",
KillTimeout: 10,
Count: 2,
RespawnInterval: 25,
Expand Down
4 changes: 2 additions & 2 deletions export/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const TEMPLATE_SYSTEMD_HELPER = `#!/bin/bash
[[ -r /etc/profile.d/rbenv.sh ]] && source /etc/profile.d/rbenv.sh
exec {{.Service.Cmd}}
exec {{.Service.Cmd}}{{ if .Service.Options.IsCustomLogEnabled }} >>{{.Service.Options.FullLogPath}}{{ end }}
`

// TEMPLATE_SYSTEMD_APP contains default application template
Expand Down Expand Up @@ -85,7 +85,7 @@ User={{.Application.User}}
Group={{.Application.Group}}
WorkingDirectory={{.Service.Options.WorkingDir}}
{{ if .Service.Options.IsEnvSet }}Environment={{.Service.Options.EnvString}}{{ end }}
ExecStart=/bin/bash {{.Service.HelperPath}} {{ if .Service.Options.IsCustomLogEnabled }}>> {{.Service.Options.LogPath}} {{end}}>> /var/log/{{.Application.Name}}/{{.Service.Name}}.log 2>&1
ExecStart=/bin/bash {{.Service.HelperPath}} &>>/var/log/{{.Application.Name}}/{{.Service.Name}}.log
`

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down
4 changes: 2 additions & 2 deletions export/upstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const TEMPLATE_UPSTART_HELPER = `#!/bin/bash
[[ -r /etc/profile.d/rbenv.sh ]] && source /etc/profile.d/rbenv.sh
cd {{.Service.Options.WorkingDir}} && exec {{ if .Service.Options.IsEnvSet }}{{.Service.Options.EnvString}} {{ end }}{{.Service.Cmd}}
cd {{.Service.Options.WorkingDir}} && exec {{ if .Service.Options.IsEnvSet }}{{.Service.Options.EnvString}} {{ end }}{{.Service.Cmd}}{{ if .Service.Options.IsCustomLogEnabled }} >>{{.Service.Options.FullLogPath}}{{ end }}
`

// TEMPLATE_UPSTART_APP contains default application template
Expand Down Expand Up @@ -69,7 +69,7 @@ script
chown {{.Application.User}} /var/log/{{.Application.Name}}/{{.Service.Name}}.log
chgrp {{.Application.Group}} /var/log/{{.Application.Name}}/{{.Service.Name}}.log
chmod g+w /var/log/{{.Application.Name}}/{{.Service.Name}}.log
exec sudo -u {{.Application.User}} /bin/bash {{.Service.HelperPath}} {{ if .Service.Options.IsCustomLogEnabled }}>> {{.Service.Options.LogPath}} {{end}}>> /var/log/{{.Application.Name}}/{{.Service.Name}}.log 2>&1
exec sudo -u {{.Application.User}} /bin/bash {{.Service.HelperPath}} &>>/var/log/{{.Application.Name}}/{{.Service.Name}}.log
end script
`

Expand Down
9 changes: 9 additions & 0 deletions procfile/procfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ func (so *ServiceOptions) EnvString() string {
return strings.Join(clauses, " ")
}

// FullLogPath return absolute path to service log
func (so *ServiceOptions) FullLogPath() string {
if strings.HasPrefix(so.LogPath, "/") {
return so.LogPath
}

return so.WorkingDir + "/" + so.LogPath
}

// ////////////////////////////////////////////////////////////////////////////////// //

// parseV1Procfile parse v1 procfile data
Expand Down
3 changes: 2 additions & 1 deletion procfile/procfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ func (s *ProcfileSuite) TestProcV2Parsing(c *C) {
c.Assert(service.Cmd, Equals, "/usr/bin/tail -F /var/log/messages")
c.Assert(service.Options, NotNil)
c.Assert(service.Options.WorkingDir, Equals, "/srv/projects/my_website/current")
c.Assert(service.Options.LogPath, Equals, "/var/log/messages_copy")
c.Assert(service.Options.LogPath, Equals, "log/my_one_another_tail_cmd.log")
c.Assert(service.Options.FullLogPath(), Equals, "/srv/projects/my_website/current/log/my_one_another_tail_cmd.log")
c.Assert(service.Options.IsCustomLogEnabled(), Equals, true)
c.Assert(service.Options.RespawnCount, Equals, 7)
c.Assert(service.Options.RespawnInterval, Equals, 22)
Expand Down
2 changes: 1 addition & 1 deletion testdata/procfile_v2
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ commands:

my_one_another_tail_cmd:
command: /usr/bin/tail -F /var/log/messages
log: /var/log/messages_copy
log: log/my_one_another_tail_cmd.log

my_multi_tail_cmd:
command: /usr/bin/tail -F /var/log/messages
Expand Down

0 comments on commit b79aa98

Please sign in to comment.