Skip to content

Commit f10892d

Browse files
authored
add postrm script to deb and rpm packages (#4334)
1 parent ab30195 commit f10892d

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: feature
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: add postrm script to deb and rpm packages
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
19+
#description:
20+
21+
# Affected component; a word indicating the component this changeset affects.
22+
component:
23+
24+
# PR URL; optional; the PR number that added the changeset.
25+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
26+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
27+
# Please provide it if you are adding a fragment for a different PR.
28+
#pr: https://github.com/owner/repo/1234
29+
30+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
31+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
32+
#issue: https://github.com/owner/repo/1234

dev-tools/mage/pkgtypes.go

+9
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ type PackageSpec struct {
9292
Description string `yaml:"description,omitempty"`
9393
PreInstallScript string `yaml:"pre_install_script,omitempty"`
9494
PostInstallScript string `yaml:"post_install_script,omitempty"`
95+
PostRmScript string `yaml:"post_rm_script,omitempty"`
9596
Files map[string]PackageFile `yaml:"files"`
9697
Qualifier string `yaml:"qualifier,omitempty"` // Optional
9798
OutputFile string `yaml:"output_file,omitempty"` // Optional
@@ -101,6 +102,7 @@ type PackageSpec struct {
101102
packageDir string
102103
localPreInstallScript string
103104
localPostInstallScript string
105+
localPostRmScript string
104106
}
105107

106108
// PackageFile represents a file or directory within a package.
@@ -390,6 +392,7 @@ func (s PackageSpec) Evaluate(args ...map[string]interface{}) PackageSpec {
390392
s.Description = mustExpand(s.Description)
391393
s.PreInstallScript = mustExpand(s.PreInstallScript)
392394
s.PostInstallScript = mustExpand(s.PostInstallScript)
395+
s.PostRmScript = mustExpand(s.PostRmScript)
393396
s.OutputFile = mustExpand(s.OutputFile)
394397

395398
if s.ServiceName == "" {
@@ -456,6 +459,9 @@ func (s PackageSpec) Evaluate(args ...map[string]interface{}) PackageSpec {
456459
if err := copyInstallScript(s, s.PostInstallScript, &s.localPostInstallScript); err != nil {
457460
panic(err)
458461
}
462+
if err := copyInstallScript(s, s.PostRmScript, &s.localPostRmScript); err != nil {
463+
panic(err)
464+
}
459465

460466
return s
461467
}
@@ -776,6 +782,9 @@ func runFPM(spec PackageSpec, packageType PackageType) error {
776782
if spec.localPostInstallScript != "" {
777783
args = append(args, "--after-install", spec.localPostInstallScript)
778784
}
785+
if spec.localPostRmScript != "" {
786+
args = append(args, "--after-remove", spec.localPostRmScript)
787+
}
779788
for _, pf := range spec.Files {
780789
if pf.Config {
781790
args = append(args, "--config-files", pf.Target)

dev-tools/packaging/packages.yml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ shared:
2121
- &deb_rpm_agent_spec
2222
<<: *common
2323
post_install_script: '{{ elastic_beats_dir }}/dev-tools/packaging/templates/linux/postinstall.sh.tmpl'
24+
post_rm_script: '{{ elastic_beats_dir }}/dev-tools/packaging/templates/linux/postrm.sh.tmpl'
2425
files:
2526
/usr/share/{{.BeatName}}/LICENSE.txt:
2627
source: '{{ repo.RootDir }}/LICENSE.txt'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
symlink="/usr/share/elastic-agent/bin/elastic-agent"
6+
7+
case "$1" in
8+
purge)
9+
rm -rf /var/lib/elastic-agent /var/log/elastic-agent /etc/elastic-agent
10+
;;
11+
12+
# 0 is for rpm uninstall
13+
upgrade|remove|failed-upgrade|abort-install|abort-upgrade|disappear|0)
14+
if systemctl --quiet is-active elastic-agent; then
15+
echo "stopping elastic-agent"
16+
systemctl --quiet stop elastic-agent
17+
fi
18+
# delete symlink if exists
19+
if test -L "$symlink"; then
20+
echo "found symlink $symlink, unlink"
21+
unlink "$symlink"
22+
fi
23+
;;
24+
*)
25+
;;
26+
esac
27+
28+
echo "systemd daemon-reload"
29+
systemctl daemon-reload 2> /dev/null
30+
exit 0

0 commit comments

Comments
 (0)