Created
May 10, 2014 14:31
-
-
Save smpallen99/06e0c5c024841784cbcd to your computer and use it in GitHub Desktop.
EXRM release rpm with live upgrade
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# chkconfig: 345 95 5 | |
# description: The extest service script | |
# process name: extest | |
# | |
# Author: Steve Pallen | |
# | |
# Source function library. | |
. /etc/init.d/functions | |
PROG_NAME=extest | |
INSTALL_DIR=/usr/local/$PROG_NAME | |
PROG=$INSTALL_DIR/bin/$PROG_NAME | |
RETVAl=0 | |
txtgrn=$(tput setaf 2) | |
txtred=$(tput setaf 1) | |
txtrst=$(tput sgr0) | |
if [ -f /etc/sysconfig/$PROG_NAME ] ; then | |
. /etc/sysconfig/$PROG_NAME | |
fi | |
[ -f $PROG ] || exit 0 | |
message() { | |
if [ $RETVAL -eq 0 ]; then | |
printf "%-45s[${txtgrn} OK ${txtrst}]\n" "$1" | |
else | |
printf "%-45s[${txtred}FAILED${txtrst}]\n" "$1" | |
fi | |
} | |
run() { | |
HOME=$INSTALL_DIR $PROG $1 > /dev/null 2>&1 | |
} | |
start() { | |
#echo -n $"Starting $PROG_NAME: " | |
run start | |
RETVAL=$? | |
message $"Starting $PROG_NAME: " | |
return $RETVAL | |
} | |
stop() { | |
run stop | |
RETVAL=$? | |
message "Stopping $PROG_NAME: " | |
return $RETVAL | |
} | |
restart() { | |
run restart | |
RETVAL=$? | |
message $"Restarting $PROG_NAME: " | |
return $RETVAL | |
} | |
status() { | |
run ping | |
RETVAL=$? | |
echo -n "Status: $PROG_NAME is " | |
if [ $RETVAL -eq 0 ]; then | |
echo "running ..." | |
else | |
echo "stopped" | |
fi | |
return $RETVAL | |
} | |
case "$1" in | |
start) | |
start | |
RETVAL=$? | |
;; | |
stop) | |
stop | |
;; | |
status) | |
status | |
;; | |
restart) | |
restart | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|status|restart}" | |
exit 1 | |
;; | |
esac | |
exit $RETVAL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%define install_dir /usr/local | |
Name: extest | |
Version: 0.0.2 | |
# Up issuing the release is NOT supported due to live upgrades. Please | |
# up issue the Version only | |
Release: 0%{?dist} | |
Summary: Example EXRM Test Project | |
Group: Applications | |
License: GPL | |
URL: https://github.com/bitwalker/exrm | |
Source0: %{name}-%{version}.tar.gz | |
Source1: %{name}-other-%{version}.tar.gz | |
BuildRoot: %{_tmppath}/%{name}-root | |
BuildArchitectures: x86_64 | |
AutoReq: 0 | |
Provides: %{name} | |
%description | |
Some description goes here | |
%install | |
rm -rf $RPM_BUILD_ROOT | |
mkdir -p $RPM_BUILD_ROOT/tmp | |
mkdir -p $RPM_BUILD_ROOT/%{install_dir}/%{name} | |
tar xzf %{SOURCE1} -C %{buildroot} | |
cp %{SOURCE0} %{buildroot}/tmp/ | |
%clean | |
rm -rf $RPM_BUILD_ROOT | |
%post | |
if [ $1 -eq 1 ]; then | |
# new install | |
tar xzf /tmp/%{name}-%{version}.tar.gz -C %{install_dir}/%{name} | |
rm /tmp/%{name}-%{version}.tar.gz | |
/sbin/chkconfig --add %{name} | |
/sbin/service %{name} start > /dev/null 2>&1 | |
else | |
# upgrade | |
mkdir %{install_dir}/%{name}/releases/%{version} | |
mv /tmp/%{name}-%{version}.tar.gz %{install_dir}/%{name}/releases/%{version}/%{name}.tar.gz | |
cd %{install_dir}/%{name} && bin/%{name} upgrade "%{version}" | |
fi | |
exit 0 | |
%preun | |
if [ "$1" = 0 ]; then | |
# package remove | |
/sbin/service %{name} stop > /dev/null 2>&1 | |
/sbin/chkconfig --del %{name} | |
rm -rf /usr/local/%{name} | |
fi | |
exit 0 | |
%files | |
%defattr(-, root, root, -) | |
/tmp/%{name}-%{version}.tar.gz | |
%dir /usr/local/%{name} | |
%defattr(755, root, root, -) | |
/etc/init.d/%{name} | |
%changelog | |
* Sat May 10 2014 Stephen Pallen <[email protected]> 0.0.2-0 | |
- Added support for live upgrades | |
* Fri May 9 2014 Stephen Pallen <[email protected]> 0.0.1-0 | |
- Initial attempt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This version of the spec file and init.d script supports live upgrades. Note that I have renamed the project to extest.
This solution uses the output tar file from Exrm release generation.