Skip to content

Instantly share code, notes, and snippets.

@smpallen99
Created May 9, 2014 23:17
Show Gist options
  • Save smpallen99/45a6afeb252a0647a62e to your computer and use it in GitHub Desktop.
Save smpallen99/45a6afeb252a0647a62e to your computer and use it in GitHub Desktop.
EXRM release rpm first pass
#!/bin/bash
#
# chkconfig: 345 95 5
# description: The test service script
# process name: test
#
# Author: Steve Pallen
#
# Source function library.
. /etc/init.d/functions
PROG_NAME=test
INSTALL_DIR=/usr/local/test
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
Name: test
Version: 0.0.1
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
echo $RPM_BUILD_ROOT
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/usr/local/%{name}
tar xzf %{SOURCE0} -C %{buildroot}/usr/local/%{name}
tar xzf %{SOURCE1} -C %{buildroot}
%clean
rm -rf $RPM_BUILD_ROOT
%post
# first install - $1 == 1
if [ $1 -eq 1 ]; then
/sbin/chkconfig --add %{name}
/sbin/service %{name} start > /dev/null 2>&1
fi
exit 0
%postun
# last uninstall $1 == 0
if [ "$1" = 0 ]; then
/sbin/service %{name} stop > /dev/null 2>&1
/sbin/chkconfig --del %{test}
fi
exit 0
%files
%defattr(-, root, root, -)
/usr/local/%{name}/*
%defattr(755, root, root, -)
/etc/init.d/%{name}
%changelog
* Fri May 9 2014 Stephen Pallen <steve@example.com> 0.0.1-0
- Initial attempt
@smpallen99
Copy link
Author

First pass at creating a spec file and an init script for the EXRM test project. This first pass is not complete since it does not handle upgrades.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment