From 9dd0aaaca05026a763333ef15da43f74890a50ad Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Tue, 9 Feb 2010 11:19:01 -0500 Subject: provide initial Debian compatibility for git and git::daemon classes --- files/config/CentOS/git-daemon | 26 ++++++ files/config/CentOS/git-daemon.vhosts | 27 ++++++ files/config/Debian/git-daemon | 22 +++++ files/init.d/CentOS/git-daemon | 75 +++++++++++++++++ files/init.d/Debian/git-daemon | 151 ++++++++++++++++++++++++++++++++++ files/init.d/git-daemon | 75 ----------------- files/sysconfig/git-daemon | 26 ------ files/sysconfig/git-daemon.vhosts | 27 ------ manifests/base.pp | 3 +- manifests/centos.pp | 2 + manifests/daemon.pp | 28 ++----- manifests/daemon/base.pp | 30 +++++++ manifests/daemon/centos.pp | 19 +++++ manifests/daemon/debian.pp | 11 +++ manifests/daemon/disable.pp | 18 ++-- manifests/daemon/vhosts.pp | 10 ++- manifests/debian.pp | 5 ++ manifests/init.pp | 13 ++- 18 files changed, 402 insertions(+), 166 deletions(-) create mode 100644 files/config/CentOS/git-daemon create mode 100644 files/config/CentOS/git-daemon.vhosts create mode 100644 files/config/Debian/git-daemon create mode 100644 files/init.d/CentOS/git-daemon create mode 100644 files/init.d/Debian/git-daemon delete mode 100644 files/init.d/git-daemon delete mode 100644 files/sysconfig/git-daemon delete mode 100644 files/sysconfig/git-daemon.vhosts create mode 100644 manifests/centos.pp create mode 100644 manifests/daemon/base.pp create mode 100644 manifests/daemon/centos.pp create mode 100644 manifests/daemon/debian.pp create mode 100644 manifests/debian.pp diff --git a/files/config/CentOS/git-daemon b/files/config/CentOS/git-daemon new file mode 100644 index 0000000..a9b208c --- /dev/null +++ b/files/config/CentOS/git-daemon @@ -0,0 +1,26 @@ +# git-daemon config file + +# location of the lockfile +#LOCKFILE=/var/lock/subsys/git-daemon + +# which directory to server +#GITDIR=/srv/git + +# do we serve vhosts? +# setting this to yes assumes that you +# have in $GITDIR per vhost to serve +# a subdirectory containing their repos. +# for example: +# - /srv/git/git.example.com +# - /srv/git/git.example.org +#GITVHOST=no + +# the user git-daemon should run with +#GITUSER=nobody + +# options for the daemon +#OPTIONS="--reuseaddr --verbose --detach" + +# location of the daemon +#GITDAEMON=/usr/bin/git-daemon + diff --git a/files/config/CentOS/git-daemon.vhosts b/files/config/CentOS/git-daemon.vhosts new file mode 100644 index 0000000..62bb9d4 --- /dev/null +++ b/files/config/CentOS/git-daemon.vhosts @@ -0,0 +1,27 @@ +# git-daemon config file + +# location of the lockfile +#LOCKFILE=/var/lock/subsys/git-daemon + +# which directory to server +#GITDIR=/srv/git + +# do we serve vhosts? +# setting this to yes assumes that you +# have in $GITDIR per vhost to serve +# a subdirectory containing their repos. +# for example: +# - /srv/git/git.example.com +# - /srv/git/git.example.org +#GITVHOST=no +GITVHOST=yes + +# the user git-daemon should run with +#GITUSER=nobody + +# options for the daemon +#OPTIONS="--reuseaddr --verbose --detach" + +# location of the daemon +#GITDAEMON=/usr/bin/git-daemon + diff --git a/files/config/Debian/git-daemon b/files/config/Debian/git-daemon new file mode 100644 index 0000000..b25e1e7 --- /dev/null +++ b/files/config/Debian/git-daemon @@ -0,0 +1,22 @@ +# Defaults for the git-daemon initscript + +# Set to yes to start git-daemon +RUN=yes + +# Set to the user and group git-daemon should run as +USER=nobody +GROUP=nogroup + +# Set the base path and the directory where the repositories are. +REPOSITORIES="/srv/git" + +# Provide a way to have custom setup. +# +# Note, when ADVANCED_OPTS is defined the REPOSITORIES setting is ignored, +# so take good care to specify exactly what git-daemon have to do. +# +# Here is an example from the man page: +#ADVANCED_OPTS="--verbose --export-all \ +# --interpolated-path=/pub/%IP/%D \ +# /pub/192.168.1.200/software \ +# /pub/10.10.220.23/software" diff --git a/files/init.d/CentOS/git-daemon b/files/init.d/CentOS/git-daemon new file mode 100644 index 0000000..aed2075 --- /dev/null +++ b/files/init.d/CentOS/git-daemon @@ -0,0 +1,75 @@ +#!/bin/bash +# puppet Init script for running the git-daemon +# +# Author: Marcel Haerry +# +# chkconfig: - 98 02 +# +# description: Enables the git-daemon to serve various directories. By default it serves /srv/git +# processname: git-daemon +# config: /etc/sysconfig/git-daemon + +PATH=/usr/bin:/sbin:/bin:/usr/sbin +export PATH + +[ -f /etc/sysconfig/git-daemon ] && . /etc/sysconfig/git-daemon +lockfile=${LOCKFILE-/var/lock/subsys/git-daemon} +gitdir=${GITDIR-/srv/git} +gitvhost=${GITVHOST-no} +user=${GITUSER-nobody} +options=${OPTIONS-"--reuseaddr --verbose --detach"} +gitdaemon=${GITDAEMON-/usr/bin/git-daemon} +RETVAL=0 + +gitoptions="--user=${user} ${options}" +if [ $gitvhost = yes ]; then + gitoptions="${gitoptions} --interpolated-path=${gitdir}/%H/%D" +else + gitoptions="${gitoptions} --base-path=${gitdir}" +fi + +# Source function library. +. /etc/rc.d/init.d/functions + +start() { + echo -n $"Starting git-daemon: " + daemon $gitdaemon $gitoptions + RETVAL=$? + echo + [ $RETVAL = 0 ] && touch ${lockfile} + return $RETVAL +} + +stop() { + echo -n $"Stopping git-daemon: " + killproc $gitdaemon + RETVAL=$? + echo + [ $RETVAL = 0 ] && rm -f ${lockfile} +} + +restart() { + stop + start +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + restart + ;; + status) + status $gitdaemon + RETVAL=$? + ;; + *) + echo $"Usage: $0 {start|stop|status|restart}" + exit 1 +esac + +exit $RETVAL diff --git a/files/init.d/Debian/git-daemon b/files/init.d/Debian/git-daemon new file mode 100644 index 0000000..4edfe4c --- /dev/null +++ b/files/init.d/Debian/git-daemon @@ -0,0 +1,151 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: git-daemon +# Required-Start: $network $remote_fs $syslog +# Required-Stop: $network $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: git-daemon service +# Description: git-daemon makes git repositories available via the git +# protocol. +### END INIT INFO + +# Author: Antonio Ospite +# +# Please remove the "Author" lines above and replace them +# with your own name if you copy and modify this script. + +# Do NOT "set -e" + +# PATH should only include /usr/* if it runs after the mountnfs.sh script +PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/lib/git-core +DESC="git-daemon service" +NAME=git-daemon +DAEMON=/usr/lib/git-core/$NAME +PIDFILE=/var/run/$NAME.pid +SCRIPTNAME=/etc/init.d/$NAME + +# Exit if the package is not installed +[ -x "$DAEMON" ] || exit 0 + +# Fallback options values, we use these when +# the /etc/default/git-daemon file does not exist +RUN=no +USER=git +GROUP=git +REPOSITORIES="/srv/git/" + +# Read configuration variable file if it is present +[ -r /etc/default/$NAME ] && . /etc/default/$NAME + +# If ADVANCED_OPTS is empty, use a default setting +if [ "x$ADVANCED_OPTS" == "x" ]; +then + ADVANCED_OPTS="--base-path=$REPOSITORIES $REPOSITORIES" +fi + +DAEMON_ARGS="--syslog --reuseaddr \ + --user=$USER --group=$GROUP \ + $ADVANCED_OPTS" + + +# Load the VERBOSE setting and other rcS variables +.. /lib/init/vars.sh + +# Define LSB log_* functions. +# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. +.. /lib/lsb/init-functions + +# +# Function that starts the daemon/service +# +do_start() +{ + # Return + # 0 if daemon has been started + # 1 if daemon was already running + # 2 if daemon could not be started + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ + || return 1 + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --background --make-pidfile -- \ + $DAEMON_ARGS \ + || return 2 + + return 0 +} + +# +# Function that stops the daemon/service +# +do_stop() +{ + # Return + # 0 if daemon has been stopped + # 1 if daemon was already stopped + # 2 if daemon could not be stopped + # other if a failure occurred + start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME + RETVAL="$?" + [ "$RETVAL" = 2 ] && return 2 + # Wait for children to finish too if this is a daemon that forks + # and if the daemon is only ever run from this initscript. + # If the above conditions are not satisfied then add some other code + # that waits for the process to drop all resources that could be + # needed by services started subsequently. A last resort is to + # sleep for some time. + start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON + [ "$?" = 2 ] && return 2 + # Many daemons don't delete their pidfiles when they exit. + rm -f $PIDFILE + return "$RETVAL" +} + +case "$1" in + start) + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + do_start + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + stop) + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + do_stop + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + status) + status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + restart|force-reload) + # + # If the "reload" option is implemented then remove the + # 'force-reload' alias + # + log_daemon_msg "Restarting $DESC" "$NAME" + do_stop + case "$?" in + 0|1) + do_start + case "$?" in + 0) log_end_msg 0 ;; + 1) log_end_msg 1 ;; # Old process is still running + *) log_end_msg 1 ;; # Failed to start + esac + ;; + *) + # Failed to stop + log_end_msg 1 + ;; + esac + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 + exit 3 + ;; +esac + +: diff --git a/files/init.d/git-daemon b/files/init.d/git-daemon deleted file mode 100644 index aed2075..0000000 --- a/files/init.d/git-daemon +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/bash -# puppet Init script for running the git-daemon -# -# Author: Marcel Haerry -# -# chkconfig: - 98 02 -# -# description: Enables the git-daemon to serve various directories. By default it serves /srv/git -# processname: git-daemon -# config: /etc/sysconfig/git-daemon - -PATH=/usr/bin:/sbin:/bin:/usr/sbin -export PATH - -[ -f /etc/sysconfig/git-daemon ] && . /etc/sysconfig/git-daemon -lockfile=${LOCKFILE-/var/lock/subsys/git-daemon} -gitdir=${GITDIR-/srv/git} -gitvhost=${GITVHOST-no} -user=${GITUSER-nobody} -options=${OPTIONS-"--reuseaddr --verbose --detach"} -gitdaemon=${GITDAEMON-/usr/bin/git-daemon} -RETVAL=0 - -gitoptions="--user=${user} ${options}" -if [ $gitvhost = yes ]; then - gitoptions="${gitoptions} --interpolated-path=${gitdir}/%H/%D" -else - gitoptions="${gitoptions} --base-path=${gitdir}" -fi - -# Source function library. -. /etc/rc.d/init.d/functions - -start() { - echo -n $"Starting git-daemon: " - daemon $gitdaemon $gitoptions - RETVAL=$? - echo - [ $RETVAL = 0 ] && touch ${lockfile} - return $RETVAL -} - -stop() { - echo -n $"Stopping git-daemon: " - killproc $gitdaemon - RETVAL=$? - echo - [ $RETVAL = 0 ] && rm -f ${lockfile} -} - -restart() { - stop - start -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - restart) - restart - ;; - status) - status $gitdaemon - RETVAL=$? - ;; - *) - echo $"Usage: $0 {start|stop|status|restart}" - exit 1 -esac - -exit $RETVAL diff --git a/files/sysconfig/git-daemon b/files/sysconfig/git-daemon deleted file mode 100644 index a9b208c..0000000 --- a/files/sysconfig/git-daemon +++ /dev/null @@ -1,26 +0,0 @@ -# git-daemon config file - -# location of the lockfile -#LOCKFILE=/var/lock/subsys/git-daemon - -# which directory to server -#GITDIR=/srv/git - -# do we serve vhosts? -# setting this to yes assumes that you -# have in $GITDIR per vhost to serve -# a subdirectory containing their repos. -# for example: -# - /srv/git/git.example.com -# - /srv/git/git.example.org -#GITVHOST=no - -# the user git-daemon should run with -#GITUSER=nobody - -# options for the daemon -#OPTIONS="--reuseaddr --verbose --detach" - -# location of the daemon -#GITDAEMON=/usr/bin/git-daemon - diff --git a/files/sysconfig/git-daemon.vhosts b/files/sysconfig/git-daemon.vhosts deleted file mode 100644 index 62bb9d4..0000000 --- a/files/sysconfig/git-daemon.vhosts +++ /dev/null @@ -1,27 +0,0 @@ -# git-daemon config file - -# location of the lockfile -#LOCKFILE=/var/lock/subsys/git-daemon - -# which directory to server -#GITDIR=/srv/git - -# do we serve vhosts? -# setting this to yes assumes that you -# have in $GITDIR per vhost to serve -# a subdirectory containing their repos. -# for example: -# - /srv/git/git.example.com -# - /srv/git/git.example.org -#GITVHOST=no -GITVHOST=yes - -# the user git-daemon should run with -#GITUSER=nobody - -# options for the daemon -#OPTIONS="--reuseaddr --verbose --detach" - -# location of the daemon -#GITDAEMON=/usr/bin/git-daemon - diff --git a/manifests/base.pp b/manifests/base.pp index 06742a7..ca89aac 100644 --- a/manifests/base.pp +++ b/manifests/base.pp @@ -1,5 +1,6 @@ class git::base { - package{'git': + package { 'git': ensure => present, + alias => 'git, } } diff --git a/manifests/centos.pp b/manifests/centos.pp new file mode 100644 index 0000000..9634475 --- /dev/null +++ b/manifests/centos.pp @@ -0,0 +1,2 @@ +class git::centos inherits git::base { +} diff --git a/manifests/daemon.pp b/manifests/daemon.pp index 0d22adf..33c0a26 100644 --- a/manifests/daemon.pp +++ b/manifests/daemon.pp @@ -1,32 +1,14 @@ class git::daemon { + include git - package{'git-daemon': - ensure => installed, - require => Package['git'], - } - file{'/etc/init.d/git-daemon': - source => [ "puppet://$server/modules/site-git/init.d/${fqdn}/git-daemon", - "puppet://$server/modules/site-git/init.d/git-daemon", - "puppet://$server/modules/git/init.d/git-daemon" ], - require => Package['git-daemon'], - owner => root, group => 0, mode => 0755; - } - file{'/etc/sysconfig/git-daemon': - source => [ "puppet://$server/modules/site-git/sysconfig/${fqdn}/git-daemon", - "puppet://$server/modules/site-git/sysconfig/git-daemon", - "puppet://$server/modules/git/sysconfig/git-daemon" ], - require => Package['git-daemon'], - owner => root, group => 0, mode => 0644; - } - service{'git-daemon': - ensure => running, - enable => true, - hasstatus => true, - require => [ File['/etc/sysconfig/git-daemon'], File['/etc/init.d/git-daemon'] ], + case $operatingsystem { + debian: { include git::daemon::debian } + centos: { include git::daemon::centos } } if $use_shorewall { include shorewall::rules::gitdaemon } + } diff --git a/manifests/daemon/base.pp b/manifests/daemon/base.pp new file mode 100644 index 0000000..5dd16d6 --- /dev/null +++ b/manifests/daemon/base.pp @@ -0,0 +1,30 @@ +class git::daemon::base { + + file { 'git-daemon_initscript': + source => [ "puppet://$server/modules/site-git/init.d/${fqdn}/git-daemon", + "puppet://$server/modules/site-git/init.d/${operatingsystem}/git-daemon", + "puppet://$server/modules/site-git/init.d/git-daemon", + "puppet://$server/modules/git/init.d/${operatingsystem}/git-daemon", + "puppet://$server/modules/git/init.d/git-daemon" ], + require => Package['git'], + owner => root, group => 0, mode => 0755; + } + + file { 'git-daemon_config': + source => [ "puppet://$server/modules/site-git/config/${fqdn}/git-daemon", + "puppet://$server/modules/site-git/config/${operatingsystem}/git-daemon", + "puppet://$server/modules/site-git/config/git-daemon", + "puppet://$server/modules/git/config/${operatingsystem}/git-daemon", + "puppet://$server/modules/git/config/git-daemon" ], + require => Package['git'], + owner => root, group => 0, mode => 0644; + } + + service { 'git-daemon': + ensure => running, + enable => true, + hasstatus => true, + require => [ File['git-daemon_initscript'], File['git-daemon_config'] ], + } + +} diff --git a/manifests/daemon/centos.pp b/manifests/daemon/centos.pp new file mode 100644 index 0000000..940ae52 --- /dev/null +++ b/manifests/daemon/centos.pp @@ -0,0 +1,19 @@ +class git::daemon::centos inherits git::daemon::base { + + package { 'git-daemon': + ensure => installed, + require => Package['git'], + alias => 'git-daemon', + } + + File { 'git-daemon_initscript': + path => '/etc/init.d/git-daemon', + require +> Package['git-daemon'], + } + + File { 'git-daemon_config': + path => '/etc/init.d/git-daemon', + require +> Package['git-daemon'], + } + +} diff --git a/manifests/daemon/debian.pp b/manifests/daemon/debian.pp new file mode 100644 index 0000000..758c9fe --- /dev/null +++ b/manifests/daemon/debian.pp @@ -0,0 +1,11 @@ +class git::daemon::debian inherits git::daemon::base { + + File { 'git-daemon_initscript': + path => '/etc/init.d/git-daemon', + } + + File { 'git-daemon_config': + path => '/etc/default/git-daemon', + } + +} diff --git a/manifests/daemon/disable.pp b/manifests/daemon/disable.pp index 6e01268..fe0c9b0 100644 --- a/manifests/daemon/disable.pp +++ b/manifests/daemon/disable.pp @@ -1,23 +1,29 @@ class git::daemon::disable inherits git::daemon { - Package['git-daemon']{ - ensure => absent, + + if defined(Package['git-daemon']) { + Package['git-daemon'] { + ensure => absent, + } } - File['/etc/init.d/git-daemon']{ + File['git-daemon_initscript']{ ensure => absent, } - File['/etc/sysconfig/git-daemon']{ + + File['git-daemon_config'] { ensure => absent, } - Service['git-daemon']{ + + Service['git-daemon'] { ensure => stopped, enable => false, require => undef, - before => File['/etc/init.d/git-daemon'], + before => File['git-daemon_initscript'], } if $use_shorewall { include shorewall::rules::gitdaemon::absent } + } diff --git a/manifests/daemon/vhosts.pp b/manifests/daemon/vhosts.pp index 4250a5e..d627df1 100644 --- a/manifests/daemon/vhosts.pp +++ b/manifests/daemon/vhosts.pp @@ -1,7 +1,9 @@ class git::daemon::vhosts inherits git::daemon { - File['/etc/sysconfig/git-daemon']{ - source => [ "puppet://$server/modules/site-git/sysconfig/${fqdn}/git-daemon.vhosts", - "puppet://$server/modules/site-git/sysconfig/git-daemon.vhosts", - "puppet://$server/modules/git/sysconfig/git-daemon.vhosts" ], + File['git-daemon_config']{ + source => [ "puppet://$server/modules/site-git/config/${fqdn}/git-daemon.vhosts", + "puppet://$server/modules/site-git/config/${operatingsystem}/git-daemon.vhosts", + "puppet://$server/modules/site-git/config/git-daemon.vhosts", + "puppet://$server/modules/git/config/${operatingsystem}/git-daemon.vhosts", + "puppet://$server/modules/git/config/git-daemon.vhosts" ], } } diff --git a/manifests/debian.pp b/manifests/debian.pp new file mode 100644 index 0000000..1c17df9 --- /dev/null +++ b/manifests/debian.pp @@ -0,0 +1,5 @@ +class git::debian inherits git::base { + Package['git] { + name => 'git-core', + } +} diff --git a/manifests/init.pp b/manifests/init.pp index 812830c..3afce8d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -12,9 +12,14 @@ # class git { - include git::base - if $use_shorewall { - include shorewall::rules::out::git - } + case $operatingsystem { + debian: { include git::debian } + centos: { include git::centos } + } + + if $use_shorewall { + include shorewall::rules::out::git + } + } -- cgit v1.2.3