Skip to content

Commit

Permalink
Merge pull request #158 from nikbyte/master
Browse files Browse the repository at this point in the history
Fixed bugs with processing m4 in fedora init scripts
  • Loading branch information
bogdan-iancu committed Jan 10, 2014
2 parents 934fa69 + 4f10a57 commit 09500ab
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
14 changes: 8 additions & 6 deletions packaging/fedora/opensips.init
Expand Up @@ -21,12 +21,13 @@
. /etc/rc.d/init.d/functions

prog=opensips
oser=/usr/sbin/$prog
opensips=/usr/sbin/$prog
cfgdir="/etc/$prog"
pidfile="/var/run/$prog.pid"
lockfile="/var/lock/subsys/$prog"
configfile="/etc/$prog/$prog.cfg"
m4configfile="/etc/$prog/$prog.m4"
m4archivedir="/etc/$prog/archive"
configfile="$cfgdir/$prog.cfg"
m4configfile="$cfgdir/$prog.m4"
m4archivedir="$cfgdir/archive"
OPTIONS=""
RETVAL=0

Expand All @@ -43,9 +44,10 @@ start() {

# Generate config from M4
if [ -f $m4configfile ]; then
cd "$cfgdir"
m4 -Q $m4configfile >$configfile.tmp
if [ $? != 0 ]; then
log "cannot process m4 macro"
echo -n "cannot process m4 macro" && failure && echo
rm "$configfile.tmp"
return 1
fi
Expand All @@ -65,7 +67,7 @@ start() {

# there is something at end of this output which is needed to
# report proper [ OK ] status in Fedora scripts
daemon $oser -u $prog -g $prog -P $pidfile -f $configfile $OPTIONS 2>/dev/null | tail -1
daemon $opensips -u $prog -g $prog -P $pidfile -f $configfile $OPTIONS 2>/dev/null | tail -1
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch $lockfile
Expand Down
32 changes: 32 additions & 0 deletions packaging/fedora/opensips.m4cfg
@@ -0,0 +1,32 @@
#!/bin/bash

prog=opensips
cfgdir="/etc/$prog"
configfile="$cfgdir/$prog.cfg"
m4configfile="$cfgdir/$prog.m4"
m4archivedir="$cfgdir/archive"

# Generate config from M4
if [ -f $m4configfile ]; then
cd "$cfgdir"
m4 -Q $m4configfile >$configfile.tmp
if [ $? != 0 ]; then
echo "cannot process m4 macro"
rm "$configfile.tmp"
exit 1
fi

[ -e $configfile ] || touch $configfile

# compare configs
if [ `md5sum ${configfile}|awk '{print $1}'` != `md5sum ${configfile}.tmp|awk '{print $1}'` ]; then
mkdir -p "${m4archivedir}"
mv "${configfile}" "${m4archivedir}/${prog}.cfg-`date +%Y%m%d_%H%M%S`"
fi

mv "${configfile}.tmp" "${configfile}"
chown ${prog}:${prog} ${configfile}
chmod 640 ${configfile}
fi

exit 0
2 changes: 1 addition & 1 deletion packaging/fedora/opensips.spec
Expand Up @@ -786,7 +786,7 @@ chown -R %{name}:%{name} %{_sysconfdir}/%{name}
%if 0%{?fedora} > 16
%{_unitdir}/%{name}.service
%{_sysconfdir}/tmpfiles.d/%{name}.conf
%{_sbindir}/opensips-m4cfg
%{_sbindir}/%{name}-m4cfg
%dir %attr(0755, %{name}, %{name}) %{_localstatedir}/run/%{name}
%else
%attr(755,root,root) %{_initrddir}/opensips
Expand Down

0 comments on commit 09500ab

Please sign in to comment.