Skip to content

Commit

Permalink
feat(tools): add post install (#3866)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux authored Jan 18, 2019
1 parent a49569a commit abc8a3c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tools/debpacker/debpacker.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ func New(w Writer, c Config, out string) *Packer {
}

if c.SystemdServiceConfig.ExecStart == "" {
c.SystemdServiceConfig.ExecStart = "/usr/bin/" + filepath.Base(c.BinaryFile)
if c.BinaryFile != "" {
c.SystemdServiceConfig.ExecStart = "/usr/bin/" + filepath.Base(c.BinaryFile)
}
if c.Command != "" {
c.SystemdServiceConfig.ExecStart = c.Command
}

}

return &Packer{
Expand All @@ -60,6 +66,7 @@ type Config struct {
PackageName string `yaml:"package-name"`
Architecture string `yaml:"architecture"`
BinaryFile string `yaml:"binary-file"`
Command string `yaml:"command,omitempty"`
ConfigurationFiles []string `yaml:"configuration-files,omitempty"`
CopyFiles []string `yaml:"copy-files,omitempty"`
Mkdirs []string `yaml:"mkdirs,omitempty"`
Expand All @@ -81,6 +88,7 @@ type SystemdServiceConfig struct {
WantedBy string `yaml:"wanted-by,omitempty"` //default multi-user.target
Environments map[string]string `yaml:"environments"`
WorkingDirectory string `yaml:"working-directory,omitempty"`
PostInstallCmd string `yaml:"post-install-cmd,omitempty"`
}

// Prepare the debian package config file.
Expand All @@ -94,8 +102,10 @@ func (p Packer) Prepare() error {
return err
}

if err := p.copyBinaryFile(); err != nil {
return err
if p.config.BinaryFile != "" {
if err := p.copyBinaryFile(); err != nil {
return err
}
}

if err := p.copyConfigurationFiles(); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions tools/debpacker/tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ adduser --system --group {{.SystemdServiceConfig.User}}
mkdir -p /var/lib/{{.PackageName}}
chown -R {{.SystemdServiceConfig.User}}:{{.SystemdServiceConfig.User}} /var/lib/{{.PackageName}}
chmod 770 /var/lib/{{.PackageName}}
{{if .SystemdServiceConfig.PostInstallCmd -}}
echo "Service initialization"
{{.SystemdServiceConfig.PostInstallCmd}}
{{end -}}
chmod +x {{.SystemdServiceConfig.ExecStart}}
echo "Service installed"
Expand Down

0 comments on commit abc8a3c

Please sign in to comment.