Merge pull request #450 from unpoller/fix-nfpm-install-process
nfpm tips to fix this for systemd systems
This commit is contained in:
		
						commit
						b7280a8625
					
				|  | @ -286,7 +286,7 @@ nfpms: | ||||||
|        |        | ||||||
|       # systemd service |       # systemd service | ||||||
|       - src: init/systemd/unpoller.service |       - src: init/systemd/unpoller.service | ||||||
|         dst: /etc/systemd/service/unpoller.service |         dst: /etc/systemd/system/unpoller.service | ||||||
|         type: config |         type: config | ||||||
|        |        | ||||||
|       # freebsd rc service |       # freebsd rc service | ||||||
|  | @ -327,8 +327,9 @@ nfpms: | ||||||
|        |        | ||||||
|     # signing |     # signing | ||||||
|     scripts: |     scripts: | ||||||
|       postinstall: "scripts/after-install.sh" |       postinstall: "scripts/post-install.sh" | ||||||
|       preremove: "scripts/before-remove.sh" |       preremove: "scripts/pre-remove.sh" | ||||||
|  |       postremove: "scripts/post-remove.sh" | ||||||
| 
 | 
 | ||||||
| signs: | signs: | ||||||
|   - id: default |   - id: default | ||||||
|  |  | ||||||
|  | @ -1,29 +0,0 @@ | ||||||
| #!/bin/sh |  | ||||||
| 
 |  | ||||||
| # This file is used by deb, rpm and BSD packages. |  | ||||||
| # FPM adds this as the after-install script. |  | ||||||
| # Edit this file as needed for your application. |  | ||||||
| # This file is only installed if FORMULA is set to service. |  | ||||||
| 
 |  | ||||||
| OS="$(uname -s)" |  | ||||||
| 
 |  | ||||||
| if [ "${OS}" = "Linux" ]; then |  | ||||||
|   # Make a user and group for this app, but only if it does not already exist. |  | ||||||
|   id unpoller >/dev/null 2>&1  || \ |  | ||||||
|     useradd --system --user-group --no-create-home --home-dir /tmp --shell /bin/false unpoller |  | ||||||
| elif [ "${OS}" = "OpenBSD" ]; then |  | ||||||
|   id unpoller >/dev/null 2>&1  || \ |  | ||||||
|     useradd  -g =uid -d /tmp -s /bin/false unpoller |  | ||||||
| elif [ "${OS}" = "FreeBSD" ]; then |  | ||||||
|   id unpoller >/dev/null 2>&1  || \ |  | ||||||
|     pw useradd unpoller -d /tmp -w no -s /bin/false |  | ||||||
| else |  | ||||||
|   echo "Unknown OS: ${OS}, please add system user unpoller manually." |  | ||||||
| fi |  | ||||||
| 
 |  | ||||||
| if [ -x "/bin/systemctl" ]; then |  | ||||||
|   # Reload and restart - this starts the application as user nobody. |  | ||||||
|   /bin/systemctl daemon-reload |  | ||||||
|   /bin/systemctl enable unpoller |  | ||||||
|   /bin/systemctl restart unpoller |  | ||||||
| fi |  | ||||||
|  | @ -1,17 +0,0 @@ | ||||||
| #!/bin/bash |  | ||||||
| 
 |  | ||||||
| # This file is used by rpm and deb packages. FPM use. |  | ||||||
| # Edit this file as needed for your application. |  | ||||||
| # This file is only installed if FORMULA is set to service. |  | ||||||
| 
 |  | ||||||
| if [ "$1" = "upgrade" ] || [ "$1" = "1" ] ; then |  | ||||||
|   exit 0 |  | ||||||
| fi |  | ||||||
| 
 |  | ||||||
| if [ -x "/bin/systemctl" ]; then |  | ||||||
|   /bin/systemctl stop unpoller |  | ||||||
|   /bin/systemctl disable unpoller |  | ||||||
| elif [ -x /usr/sbin/service ]; then |  | ||||||
|   /usr/sbin/service unpoller stop |  | ||||||
|   /usr/sbin/service unpoller disable |  | ||||||
| fi |  | ||||||
|  | @ -0,0 +1,100 @@ | ||||||
|  | #!/bin/sh | ||||||
|  | 
 | ||||||
|  | # Step 1, decide if we should use systemd or init/upstart | ||||||
|  | use_systemctl="True" | ||||||
|  | systemd_version=0 | ||||||
|  | if ! command -V systemctl >/dev/null 2>&1; then | ||||||
|  |   use_systemctl="False" | ||||||
|  | else | ||||||
|  |     systemd_version=$(systemctl --version | head -1 | sed 's/systemd //g' | sed 's/ .*//') | ||||||
|  | fi | ||||||
|  | 
 | ||||||
|  | cleanup() { | ||||||
|  |     # This is where you remove files that were not needed on this platform / system | ||||||
|  |     if [ "${use_systemctl}" = "False" ]; then | ||||||
|  |         rm -f /etc/systemd/system/unpoller.service | ||||||
|  |     else | ||||||
|  |         rm -f /etc/chkconfig/unpoller | ||||||
|  |         rm -f /etc/init.d/unpoller | ||||||
|  |     fi | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | OS="$(uname -s)" | ||||||
|  | 
 | ||||||
|  | cleanInstall() { | ||||||
|  |     printf "\033[32m Post Install of an clean install\033[0m\n" | ||||||
|  |     # Step 3 (clean install), enable the service in the proper way for this platform | ||||||
|  |      | ||||||
|  | 
 | ||||||
|  |     if [ "${OS}" = "Linux" ]; then | ||||||
|  |         # Make a user and group for this app, but only if it does not already exist. | ||||||
|  |         id unpoller >/dev/null 2>&1  || \ | ||||||
|  |             useradd --system --user-group --no-create-home --home-dir /tmp --shell /bin/false unpoller | ||||||
|  |     elif [ "${OS}" = "OpenBSD" ]; then | ||||||
|  |         id unpoller >/dev/null 2>&1  || \ | ||||||
|  |             useradd  -g =uid -d /tmp -s /bin/false unpoller | ||||||
|  |     elif [ "${OS}" = "FreeBSD" ]; then | ||||||
|  |         id unpoller >/dev/null 2>&1  || \ | ||||||
|  |             pw useradd unpoller -d /tmp -w no -s /bin/false | ||||||
|  |     else | ||||||
|  |         echo "Unknown OS: ${OS}, please add system user unpoller manually." | ||||||
|  |     fi | ||||||
|  | 
 | ||||||
|  |     if [ "${use_systemctl}" = "False" ]; then | ||||||
|  |         if command -V chkconfig >/dev/null 2>&1; then | ||||||
|  |           chkconfig --add unpoller | ||||||
|  |         fi | ||||||
|  | 
 | ||||||
|  |         service unpoller restart ||: | ||||||
|  |     else | ||||||
|  |         # rhel/centos7 cannot use ExecStartPre=+ to specify the pre start should be run as root | ||||||
|  |         # even if you want your service to run as non root. | ||||||
|  |         if [] "${systemd_version}" -lt 231 ]; then | ||||||
|  |             printf "\033[31m systemd version %s is less then 231, fixing the service file \033[0m\n" "${systemd_version}" | ||||||
|  |             sed -i "s/=+/=/g" /etc/systemd/system/unpoller.service | ||||||
|  |         fi | ||||||
|  |         printf "\033[32m Reload the service unit from disk\033[0m\n" | ||||||
|  |         systemctl daemon-reload ||: | ||||||
|  |         printf "\033[32m Unmask the service\033[0m\n" | ||||||
|  |         systemctl unmask unpoller ||: | ||||||
|  |         printf "\033[32m Set the preset flag for the service unit\033[0m\n" | ||||||
|  |         systemctl preset unpoller ||: | ||||||
|  |         printf "\033[32m Set the enabled flag for the service unit\033[0m\n" | ||||||
|  |         systemctl enable unpoller ||: | ||||||
|  |         systemctl restart unpoller ||: | ||||||
|  |     fi | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | upgrade() { | ||||||
|  |     printf "\033[32m Post Install of an upgrade\033[0m\n" | ||||||
|  |     # Step 3(upgrade), do what you need | ||||||
|  |      | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | # Step 2, check if this is a clean install or an upgrade | ||||||
|  | action="$1" | ||||||
|  | if  [ "$1" = "configure" ] && [ -z "$2" ]; then | ||||||
|  |   # Alpine linux does not pass args, and deb passes $1=configure | ||||||
|  |   action="install" | ||||||
|  | elif [ "$1" = "configure" ] && [ -n "$2" ]; then | ||||||
|  |     # deb passes $1=configure $2=<current version> | ||||||
|  |     action="upgrade" | ||||||
|  | fi | ||||||
|  | 
 | ||||||
|  | case "$action" in | ||||||
|  |   "1" | "install") | ||||||
|  |     cleanInstall | ||||||
|  |     ;; | ||||||
|  |   "2" | "upgrade") | ||||||
|  |     printf "\033[32m Post Install of an upgrade\033[0m\n" | ||||||
|  |     upgrade | ||||||
|  |     ;; | ||||||
|  |   *) | ||||||
|  |     # $1 == version being installed | ||||||
|  |     printf "\033[32m Alpine\033[0m" | ||||||
|  |     cleanInstall | ||||||
|  |     ;; | ||||||
|  | esac | ||||||
|  | 
 | ||||||
|  | # Step 4, clean up unused files, yes you get a warning when you remove the package, but that is ok. | ||||||
|  | cleanup | ||||||
|  | @ -0,0 +1,45 @@ | ||||||
|  | #!/bin/sh | ||||||
|  | 
 | ||||||
|  | # Step 1, decide if we should use systemd or init/upstart | ||||||
|  | use_systemctl="True" | ||||||
|  | systemd_version=0 | ||||||
|  | if ! command -V systemctl >/dev/null 2>&1; then | ||||||
|  |   use_systemctl="False" | ||||||
|  | else | ||||||
|  |     systemd_version=$(systemctl --version | head -1 | sed 's/systemd //g') | ||||||
|  | fi | ||||||
|  | 
 | ||||||
|  | remove() { | ||||||
|  |     printf "\033[32m Post Remove of a normal remove\033[0m\n" | ||||||
|  |     echo "Remove" > /tmp/postremove-proof | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | purge() { | ||||||
|  |     printf "\033[32m Post Remove purge, deb only\033[0m\n" | ||||||
|  |     echo "Purge" > /tmp/postremove-proof | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | upgrade() { | ||||||
|  |     printf "\033[32m Post Remove of an upgrade\033[0m\n" | ||||||
|  |     echo "Upgrade" > /tmp/postremove-proof | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | echo "$@" | ||||||
|  | 
 | ||||||
|  | action="$1" | ||||||
|  | 
 | ||||||
|  | case "$action" in | ||||||
|  |   "0" | "remove") | ||||||
|  |     remove | ||||||
|  |     ;; | ||||||
|  |   "1" | "upgrade") | ||||||
|  |     upgrade | ||||||
|  |     ;; | ||||||
|  |   "purge") | ||||||
|  |     purge | ||||||
|  |     ;; | ||||||
|  |   *) | ||||||
|  |     printf "\033[32m Alpine\033[0m" | ||||||
|  |     remove | ||||||
|  |     ;; | ||||||
|  | esac | ||||||
|  | @ -0,0 +1,22 @@ | ||||||
|  | #!/bin/bash | ||||||
|  | 
 | ||||||
|  | # Step 1, decide if we should use systemd or init/upstart | ||||||
|  | use_systemctl="True" | ||||||
|  | systemd_version=0 | ||||||
|  | if ! command -V systemctl >/dev/null 2>&1; then | ||||||
|  |   use_systemctl="False" | ||||||
|  | else | ||||||
|  |     systemd_version=$(systemctl --version | head -1 | sed 's/systemd //g') | ||||||
|  | fi | ||||||
|  | 
 | ||||||
|  | if [ "$1" = "upgrade" ] || [ "$1" = "1" ] ; then | ||||||
|  |   exit 0 | ||||||
|  | fi | ||||||
|  | 
 | ||||||
|  | if [ "${use_systemctl}" = "False" ]; then | ||||||
|  |   service unpoller stop | ||||||
|  |   service unpoller disable | ||||||
|  | else | ||||||
|  |   systemctl stop unpoller | ||||||
|  |   systemctl disable unpoller | ||||||
|  | fi | ||||||
		Loading…
	
		Reference in New Issue