Commits

Stefan Saasen  committed ebf5970

Start Stash via our init script

  • Participants
  • Parent commits ca9bf5b

Comments (0)

Files changed (3)

     v.customize  ["modifyvm", :id, "--memory", 1024]
   end
 
+  config.vm.synced_folder "templates/", "/tmp/vagrant-puppet/templates"
+
   config.vm.network :forwarded_port, guest: 7990, host: 8080
   config.vm.provision :puppet, :module_path => "modules" do |puppet|
     puppet.manifests_path = "manifests"
     puppet.manifest_file  = "default.pp"
+    puppet.options = ["--templatedir","/tmp/vagrant-puppet/templates"]
   end
 end

File manifests/default.pp

              "tmux",
              "curl",
              "git-core",
-             "daemontools",
-             "daemontools-run",
              "bash"]:
     ensure => present,
     require => Exec["apt-get update"],
   exec {
     "download_stash":
     command => "curl -L http://www.atlassian.com/software/stash/downloads/binary/atlassian-stash-2.5.2.tar.gz | tar zx",
-    cwd => "/vagrant",
+    cwd => "/home/vagrant",
     user => "vagrant",
     path    => "/usr/bin/:/bin/",
     logoutput => true,
     require => [ Package["curl"] ],
-    creates => "/vagrant/atlassian-stash-2.5.2",
+    creates => "/home/vagrant/atlassian-stash-2.5.2",
   }
 
   exec {
     "create_stash_home":
-    command => "mkdir -p /vagrant/stash-home",
-    cwd => "/vagrant",
+    command => "mkdir -p /home/vagrant/stash/stash-home",
+    cwd => "/home/vagrant",
     user => "vagrant",
     path    => "/usr/bin/:/bin/",
     require => Exec["download_stash"],
     logoutput => true,
-    creates => "/vagrant/stash-home",
+    creates => "/home/vagrant/stash/stash-home",
+  }
+
+  file { "/etc/init.d/stash" :
+    content => template("stash-init.erb"),
+    mode    => '0755',
+    owner    => 'root',
   }
 
-  $checkout = "/home/vagrant/svn-migration-scripts"
-  vcsrepo { $checkout:
-    ensure   => latest,
-    owner    => "vagrant",
-    user     => "vagrant",
-    group    => "vagrant",
-    provider => git,
-    source   => "https://bitbucket.org/atlassian/svn-migration-scripts.git",
-    revision => "master",
-    require  => Package['git-core'],
+  file { "/home/vagrant/stash/stash-home":
+    source => "/vagrant/stash-home",
+    recurse => true,
+    require => [Exec["create_stash_home"]],
   }
+
+  service { "stash" :
+    ensure => running,
+    hasrestart => true,
+    hasstatus => true,
+    enable => true,
+    require => [File["/etc/init.d/stash"], Exec["download_stash"]],
+  }
+
 }
 
 include must-have

File templates/stash-init.erb

+#! /bin/sh
+
+### BEGIN INIT INFO
+# Provides:          stash
+# Required-Start:    $remote_fs $syslog
+# Required-Stop:     $remote_fs $syslog
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Initscript for Atlassian Stash
+# Description:  Automatically start Atlassian Stash when the system starts up.
+#               Provide commands for manually starting and stopping Stash.
+### END INIT INFO
+
+# Adapt the following lines to your configuration
+# RUNUSER: The user to run Stash as.
+RUNUSER=vagrant
+
+# STASH_INSTALLDIR: The path to the Stash installation directory
+STASH_INSTALLDIR="/home/vagrant/atlassian-stash-2.5.2"
+
+# STASH_HOME: Path to the Stash home directory
+STASH_HOME="/home/vagrant/stash/stash-home"
+
+# ==================================================================================
+# ==================================================================================
+# ==================================================================================
+
+# PATH should only include /usr/* if it runs after the mountnfs.sh script
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+DESC="Atlassian Stash"
+NAME=stash
+PIDFILE=$STASH_INSTALLDIR/work/catalina.pid
+SCRIPTNAME=/etc/init.d/$NAME
+
+# Read configuration variable file if it is present
+[ -r /etc/default/$NAME ] && . /etc/default/$NAME
+
+# Define LSB log_* functions.
+# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
+. /lib/lsb/init-functions
+
+
+run_with_home() {
+    if [ "$RUNUSER" != "$USER" ]; then
+        su - "$RUNUSER" -c "export STASH_HOME=${STASH_HOME};${STASH_INSTALLDIR}/bin/$1"
+    else
+        export STASH_HOME=${STASH_HOME};${STASH_INSTALLDIR}/bin/$1
+    fi
+}
+
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+    run_with_home start-stash.sh
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+    if [ -e $PIDFILE ]; then
+      run_with_home stop-stash.sh
+    else
+      log_failure_msg "$NAME is not running."
+    fi
+}
+
+
+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)
+       if [ ! -e $PIDFILE ]; then
+         log_failure_msg "$NAME is not running."
+         return 1
+       fi
+       status_of_proc -p $PIDFILE "" $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
+