Skip to content

Commit

Permalink
add m4 config support for debian distros
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Altmann committed Aug 13, 2013
1 parent b31075d commit 310e195
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
27 changes: 26 additions & 1 deletion packaging/debian-lenny/opensips.init
Expand Up @@ -19,6 +19,9 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/opensips
NAME=opensips
DESC=opensips
CFGFILE=/etc/opensips/opensips.cfg
M4CFGFILE=/etc/opensips/opensips.m4
M4ARCHIVEDIR=/etc/opensips/archive
HOMEDIR=/var/run/opensips
PIDFILE=$HOMEDIR/$NAME.pid
DEFAULTS=/etc/default/opensips
Expand All @@ -28,7 +31,7 @@ RUN_OPENSIPS=no
# otherwise the boot process will just stop
check_fork ()
{
if grep -q "^[[:space:]]*fork[[:space:]]*=[[:space:]]*no.*" /etc/opensips/opensips.cfg; then
if grep -q "^[[:space:]]*fork[[:space:]]*=[[:space:]]*no.*" $CFGFILE; then
echo "Not starting $DESC: fork=no specified in config file; run /etc/init.d/opensips debug instead"
exit 1
fi
Expand Down Expand Up @@ -112,6 +115,28 @@ case "$1" in
check_fork
fi

# Generate config from M4
if [ -f $M4CFGFILE ]; then
m4 -Q $M4CFGFILE >$CFGFILE.tmp
if [ $? != 0 ]; then
echo "Cannot process m4 macro"
rm "$CFGFILE.tmp"
exit 1
fi

[ -e $CFGFILE ] || touch $CFGFILE

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

mv "$CFGFILE.tmp" "$CFGFILE"
chown $USER:$GROUP $CFGFILE
chmod 640 $CFGFILE
fi

echo -n "Starting $DESC: $NAME"
start-stop-daemon --start --quiet --pidfile $PIDFILE \
--exec $DAEMON -- $OPTIONS || echo -n " already running"
Expand Down
27 changes: 26 additions & 1 deletion packaging/debian/opensips.init
Expand Up @@ -19,6 +19,9 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/opensips
NAME=opensips
DESC=opensips
CFGFILE=/etc/opensips/opensips.cfg
M4CFGFILE=/etc/opensips/opensips.m4
M4ARCHIVEDIR=/etc/opensips/archive
HOMEDIR=/var/run/opensips
PIDFILE=$HOMEDIR/$NAME.pid
DEFAULTS=/etc/default/opensips
Expand All @@ -28,7 +31,7 @@ RUN_OPENSIPS=no
# otherwise the boot process will just stop
check_fork ()
{
if grep -q "^[[:space:]]*fork[[:space:]]*=[[:space:]]*no.*" /etc/opensips/opensips.cfg; then
if grep -q "^[[:space:]]*fork[[:space:]]*=[[:space:]]*no.*" $CFGFILE; then
echo "Not starting $DESC: fork=no specified in config file; run /etc/init.d/opensips debug instead"
exit 1
fi
Expand Down Expand Up @@ -119,6 +122,28 @@ case "$1" in
chmod 775 "$HOMEDIR"
chown "$USER:$GROUP" "$HOMEDIR" >/dev/null 2>&1 || true

# Generate config from M4
if [ -f $M4CFGFILE ]; then
m4 -Q $M4CFGFILE >$CFGFILE.tmp
if [ $? != 0 ]; then
echo "Cannot process m4 macro"
rm "$CFGFILE.tmp"
exit 1
fi

[ -e $CFGFILE ] || touch $CFGFILE

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

mv "$CFGFILE.tmp" "$CFGFILE"
chown $USER:$GROUP $CFGFILE
chmod 640 $CFGFILE
fi

echo -n "Starting $DESC: $NAME"
start-stop-daemon --start --quiet --pidfile $PIDFILE \
--exec $DAEMON -- $OPTIONS || echo -n " already running"
Expand Down

0 comments on commit 310e195

Please sign in to comment.