Skip to content

Commit

Permalink
feat(packaging): add maintainer scripts to enable the service on inst…
Browse files Browse the repository at this point in the history
…allation (#4)

* feat(packaging): add maintainer scripts to auto start the service on installation

* start service on post installation and stop service on pre-removal
  • Loading branch information
reubenmiller authored Aug 7, 2023
1 parent 058110e commit c8cde94
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/_scripts/postinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

# enable and start services (only if the binary is found)
if command -V tedge-agent >/dev/null 2>&1; then
tedgectl enable tedge-agent
tedgectl start tedge-agent
fi

if command -V tedge-mapper-c8y >/dev/null 2>&1; then
tedgectl enable tedge-mapper-c8y
tedgectl start tedge-mapper-c8y
fi

if command -V c8y-configuration-plugin >/dev/null 2>&1; then
tedgectl enable c8y-configuration-plugin
tedgectl start c8y-configuration-plugin
fi

if command -V c8y-log-plugin >/dev/null 2>&1; then
tedgectl enable c8y-log-plugin
tedgectl start c8y-log-plugin
fi

if command -V c8y-firmware-plugin >/dev/null 2>&1; then
tedgectl enable c8y-firmware-plugin
tedgectl start c8y-firmware-plugin
fi
15 changes: 15 additions & 0 deletions packages/_scripts/preremove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

# disable services (ignore if not found)
tedgectl disable tedge-agent 2>/dev/null ||:
tedgectl disable tedge-mapper-c8y 2>/dev/null ||:
tedgectl disable c8y-configuration-plugin 2>/dev/null ||:
tedgectl disable c8y-log-plugin 2>/dev/null ||:
tedgectl disable c8y-firmware-plugin 2>/dev/null ||:

# stop services (ignore if not found)
tedgectl stop tedge-agent 2>/dev/null ||:
tedgectl stop tedge-mapper-c8y 2>/dev/null ||:
tedgectl stop c8y-configuration-plugin 2>/dev/null ||:
tedgectl stop c8y-log-plugin 2>/dev/null ||:
tedgectl stop c8y-firmware-plugin 2>/dev/null ||:
3 changes: 3 additions & 0 deletions packages/openrc/nfpm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ contents:
dst: /usr/bin/
file_info:
mode: 0755
scripts:
postinstall: ./packages/_scripts/postinstall.sh
preremove: ./packages/_scripts/preremove.sh
3 changes: 3 additions & 0 deletions packages/runit/nfpm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ contents:
dst: /usr/bin/
file_info:
mode: 0755
scripts:
postinstall: ./packages/_scripts/postinstall.sh
preremove: ./packages/_scripts/preremove.sh
3 changes: 3 additions & 0 deletions packages/s6-overlay/nfpm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ contents:
dst: /usr/bin/
file_info:
mode: 0755
scripts:
postinstall: ./packages/_scripts/postinstall.sh
preremove: ./packages/_scripts/preremove.sh
3 changes: 3 additions & 0 deletions packages/sysvinit/nfpm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ contents:
dst: /usr/bin/
file_info:
mode: 0755
scripts:
postinstall: ./packages/_scripts/postinstall.sh
preremove: ./packages/_scripts/preremove.sh

0 comments on commit c8cde94

Please sign in to comment.