Permalink
Browse files

Initial refactoring of gitorious for impending move to ruby1.9/rails3

  • Loading branch information...
1 parent 0845148 commit 5157be9bfad375fca4d0c15d78f6de32472ce264 @mtorromeo committed Nov 23, 2012
View
@@ -8,14 +8,28 @@ arch=(i686 x86_64)
url="http://gitorious.org/gitorious"
license=('AGPLv3')
-depends=('sphinx' 'mysql' 'ruby-enterprise' 'ruby-enterprise-raspell' 'ruby-enterprise-bundler' 'ruby-enterprise-stompserver' 'imagemagick' 'nodejs-buster' 'libxslt')
+depends=('sphinx' 'mysql' 'ruby-bundler' 'imagemagick' 'nodejs-buster' 'libxslt')
makedepends=('git')
-optdepends=('memcached: High performance cache')
+optdepends=(
+ 'memcached: High performance cache'
+ 'redis: message queue')
+options=('!strip')
install=gitorious.install
-backup=(etc/webapps/gitorious/broker.yml etc/webapps/gitorious/database.yml etc/webapps/gitorious/gitorious.yml)
-
-source=(gitorious-daemon.rc.d gitorious-poller.rc.d gitorious-ultrasphinx.rc.d gitorious-resque-worker.rc.d database.yml gitorious.yml sphinx-cmd.patch)
+backup=(
+ etc/webapps/gitorious/gitorious.yml
+ etc/webapps/gitorious/database.yml
+ etc/webapps/gitorious/authentication.yml
+ etc/webapps/gitorious/memcache.yml
+ etc/webapps/gitorious/resque.yml
+ etc/webapps/gitorious/unicorn.rb
+)
+
+source=(
+ gitorious-daemon.rc.d
+ gitorious-resque-worker.rc.d
+ sphinx-cmd.patch
+)
conflicts=(gitorious)
provides=(gitorious)
@@ -32,34 +46,34 @@ build() {
ln -s /usr/bin/gcc gcc46-pathfix/gcc-4.6
export PATH="$PATH:$srcdir/gcc46-pathfix"
- msg "Connecting to GIT server...."
+ msg2 "Connecting to GIT server...."
if [ -d "$srcdir/$_gitname" ]; then
cd $_gitname && git pull origin
msg "The local files are updated."
else
- git clone $_gitroot $_gitname
+ git clone -b feature/rails3 $_gitroot $_gitname
+ cd $_gitname
fi
+ git submodule update --recursive --init
- msg "GIT checkout done or server timeout"
+ msg2 "GIT checkout done or server timeout"
rm -rf "$srcdir/$_gitname-build"
cp -r "$srcdir/$_gitname" "$srcdir/$_gitname-build"
cd "$srcdir/$_gitname-build/"
- rm -rf .git .gitmodules
- find . -type f -name .gitignore -delete
+ find . -type f -name .git\* -delete
+ find . -type d -name .git\* -exec rm -rf {} +
- msg "Fetching bundled gems..."
- /opt/ruby-enterprise/bin/bundle install --deployment --binstubs
+ msg2 "Fetching bundled gems..."
+ bundle install --deployment --binstubs
rm -rf vendor/bundle/ruby/*/cache
- msg "Patching application..."
+ msg2 "Patching application..."
# Activate production mode
sed -i "s|^# ENV\['RAILS_ENV'\]|ENV['RAILS_ENV']|" config/environment.rb
patch -p1 -i "$srcdir/sphinx-cmd.patch"
-
- find bin script data/hooks -type f -exec sed -i 's|^#!/usr/bin/env ruby|#!/opt/ruby-enterprise/bin/ruby|' {} \;
}
package() {
@@ -70,33 +84,45 @@ package() {
install -d "$pkgdir/usr/share/webapps"
install -d "$_etc"
- mv "$_gitname-build" "${pkgdir}${_gitorious}"
+ msg2 "Copying gitorious files"
+ cp -a "$_gitname-build" "${pkgdir}${_gitorious}"
- install -D -m0644 "$srcdir/database.yml" "$_etc/database.yml"
- install -D -m0644 "$srcdir/gitorious.yml" "$_etc/gitorious.yml"
- install -D -m0644 "${pkgdir}${_gitorious}/config/broker.yml.example" "$_etc/broker.yml"
- install -D -m0644 "${pkgdir}${_gitorious}/vendor/plugins/ultrasphinx/examples/ap.multi" "$pkgdir/usr/lib/aspell/ap.multi"
+ # Configurations
+ msg2 "Moving configuration files"
+ for f in "$pkgdir$_gitorious/config/"*.sample*; do
+ fdest=$(basename "$f")
+ fdest=${fdest/.sample/}
+ install -Dm0644 "$f" "$_etc/$fdest"
+ rm "$f"
+ ln -s "/etc/webapps/gitorious/$fdest" "$pkgdir$_gitorious/config/$fdest"
+ done
- ln -s "/etc/webapps/gitorious/database.yml" "${pkgdir}${_gitorious}/config/"
- ln -s "/etc/webapps/gitorious/gitorious.yml" "${pkgdir}${_gitorious}/config/"
- ln -s "/etc/webapps/gitorious/broker.yml" "${pkgdir}${_gitorious}/config/"
+ sed -e 's|^ password:\s*$| password: G170r!oUs|' \
+ -e 's|^ username:.*$| username: gitorious|' \
+ -e 's|gitorious_production|gitorious|' \
+ -i "$_etc/database.yml"
- install -d "$pkgdir/usr/bin"
- ln -s "${_gitorious}/script/gitorious" "$pkgdir/usr/bin/gitorious"
+ sed -e 's|/var/git/|/var/gitorious/|' \
+ -e 's|gitorious.local|localhost.localdomain|' \
+ -i "$_etc/gitorious.yml"
# capillary
ln -s /usr/lib/node_modules/buster/node_modules/ "${pkgdir}${_gitorious}/public/javascripts/lib/capillary/node_modules"
- install -D -m0755 "$srcdir/gitorious-daemon.rc.d" "$pkgdir/etc/rc.d/gitorious-daemon"
- install -D -m0755 "$srcdir/gitorious-poller.rc.d" "$pkgdir/etc/rc.d/gitorious-poller"
- install -D -m0755 "$srcdir/gitorious-resque-worker.rc.d" "$pkgdir/etc/rc.d/gitorious-resque-worker"
- install -D -m0755 "$srcdir/gitorious-ultrasphinx.rc.d" "$pkgdir/etc/rc.d/gitorious-ultrasphinx"
+ # services
+ msg2 "Installing services"
+ install -Dm0755 "$srcdir/gitorious-daemon.rc.d" "$pkgdir/etc/rc.d/gitorious-daemon"
+ install -Dm0755 "$srcdir/gitorious-resque-worker.rc.d" "$pkgdir/etc/rc.d/gitorious-resque-worker"
+
+ # data directories
+ msg2 "Setting up data directories"
+ install -dm0755 "$pkgdir/var/gitorious/"{tarballs,tarballs-work,repositories}
+
+ # remove tests
+ msg2 "Removing tests"
+ find "$pkgdir" -type d \( -name test -o -name tests \) -exec rm -rf {} +
}
-md5sums=('9d3a4476db211d0dd3a47368d21ea63a'
- 'a5dca286ee2023fbd63ffda5c327bd85'
- '9e759e6b3e34bbd0410c7d976bc1bc02'
- '7693608913eb9d5f9cdec5459f528fd9'
- '6a6efd4a0c9deaaefe841c57176a1bee'
- '81d964b4317ae0e91a8dbaf57fd80813'
- 'f46e84a467b492a6d5de936e1595e028')
+sha256sums=('040fdf9c9f9e39f5b0a8483befce74ed47750d813be421dd653393205f20b5c8'
+ '0b48f79cbd64bf01bd6bad02c30ef51391040114479e24b772dceef91a60c19c'
+ '65be83bccf7d18ebe87efb2ab318cea3e9e79ac36fa16e3217b5ae2b92963f7e')
@@ -1,5 +1,5 @@
production:
- adapter: mysql
+ adapter: mysql2
database: gitorious
username: gitorious
password: G170r!oUs
@@ -1,70 +0,0 @@
-#!/bin/bash
-
-. /etc/rc.conf
-. /etc/rc.d/functions
-
-GITORIOUS_HOME="/usr/share/webapps/gitorious"
-BUNDLE="/opt/ruby-enterprise/bin/bundle"
-PID_FILE="$GITORIOUS_HOME/tmp/pids/poller0.pid"
-
-check_pid() {
- local PIDFILE="$1"
- [ ! -f "$PIDFILE" ] && return 1
- local PID=$(cat "$PIDFILE" 2> /dev/null)
- [ -z "$PID" ] && return 1
- if [ ! -d "/proc/$PID" ]; then
- rm -f "$PIDFILE" 2> /dev/null
- return 1
- fi
- return 0
-}
-
-kill_pid() {
- local PIDFILE="$1"
- if check_pid "$PIDFILE"; then
- local PID=$(cat "$PIDFILE" 2> /dev/null)
- kill $PID &> /dev/null
- local RET=$?
- check_pid "$PIDFILE"
- return $RET
- fi
- return 1
-}
-
-wait_pid() {
- while check_pid "$1"; do sleep 1; done
-}
-
-case "$1" in
- start)
- stat_busy "Starting gitorious poller"
- if [ ! -d "$GITORIOUS_HOME/tmp/pids" ]; then
- mkdir "$GITORIOUS_HOME/tmp/pids"
- chown git:git "$GITORIOUS_HOME/tmp/pids"
- fi
- check_pid "$PID_FILE" || su - git -c "env RAILS_ENV=production $BUNDLE exec script/poller start" > /dev/null 2>&1
- if [ $? -gt 0 ]; then
- stat_fail
- else
- add_daemon gitorious-poller
- stat_done
- fi
- ;;
- stop)
- stat_busy "Stopping gitorious poller"
- if ! kill_pid "$PID_FILE"; then
- stat_fail
- else
- rm_daemon gitorious-poller
- stat_done
- fi
- ;;
- restart)
- $0 stop
- wait_pid "$PID_FILE"
- $0 start
- ;;
- *)
- echo "usage: $0 {start|stop|restart}"
-esac
-exit 0
@@ -1,44 +0,0 @@
-#!/bin/bash
-
-. /etc/rc.conf
-. /etc/rc.d/functions
-
-case "$1" in
- start)
- stat_busy "Starting gitorious ultrasphinx"
- /bin/su - git -c "bin/rake ultrasphinx:daemon:start RAILS_ENV=production"
- if [ $? -gt 0 ]; then
- stat_fail
- else
- add_daemon gitorious-ultrasphinx
- stat_done
- fi
- ;;
- stop)
- stat_busy "Stopping gitorious ultrasphinx"
- /bin/su - git -c "bin/rake ultrasphinx:daemon:stop RAILS_ENV=production"
- if [ $? -gt 0 ]; then
- stat_fail
- else
- rm_daemon gitorious-ultrasphinx
- stat_done
- fi
- ;;
- status)
- /bin/su - git -c "bin/rake ultrasphinx:daemon:start RAILS_ENV=production"
- ;;
- restart)
- stat_busy "Restarting gitorious ultrasphinx"
- /bin/su - git -c "bin/rake ultrasphinx:daemon:restart RAILS_ENV=production"
- if [ $? -gt 0 ]; then
- stat_fail
- rm_daemon gitorious-ultrasphinx
- else
- add_daemon gitorious-ultrasphinx
- stat_done
- fi
- ;;
- *)
- echo "usage: $0 {start|stop|status|restart}"
-esac
-exit 0
@@ -1,70 +1,61 @@
GITDIR="/usr/share/webapps/gitorious"
-BUNDLE="/opt/ruby-enterprise/bin/bundle"
post_install() {
+ groupadd -g 333 gitorious &>/dev/null
+ useradd -u 333 -g gitorious -d $GITDIR -s /bin/bash gitorious &>/dev/null
+
SECRET=$(dd if=/dev/random count=1 2>/dev/null | sha256sum | awk '{print $1}')
sed -i "s|CHANGEME_SECRET|$SECRET|" /etc/webapps/gitorious/gitorious.yml
- echo "Creating git user"
- useradd git -MUd "$GITDIR" -s /bin/bash > /dev/null 2>&1
- echo "* * * * * cd \"$GITDIR\" && bin/rake ultrasphinx:index RAILS_ENV=production 1>/dev/null" | crontab - -u git
cd "$GITDIR" || return 1
- mkdir -p tmp tarballs repositories pids site/tmp/pids .ssh site/data/hooks/pre site/data/hooks/post
+ mkdir -p tmp pids site/tmp/pids .ssh site/data/hooks/pre site/data/hooks/post
touch .ssh/authorized_keys
chmod -R 700 script
chmod 700 .ssh
chmod 600 .ssh/authorized_keys
chmod 744 site/data/hooks/pre site/data/hooks/post
- chown -R git:git "$GITDIR"
+ chown -R gitorious:gitorious "$GITDIR"
echo "Configuring mysql & sphinx:"
echo -n " - Creating database gitorious: "
- echo 'CREATE DATABASE gitorious; GRANT ALL ON gitorious.* TO gitorious@localhost IDENTIFIED BY "G170r!oUs";' | mysql > /dev/null 2>&1 && echo ok || echo FAIL
+ echo 'CREATE DATABASE IF NOT EXISTS gitorious; GRANT ALL ON gitorious.* TO gitorious@localhost IDENTIFIED BY "G170r!oUs";' | mysql > /dev/null 2>&1 && echo ok || echo FAIL
echo -n " - db:setup "
- su - git -c "bin/rake db:setup RAILS_ENV=production" > /dev/null 2>&1 && echo ok || echo FAIL
- echo -n " - ultrasphinx:configure "
- su - git -c "bin/rake ultrasphinx:configure RAILS_ENV=production" > /dev/null 2>&1 && echo ok || echo FAIL
- echo -n " - ultrasphinx:bootstrap "
- su - git -c "bin/rake ultrasphinx:bootstrap RAILS_ENV=production" > /dev/null 2>&1 && echo ok || echo FAIL
- echo -n " - ultrasphinx:spelling:build "
- cd $GITDIR && bin/rake ultrasphinx:spelling:build RAILS_ENV=production > /dev/null 2>&1 && echo ok || echo FAIL
+ su - gitorious -c "bin/rake db:setup RAILS_ENV=production" > /dev/null 2>&1 && echo ok || echo FAIL
echo "DONE."
echo
echo "If mysql was not running during install (or any of the previous steps failed)"
echo "you will need to create the database and run rake manually."
echo "# echo 'CREATE DATABASE gitorious; GRANT ALL ON gitorious.* TO gitorious@localhost IDENTIFIED BY \"G170r!oUs\";' | mysql"
- echo "# su - git -c \"bin/rake db:setup RAILS_ENV=production\""
- echo "# su - git -c \"bin/rake ultrasphinx:configure RAILS_ENV=production\""
- echo "# su - git -c \"bin/rake ultrasphinx:bootstrap RAILS_ENV=production\""
- echo "# cd $GITDIR && bin/rake ultrasphinx:spelling:build RAILS_ENV=production"
+ echo "# su - gitorious -c \"bin/rake db:setup RAILS_ENV=production\""
echo
echo "To create the admin user, issue the following command"
- echo "# su - git -c \"env RAILS_ENV=production $BUNDLE exec script/create_admin\""
+ echo "# su - gitorious -c \"env RAILS_ENV=production bundle exec script/create_admin\""
echo
echo "Gitorious is a ruby application and depends on the following daemons that must be running:"
- echo "# /etc/rc.d/stompserver start"
echo "# /etc/rc.d/gitorious-daemon start"
- echo "# /etc/rc.d/gitorious-poller start"
- echo "# /etc/rc.d/gitorious-ultrasphinx start"
echo
echo "To run the application itself you can issue the following command:"
- echo "# su - git -c \"$BUNDLE exec script/server -e production\""
+ echo "# su - gitorious -c \"bundle exec script/server -e production\""
echo "and visit http://localhost.localdomain:3000"
- echo "or deploy it like any other ruby application (Ex: apache+passenger)"
+ echo "or deploy it like any other ruby application (Ex: apache/nginx+passenger/unicorn)"
}
post_upgrade() {
- chown -R git:git "$GITDIR"
+ chown -R gitorious:gitorious "$GITDIR"
echo "The database may need to be migrated to reflect the latest changes in the application"
echo "To migrate run the following command:"
- echo "# su - git -c \"bin/rake db:migrate RAILS_ENV=production\""
+ echo "# su - gitorious -c \"bin/rake db:migrate RAILS_ENV=production\""
}
-post_remove() {
- userdel git
- rm -f /var/spool/cron/git
+post_remove(){
+ if getent passwd gitorious >/dev/null 2>&1; then
+ userdel gitorious
+ fi
+ if getent group gitorious >/dev/null 2>&1; then
+ groupdel gitorious
+ fi
}
Oops, something went wrong.

0 comments on commit 5157be9

Please sign in to comment.