Correct initial database generation and improve runcommand script logic.

Tue, 02 Apr 2013 20:44:50 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 02 Apr 2013 20:44:50 +0200
changeset 767
3ee660c5bc4f
parent 766
fd2bc92f4dee
child 768
70baf26f1088

Correct initial database generation and improve runcommand script logic.

chiliproj/chiliproj.spec file | annotate | diff | comparison | revisions
chiliproj/rc.chiliproj file | annotate | diff | comparison | revisions
     1.1 --- a/chiliproj/chiliproj.spec	Mon Apr 01 20:12:48 2013 +0200
     1.2 +++ b/chiliproj/chiliproj.spec	Tue Apr 02 20:44:50 2013 +0200
     1.3 @@ -22,6 +22,7 @@
     1.4  ##
     1.5  
     1.6  # FIXME: GEM_HOME=$HOME/.gem RAILS_ENV=production PATH=$PATH:%{l_prefix}/lib/ruby/gems/1.9.1/bin bundle install --without test development mysql postgres rmagick
     1.7 +# FIXME: %{l_prefix}/lib/ruby/gems/1.9.1/bin/rake -T (or -D)
     1.8  # FIXME: Reduce %post by removing RAILS_ENV=production
     1.9  # FIXME: Consider using imagemagick for Gantt?
    1.10  # FIXME: bundle exec rails s
    1.11 @@ -248,6 +249,9 @@
    1.12      %{l_shtool} subst \
    1.13          -e 's;# \(ENV\[.RAILS_ENV.\] ||= .production.\);\1;' \
    1.14          config/environment.rb
    1.15 +    %{l_shtool} subst \
    1.16 +        -e 's;.*<%= l(:text_powered_by.*;;' \
    1.17 +        app/views/layouts/base.rhtml
    1.18  
    1.19  %build
    1.20  
    1.21 @@ -337,35 +341,51 @@
    1.22            #   install session
    1.23            echo 'Creating ChiliProject session key...'
    1.24            $RPM_INSTALL_PREFIX/lib/ruby/gems/$RUBY_VERSION/bin/bundle \
    1.25 -              exec rake generate_session_store
    1.26 +              exec rake -s generate_session_store
    1.27            #   create initial database
    1.28 -          echo 'Creating ChiliProject initial database...'
    1.29 -          RAILS_ENV=production \
    1.30 -              $RPM_INSTALL_PREFIX/lib/ruby/gems/$RUBY_VERSION/bin/bundle \
    1.31 -              exec rake db:migrate >/dev/null
    1.32 +          echo 'Creating ChiliProject data schemas...'
    1.33 +          $RPM_INSTALL_PREFIX/lib/ruby/gems/$RUBY_VERSION/bin/bundle \
    1.34 +              exec rake db:migrate \
    1.35 +              RAILS_ENV=production VERBOSE=false
    1.36 +          #echo 'Creating ChiliProject initial database...'
    1.37 +          #$RPM_INSTALL_PREFIX/lib/ruby/gems/$RUBY_VERSION/bin/bundle \
    1.38 +          #    exec rake db:setup >/dev/null 2>&1 \
    1.39 +          #    exec rake -s db:create \
    1.40 +          #    RAILS_ENV=production
    1.41            #   insert default configuration into database
    1.42            echo 'Populating ChiliProject initial database...'
    1.43            echo 'en' | \
    1.44 -              RAILS_ENV=production \
    1.45 -              $RPM_INSTALL_PREFIX/lib/ruby/gems/$RUBY_VERSION/bin/bundle \
    1.46 -              exec rake redmine:load_default_data >/dev/null
    1.47 +          $RPM_INSTALL_PREFIX/lib/ruby/gems/$RUBY_VERSION/bin/bundle \
    1.48 +              exec rake redmine:load_default_data >/dev/null \
    1.49 +              RAILS_ENV=production
    1.50            #   correct permissions of generated files
    1.51            chown %{l_nusr}:%{l_mgrp} \
    1.52                $RPM_INSTALL_PREFIX/lib/chiliproj/log/production.log \
    1.53                $RPM_INSTALL_PREFIX/lib/chiliproj/config/initializers/session_store.rb \
    1.54 +              $RPM_INSTALL_PREFIX/lib/chiliproj/db \
    1.55                $RPM_INSTALL_PREFIX/lib/chiliproj/db/* \
    1.56                $RPM_INSTALL_PREFIX/lib/chiliproj/db/*/*
    1.57 -chown opsw-n db db/* db/migrate/*
    1.58            chmod 0664 \
    1.59                $RPM_INSTALL_PREFIX/lib/chiliproj/log/production.log \
    1.60                $RPM_INSTALL_PREFIX/lib/chiliproj/config/initializers/session_store.rb \
    1.61                $RPM_INSTALL_PREFIX/lib/chiliproj/db/* \
    1.62                $RPM_INSTALL_PREFIX/lib/chiliproj/db/*/*
    1.63 +          chmod 0775 \
    1.64 +              $RPM_INSTALL_PREFIX/lib/chiliproj/db \
    1.65 +              $RPM_INSTALL_PREFIX/lib/chiliproj/db/migrate
    1.66          ) || exit $?
    1.67 -        echo 'ChiliProject installation done.'
    1.68 +        echo 'ChiliProject postinstallation finished.'
    1.69      fi
    1.70      #   after upgrade, restart service
    1.71      [ $1 -eq 2 ] || exit 0
    1.72 +    RUBY_VERSION=`%{l_prefix}/bin/gem which rubygems | sed -e 's;.*/\([^/]*\)/rubygems\.rb$;\1;'`
    1.73 +    ( cd $RPM_INSTALL_PREFIX/lib/chiliproj
    1.74 +      ##   migrate existing database
    1.75 +      #echo 'Migrating ChiliProject existing database...'
    1.76 +      #VERBOSE=false RAILS_ENV=production \
    1.77 +      #    $RPM_INSTALL_PREFIX/lib/ruby/gems/$RUBY_VERSION/bin/bundle \
    1.78 +      #    exec rake db:migrate
    1.79 +    ) || exit $?
    1.80      eval `%{l_rc} chiliproj status 2>/dev/null`
    1.81      [ ".$chiliproj_active" = .yes ] && %{l_rc} chiliproj restart
    1.82      exit 0
     2.1 --- a/chiliproj/rc.chiliproj	Mon Apr 01 20:12:48 2013 +0200
     2.2 +++ b/chiliproj/rc.chiliproj	Tue Apr 02 20:44:50 2013 +0200
     2.3 @@ -4,22 +4,29 @@
     2.4  ##
     2.5  
     2.6  %config
     2.7 -    chili_enable="$openpkg_rc_def"
     2.8 -    chili_host="localhost"
     2.9 -    chili_port=3000
    2.10 -    chili_svcs=1
    2.11 -    chili_log_prolog="true"
    2.12 -    chili_log_epilog="true"
    2.13 -    chili_log_numfiles="10"
    2.14 -    chili_log_minsize="1M"
    2.15 -    chili_log_complevel="9"
    2.16 -    chili_logfile="@l_prefix@/lib/chiliproj/log/production.log"
    2.17 -    chili_thinpath="@l_prefix@/var/chiliproj"
    2.18 +    chiliproj_enable="$openpkg_rc_def"
    2.19 +    chiliproj_cleartext"="yes"
    2.20 +    chiliproj_tlsecured"="no"
    2.21 +    #chiliproj_flags="-u @l_nusr@ -g @l_musr@"
    2.22 +    chiliproj_flags=""
    2.23 +    chiliproj_host="localhost"
    2.24 +    chiliproj_port_clt=80
    2.25 +    chiliproj_port_tls=443
    2.26 +    chiliproj_svcs=1
    2.27 +    chiliproj_key="@l_prefix@/etc/openssl/host-ca-rsa-4096-key.pem"
    2.28 +    chiliproj_crt="@l_prefix@/etc/openssl/host-ca-rsa-4096-crt.pem"
    2.29 +    chiliproj_log_prolog="true"
    2.30 +    chiliproj_log_epilog="true"
    2.31 +    chiliproj_log_numfiles="10"
    2.32 +    chiliproj_log_minsize="1M"
    2.33 +    chiliproj_log_complevel="9"
    2.34 +    chiliproj_logfile="@l_prefix@/lib/chiliproj/log/production.log"
    2.35 +    chiliproj_thinpath="@l_prefix@/var/chiliproj"
    2.36  
    2.37  %common
    2.38 -    chili_pidpath="@l_prefix@/var/chiliproj"
    2.39 -    chili_signal () {
    2.40 -        for thepid in ${chili_pidpath}/thind.[0-9][0-9]*.pid; do
    2.41 +    chiliproj_pidpath="@l_prefix@/var/chiliproj"
    2.42 +    chiliproj_signal () {
    2.43 +        for thepid in ${chiliproj_pidpath}/thind.[0-9][0-9]*.pid; do
    2.44              [ -f $thepid ] && kill -$1 `cat $thepid`
    2.45              proclive=$?
    2.46              if [ $proclive = 0 ]; then break; fi
    2.47 @@ -28,39 +35,52 @@
    2.48      }
    2.49  
    2.50  %status -u @l_susr@ -o
    2.51 -    chili_usable="unknown"
    2.52 -    chili_active="no"
    2.53 +    chiliproj_usable="unknown"
    2.54 +    chiliproj_active="no"
    2.55      rcService chiliproj enable yes && \
    2.56 -        chili_signal 0 && chili_active="yes"
    2.57 -    echo "chili_enable=\"$chili_enable\""
    2.58 -    echo "chili_usable=\"$chili_usable\""
    2.59 -    echo "chili_active=\"$chili_active\""
    2.60 +        chiliproj_signal 0 && chiliproj_active="yes"
    2.61 +    echo "chiliproj_enable=\"$chiliproj_enable\""
    2.62 +    echo "chiliproj_usable=\"$chiliproj_usable\""
    2.63 +    echo "chiliproj_active=\"$chiliproj_active\""
    2.64  
    2.65  %start -u @l_susr@
    2.66      rcService chiliproj enable yes || exit 0
    2.67      rcService chiliproj active yes && exit 0
    2.68 -#--ssl
    2.69 -#--ssl-verify
    2.70 -#--ssl-key-file <path>
    2.71 -#--ssl-cert-file <path>
    2.72 -    cd @l_chilipath@ && \
    2.73 -        @l_gempath@/bin/bundle exec thin \
    2.74 -        -d \
    2.75 -        -e production \
    2.76 -        -u @l_nusr@ \
    2.77 -        -g @l_mgrp@ \
    2.78 -        -a $chili_host \
    2.79 -        -p $chili_port \
    2.80 -        -s $chili_svcs \
    2.81 -        -P $chili_pidpath/thind.pid \
    2.82 -        -l $chili_thinpath/thind.log \
    2.83 -        start
    2.84 +    if [ "$chiliproj_cleartext" = "yes" ]; then
    2.85 +        cd @l_chilipath@ && \
    2.86 +            @l_gempath@/bin/bundle exec thin \
    2.87 +                -d \
    2.88 +                -e production \
    2.89 +                -a $chiliproj_host \
    2.90 +                -p $chiliproj_port_clt \
    2.91 +                -s $chiliproj_svcs \
    2.92 +                -P $chiliproj_pidpath/thind.pid \
    2.93 +                -l $chiliproj_thinpath/thind.log \
    2.94 +                $chiliproj_flags \
    2.95 +                start
    2.96 +    fi
    2.97 +    if [ "$chiliproj_tlsecured" = "yes" ]; then
    2.98 +        cd @l_prefix@/lib/chiliproj && \
    2.99 +            @l_gempath@/bin/bundle exec thin \
   2.100 +                -d \
   2.101 +                -e production \
   2.102 +                -a $chiliproj_host \
   2.103 +                -p $chiliproj_port_tls \
   2.104 +                -s $chiliproj_svcs \
   2.105 +                -P $chiliproj_pidpath/thind.pid \
   2.106 +                -l $chiliproj_thinpath/thind.log \
   2.107 +                --ssl \
   2.108 +                --ssl-key-file $chiliproj_key \
   2.109 +                --ssl-cert-file $chiliproj_crt \
   2.110 +                $chiliproj_flags \
   2.111 +                start
   2.112 +    fi
   2.113  
   2.114  %stop -u @l_susr@
   2.115      rcService chiliproj enable yes || exit 0
   2.116      rcService chiliproj active no  && exit 0
   2.117      cd @l_chilipath@
   2.118 -    for thepid in ${chili_pidpath}/thind.[0-9][0-9]*.pid; do
   2.119 +    for thepid in ${chiliproj_pidpath}/thind.[0-9][0-9]*.pid; do
   2.120          cd @l_prefix@/lib/chiliproj
   2.121          @l_gempath@/bin/bundle exec thin -P $thepid stop
   2.122      done
   2.123 @@ -77,17 +97,17 @@
   2.124      rcTmp -i
   2.125      hintfile=`rcTmp -f -n hint`
   2.126      shtool rotate -f \
   2.127 -        -n ${chili_log_numfiles} -s ${chili_log_minsize} -d \
   2.128 -        -z ${chili_log_complevel} -m 664 -o @l_nusr@ -g @l_mgrp@ \
   2.129 -        -P "${chili_log_prolog}" \
   2.130 -        -E "${chili_log_epilog}; echo 1 >$hintfile" \
   2.131 -        ${chili_logfile}
   2.132 +        -n ${chiliproj_log_numfiles} -s ${chiliproj_log_minsize} -d \
   2.133 +        -z ${chiliproj_log_complevel} -m 664 -o @l_nusr@ -g @l_mgrp@ \
   2.134 +        -P "${chiliproj_log_prolog}" \
   2.135 +        -E "${chiliproj_log_epilog}; echo 1 >$hintfile" \
   2.136 +        ${chiliproj_logfile}
   2.137      shtool rotate -f \
   2.138 -        -n ${chili_thin_numfiles} -s ${chili_thin_minsize} -d \
   2.139 -        -z ${chili_thin_complevel} -m 664 -o @l_nusr@ -g @l_mgrp@ \
   2.140 -        -P "${chili_thin_prolog}" \
   2.141 -        -E "${chili_thin_epilog}; echo 1 >$hintfile" \
   2.142 -        ${chili_thinpath}/thind.*.log
   2.143 +        -n ${chiliproj_thin_numfiles} -s ${chiliproj_thin_minsize} -d \
   2.144 +        -z ${chiliproj_thin_complevel} -m 664 -o @l_nusr@ -g @l_mgrp@ \
   2.145 +        -P "${chiliproj_thin_prolog}" \
   2.146 +        -E "${chiliproj_thin_epilog}; echo 1 >$hintfile" \
   2.147 +        ${chiliproj_thinpath}/thind.*.log
   2.148      if [ -s $hintfile ]; then
   2.149          rc chiliproj restart
   2.150      fi

mercurial