ports/146970: net/csync2 - fix rc.d script error, update and take maintainership.

Alexey V.Degtyarev alexey at renatasystems.org
Tue May 25 15:50:01 UTC 2010


>Number:         146970
>Category:       ports
>Synopsis:       net/csync2 - fix rc.d script error, update and take maintainership.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 25 15:50:00 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     Alexey V. Degtyarev
>Release:        FreeBSD 8.0-RELEASE amd64
>Organization:
>Environment:
System: FreeBSD renatasystems.org 8.0-RELEASE FreeBSD 8.0-RELEASE #0: Sat Nov 21 15:02:08 UTC 2009 root at mason.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64


	
>Description:
	
1. Fix the error while csync2_stop() in csync2 rc.d script causing error
message to be printed out.

2. Update csync2 rc.d script: 
  2.1 Use daemon(8) utility to daemonize the server;
  2.2 Add $csync2_logfile tune to select file where to log (instead of stdout);
  2.3 Add $csync2_flags, $csync2_cfg tunes;
  2.4 Print warning if no PSK keys found and server is starting up;
  2.5 Minor code cleanups to suit the current rc.subr style;

3. Do not install csync2-compare script as it written in bash and probably not
commonly used (actually it not worked before now by default); The OPTION
available now to install it and use.

4. Generate RSA certificate at first time install unless already exists, as it
recommended by original documentation[1].

5. Create missing necessary to run directories (/var/db/csync2,
/var/backups/csync2) on fresh install.

6. Take the maintainership.

[1] http://oss.linbit.com/csync2/paper.pdf

>How-To-Repeat:
	
>Fix:

	

--- csync2-1.34_8.patch begins here ---
diff -uNr net/csync2.orig/Makefile net/csync2/Makefile
--- net/csync2.orig/Makefile	2010-05-16 17:46:22.000000000 +0000
+++ net/csync2/Makefile	2010-05-25 14:58:24.000000000 +0000
@@ -7,12 +7,12 @@
 
 PORTNAME=	csync2
 PORTVERSION=	1.34
-PORTREVISION=	7
+PORTREVISION=	8
 CATEGORIES=	net
 MASTER_SITES=	http://oss.linbit.com/csync2/ \
 		http://people.freebsd.org/~aaron/distfiles/
 
-MAINTAINER=	ports at FreeBSD.org
+MAINTAINER=	alexey at renatasystems.org
 COMMENT=	A cluster synchronization tool
 
 LIB_DEPENDS=	rsync.1:${PORTSDIR}/net/librsync \
@@ -22,21 +22,37 @@
 		gcrypt.16:${PORTSDIR}/security/libgcrypt \
 		gpg-error.0:${PORTSDIR}/security/libgpg-error
 
-MAN1=	csync2.1
+OPTIONS=	CSYNC2_COMPARE "Install csync2-compare script" off
+
+.include <bsd.port.pre.mk>
+
+MAN1=		csync2.1
 
 GNU_CONFIGURE=	yes
 CONFIGURE_ARGS=	--sysconfdir=${PREFIX}/etc
-CONFIGURE_ENV=	CPPFLAGS="-I${LOCALBASE}/include"
-CONFIGURE_ENV+=	LDFLAGS="-L${LOCALBASE}/lib"
-CONFIGURE_ENV+=	LIBGNUTLS_CONFIG="${LOCALBASE}/bin/pkg-config gnutls"
+CONFIGURE_ENV=	CPPFLAGS="-I${LOCALBASE}/include" \
+		LDFLAGS="-L${LOCALBASE}/lib" \
+		LIBGNUTLS_CONFIG="${LOCALBASE}/bin/pkg-config gnutls"
 
 USE_RC_SUBR=	csync2
 
 PLIST_FILES=	etc/csync2.cfg-dist \
-		sbin/csync2 \
-		sbin/csync2-compare
+		sbin/csync2
+
+.if defined(WITH_CSYNC2_COMPARE)
+RUN_DEPENDS+=	bash>=0:${PORTSDIR}/shells/bash
+PLIST_FILES+=	sbin/csync2-compare
+CSYNC2_COMPARE=	csync2-compare
+.else
+CSYNC2_COMPARE=
+.endif
+
+SUB_FILES=	pkg-install
+
+post-patch:
+	${REINPLACE_CMD} -E "s#%%CSYNC2_COMPARE%%#${CSYNC2_COMPARE}#" ${WRKSRC}/Makefile.in
 
 post-install:
-	@${CAT} ${PKGMESSAGE}
+	@PKG_PREFIX=${PREFIX} ${SH} ${PKGINSTALL} ${PKGNAME} POST-INSTALL
 
-.include <bsd.port.mk>
+.include <bsd.port.post.mk>
diff -uNr net/csync2.orig/files/csync2.in net/csync2/files/csync2.in
--- net/csync2.orig/files/csync2.in	2010-05-14 13:29:55.000000000 +0000
+++ net/csync2/files/csync2.in	2010-05-18 10:27:25.000000000 +0000
@@ -6,6 +6,14 @@
 
 # Add the following line to /etc/rc.conf to enable csync2:
 # csync2_enable="YES"
+#
+# Optional configuration of csync2:
+# csync2_cfg (str):		Path to csync2 main configuration.
+#				Default is %%PREFIX%%/etc/csync2.cfg.
+# csync2_flags (str):		Extra flags passed to csync2 program.
+#				Default to "-ii -v".
+# csync2_logfile (str):		Path to logfile where daemon' output logged to.
+#				Default to "/var/log/csync2.log".
 
 . /etc/rc.subr
 
@@ -13,26 +21,48 @@
 rcvar=${name}_enable
 
 pidfile=/var/run/${name}.pid
-start_cmd="${name}_start"
-stop_cmd="${name}_stop"
+command=%%PREFIX%%/sbin/csync2
+
+start_cmd="csync2_start"
 
 load_rc_config $name
 : ${csync2_enable="NO"}
+: ${csync2_flags="-ii -v"}
+: ${csync2_cfg="%%PREFIX%%/etc/csync2.cfg"}
+: ${csync2_logfile="/var/log/csync2.log"}
+
+required_files="${csync2_cfg}"
 
-csync2_start()
+csync2_check_keys()
 {
-  %%PREFIX%%/sbin/csync2 -ii & echo $! > ${pidfile}
+	[ -f "${csync2_cfg}" ] || return 1
+
+	_key=`grep '^[[:blank:]]*key[[:space:]]\+.\+;\?$' ${csync2_cfg} |\
+		awk '{print($2)}'`
+	[ -n "${_key}" ] || return 1
+	
+	for _file in ${_key}; do
+		_file=${_file%;}
+		[ ! -f "${_file}" ] && \
+		warn "PSK specified but not found, use csync2 -k ${_file} to create it."
+	done
+
+	return 0
 }
-csync2_stop()
-{   
-  if [ -f "${pidfile}" ]; then
-        kill `cat ${pidfile}`
-        wait_for_pid `cat ${pidfile}`
-        rm -f ${pidfile}
-  else 
-        echo "PIDFILE not found: ${pidfile}, ${name} may already be stopped"
-  fi
+
+csync2_start() {
+
+	if [ -z "$rc_fast" -a -n "$rc_pid" ]; then
+		echo 1>&2 "${name} already running? (pid=$rc_pid)."
+		return 1
+	fi
+
+	csync2_check_keys
+
+	check_startmsgs && echo "Starting ${name}."
+
+	/usr/sbin/daemon -p ${pidfile} \
+		${command} ${csync2_flags} >> ${csync2_logfile} 2>&1
 }
 
 run_rc_command "$1"
-
diff -uNr net/csync2.orig/files/patch-Makefile.in net/csync2/files/patch-Makefile.in
--- net/csync2.orig/files/patch-Makefile.in	2008-02-24 00:07:41.000000000 +0000
+++ net/csync2/files/patch-Makefile.in	2010-05-20 10:51:54.000000000 +0000
@@ -1,5 +1,14 @@
---- ./Makefile.in.orig	2007-07-24 14:04:25.000000000 -0700
-+++ ./Makefile.in	2008-01-17 02:39:42.822708243 -0800
+--- Makefile.in.orig	2007-07-24 21:04:25.000000000 +0000
++++ Makefile.in	2010-05-20 10:51:32.000000000 +0000
+@@ -150,7 +150,7 @@
+ target_alias = @target_alias@
+ 
+ sbin_PROGRAMS = csync2
+-sbin_SCRIPTS = csync2-compare
++sbin_SCRIPTS = %%CSYNC2_COMPARE%%
+ man_MANS = csync2.1
+ 
+ csync2_SOURCES = action.c cfgfile_parser.y cfgfile_scanner.l check.c	\
 @@ -168,7 +168,7 @@
  AM_CFLAGS = $(am__append_2) $(am__append_6)
  AM_LDFLAGS = $(am__append_3) $(am__append_7)
diff -uNr net/csync2.orig/files/patch-csync2-compare net/csync2/files/patch-csync2-compare
--- net/csync2.orig/files/patch-csync2-compare	1970-01-01 00:00:00.000000000 +0000
+++ net/csync2/files/patch-csync2-compare	2010-05-20 10:56:07.000000000 +0000
@@ -0,0 +1,8 @@
+--- csync2-compare.orig	2010-05-20 10:55:31.000000000 +0000
++++ csync2-compare	2010-05-20 10:55:50.000000000 +0000
+@@ -1,4 +1,4 @@
+-#!/bin/bash
++#!/usr/local/bin/bash
+ 
+ verbose=0
+ 
diff -uNr net/csync2.orig/files/pkg-install.in net/csync2/files/pkg-install.in
--- net/csync2.orig/files/pkg-install.in	1970-01-01 00:00:00.000000000 +0000
+++ net/csync2/files/pkg-install.in	2010-05-25 15:09:56.000000000 +0000
@@ -0,0 +1,68 @@
+#!/bin/sh
+
+: ${PREFIX:="%%PREFIX%%"}
+: ${CSYNC2_DBDIR:="/var/db/csync2"}
+: ${CSYNC2_BACKUPDIR:="/var/backups/csync2"}
+
+create_cert() {
+
+	_errlog=`mktemp /tmp/.${0##*/}.XXXXX`
+	code=0
+
+	exec 3>&2 2>${_errlog}
+
+	openssl genrsa -out ${PREFIX}/etc/csync2_ssl_key.pem 1024 || code=1
+	yes '' | openssl req -new -key ${PREFIX}/etc/csync2_ssl_key.pem \
+		-out /tmp/csync2_ssl_cert.csr || code=1
+	openssl x509 -req -days 600 -in /tmp/csync2_ssl_cert.csr \
+		-signkey ${PREFIX}/etc/csync2_ssl_key.pem \
+		-out ${PREFIX}/etc/csync2_ssl_cert.pem || code=1
+
+	rm -f /tmp/csync2_ssl_cert.csr
+
+	if [ ${code} -ne 0 ]; then
+		echo "csync2: OpenSSL error occured:"
+		echo
+		cat ${_errlog}
+		echo
+		rm -f ${_errlog}
+		return 1
+	fi
+
+	exec 2>&3
+
+	rm -f ${_errlog}
+
+	chmod 600 ${PREFIX}/etc/csync2_ssl_key.pem \
+		${PREFIX}/etc/csync2_ssl_cert.pem
+
+	echo "csync2: RSA certificate-key pair installed."
+
+	return 0
+}
+
+pre_install() {
+	return 0
+}
+
+post_install() {
+
+	[ -n "${PACKAGE_BUILDING}" ] && return 0
+
+	for _dir in ${CSYNC2_DBDIR} ${CSYNC2_BACKUPDIR}; do
+		[ ! -d ${_dir} ] && mkdir -p -m 700 ${_dir}
+	done
+
+	if [ ! -f ${PREFIX}/etc/csync2_ssl_cert.pem ]; then
+		create_cert || return $?
+	fi
+
+	return 0
+}
+
+[ $# -eq 2 ] || exit 0
+
+case $2 in
+	"PRE-INSTALL") pre_install ;;
+	"POST-INSTALL") post_install ;;
+esac
diff -uNr net/csync2.orig/pkg-message net/csync2/pkg-message
--- net/csync2.orig/pkg-message	2007-05-30 18:48:50.000000000 +0000
+++ net/csync2/pkg-message	1970-01-01 00:00:00.000000000 +0000
@@ -1,9 +0,0 @@
-***********************************************************************
-
-There is a fair amount of post installation configuration that must be 
-done before csync2 will work properly.  Please refer to section 3.3 Post 
-Installation in the official documentation found at:
-
-http://www.clifford.at/papers/2005/csync2/paper.pdf
-
-***********************************************************************
--- csync2-1.34_8.patch ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list