Permalink
Browse files

Initial commit with a working module that creates the user, installs …

…the standalone archiva, and define it as a service
  • Loading branch information...
1 parent 563cd77 commit cae65d9df57a5420219b45bbf0c328fe41c33007 @deigote deigote committed May 8, 2012
Showing with 180 additions and 0 deletions.
  1. +68 −0 files/etc/init.d/archiva
  2. +14 −0 manifests/conf.pp
  3. +5 −0 manifests/init.pp
  4. +53 −0 manifests/install.pp
  5. +23 −0 manifests/service.pp
  6. +17 −0 manifests/user.pp
View
68 files/etc/init.d/archiva
@@ -0,0 +1,68 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides: archiva
+# Required-Start: $local_fs $remote_fs $network $syslog $named
+# Required-Stop: $local_fs $remote_fs $network $syslog $named
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# X-Interactive: true
+# Short-Description: Start/stop archiva artifacs server
+### END INIT INFO
+
+set -e
+if [ -f /lib/lsb/init-functions ] ; then
+ . /lib/lsb/init-functions
+fi
+
+ARCHIVA_HOME="/opt/archiva"
+ARCHIVA_PID_FILE="$ARCHIVA_HOME/logs/archiva.pid"
+ARCHIVA_USER=archiva
+
+case $1 in
+ start)
+ if [ -f "$ARCHIVA_PID_FILE" ] && kill -0 `cat "$ARCHIVA_PID_FILE"` ; then
+ log_daemon_msg 'Already running!' 'archiva'
+ else
+ log_daemon_msg 'Starting' 'archiva'
+ su $ARCHIVA_USER -c "$ARCHIVA_HOME/bin/archiva start"
+ fi
+ log_end_msg 0
+ ;;
+ stop)
+ log_daemon_msg 'Stoping' 'archiva'
+ su $ARCHIVA_USER -c "$ARCHIVA_HOME/bin/archiva stop"
+ sleep 10
+ if [ -f "$ARCHIVA_PID_FILE" ] ; then
+ PID=`cat "$ARCHIVA_PID_FILE"`
+ if kill -0 $PID ; then
+ log_daemon_msg 'Still running with pid $PID... killing it' 'archiva'
+ kill -15 ?$PID
+ sleep 5
+ kill -9 $PID
+ else
+ log_daemon_msg 'Not running but pid file still exists... deleting it' 'archiva'
+ fi
+ rm "$ARCHIVA_PID_FILE"
+ fi
+ log_end_msg 0
+ ;;
+ restart)
+ $0 stop
+ $0 start
+ ;;
+ status)
+ if [ -f "$ARCHIVA_PID_FILE" ] ; then
+ PID=`cat "$ARCHIVA_PID_FILE"`
+ if kill -0 $PID; then
+ echo "Archiva is running (pid $PID)."
+ exit 0
+ fi
+ fi
+ echo "Archiva is NOT running."
+ exit 1
+ ;;
+ *)
+ log_success_msg "Usage: /etc/init.d/archiva {start|stop|restart|status}"
+ exit 1
+ ;;
+esac
View
14 manifests/conf.pp
@@ -0,0 +1,14 @@
+class archiva::conf($version = "1.4-M2", $destination_parent = '/opt', $user = 'archiva') {
+
+ $destination = "$destination_parent/archiva"
+
+ if !defined(File["$destination_parent"]) {
+ file { "$destination_parent":
+ ensure => 'directory',
+ owner => "root",
+ group => "root",
+ mode => "0751",
+ }
+ }
+
+}
View
5 manifests/init.pp
@@ -0,0 +1,5 @@
+class archiva {
+
+ include archiva::service
+
+}
View
53 manifests/install.pp
@@ -0,0 +1,53 @@
+class archiva::install {
+
+ $standalone_url = "http://apache.rediris.es/archiva/binaries/apache-archiva-${archiva::conf::version}-bin.zip"
+
+ include wget
+ include archiva::conf
+
+ file { "$archiva::conf::destination":
+ ensure => 'directory',
+ owner => "$archiva::conf::user",
+ group => "$archiva::conf::user",
+ mode => "0751",
+ }
+
+ wget::fetch { 'archiva-package-download':
+ source => "$standalone_url",
+ destination => "$archiva::conf::destination/apache-archiva.zip",
+ require => [Package["wget"], File["$archiva::conf::destination"]],
+ }
+
+ exec { 'unzip-archiva-package':
+ command => "unzip apache-archiva.zip",
+ cwd => "$archiva::conf::destination",
+ refreshonly => true,
+ subscribe => Wget::Fetch['archiva-package-download'],
+ }
+
+ exec { 'mv-archiva-content':
+ command => "find apache-archiva-* -mindepth 1 -maxdepth 1 -exec mv {} . \;",
+ cwd => "$archiva::conf::destination",
+ refreshonly => true,
+ subscribe => Exec['unzip-archiva-package'],
+ }
+
+ exec { 'rm-archiva-dir':
+ command => "find . -mindepth 1 -maxdepth 1 -type d -name 'apache-archiva-*' -exec rmdir {} \;",
+ cwd => "$archiva::conf::destination",
+ refreshonly => true,
+ subscribe => Exec['mv-archiva-content'],
+ }
+
+ exec { 'chown-archiva':
+ command => "chown -R $archiva::conf::user.$archiva::conf::user $archiva::conf::destination",
+ refreshonly => true,
+ subscribe => Exec['rm-archiva-dir'],
+ }
+
+ file { "$archiva::conf::destination/bin/wrapper-linux-x86-32":
+ ensure => 'absent',
+ require => Exec['mv-archiva-content']
+ }
+
+}
View
23 manifests/service.pp
@@ -0,0 +1,23 @@
+class archiva::service {
+
+ include archiva::conf
+ include archiva::install
+ include archiva::user
+
+ file { '/etc/init.d/archiva':
+ ensure => 'present',
+ owner => 'root',
+ group => 'root',
+ mode => '0754',
+ source => "puppet:///modules/archiva/etc/init.d/archiva",
+ require => File["$archiva::conf::destination/bin/wrapper-linux-x86-32"]
+ }
+
+ service { "archiva":
+ ensure => running,
+ hasstatus => true,
+ hasrestart => true,
+ enable => true,
+ require => [File['/etc/init.d/archiva'], Exec['chown-archiva'], User["$archiva::conf::user"]]
+ }
+}
View
17 manifests/user.pp
@@ -0,0 +1,17 @@
+class archiva::user {
+
+ include archiva::conf
+
+ group { "$archiva::conf::user":
+ ensure => present
+ }
+
+ user { "$archiva::conf::user":
+ ensure => present,
+ gid => "$archiva::conf::user",
+ shell => '/bin/sh',
+ home => "$archiva::conf::destination",
+ require => Group["$archiva::conf::user"],
+ }
+
+}

0 comments on commit cae65d9

Please sign in to comment.