diff --git a/cli/cli.go b/cli/cli.go index b513e92..a69fe79 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -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" ) diff --git a/common/init-exporter.spec b/common/init-exporter.spec index 1a049c7..2ca3895 100644 --- a/common/init-exporter.spec +++ b/common/init-exporter.spec @@ -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 @@ -105,6 +105,9 @@ rm -rf %{buildroot} ############################################################################### %changelog +* Thu Feb 23 2017 Anton Novojilov - 0.7.1-0 +- More secure helper output redirection + * Wed Feb 22 2017 Anton Novojilov - 0.7.0-0 - Fixed bug with export to upstart - Improved working with default values diff --git a/export/export_test.go b/export/export_test.go index 503a5ca..c3335f0 100644 --- a/export/export_test.go +++ b/export/export_test.go @@ -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", ""}, ) @@ -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", ""}, ) @@ -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), ""}, ) @@ -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", ""}, ) @@ -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, diff --git a/export/systemd.go b/export/systemd.go index 488b760..5bb3168 100644 --- a/export/systemd.go +++ b/export/systemd.go @@ -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 @@ -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 ` // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/export/upstart.go b/export/upstart.go index dac573b..0d18b62 100644 --- a/export/upstart.go +++ b/export/upstart.go @@ -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 @@ -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 ` diff --git a/procfile/procfile.go b/procfile/procfile.go index cbb714a..b58d0c4 100644 --- a/procfile/procfile.go +++ b/procfile/procfile.go @@ -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 diff --git a/procfile/procfile_test.go b/procfile/procfile_test.go index f9c51dc..efc1756 100644 --- a/procfile/procfile_test.go +++ b/procfile/procfile_test.go @@ -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) diff --git a/testdata/procfile_v2 b/testdata/procfile_v2 index 4907745..32a3626 100644 --- a/testdata/procfile_v2 +++ b/testdata/procfile_v2 @@ -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