Projekt

Allgemein

Profil

Redmine bitnami 3 0 3 0 » Historie » Version 11

Jeremias Keihsler, 08.02.2018 09:22

1 1 Jeremias Keihsler
h1. Bitnami 3.0.3-0
2
3 5 Jeremias Keihsler
h2. setup receiving email
4
5
add following shell-script to @/usr/local/bin/redmine_recv_mail.sh@
6
7
<pre><code class="bash">
8
9
#to make this work I also had to do following things:
10
#
11
#  cd /opt/redmine-2.5.2-2
12
#  ./use_redmine
13
#  gem install rake -v 10.1.1
14
#
15
#add following file to 
16
17
PATH="/opt/redmine-3.0.3-0/perl/bin:/opt/redmine-3.0.3-0/git/bin:/opt/redmine-3.0.3-0/sqlite/bin:/opt/redmine-3.0.3-0/ruby/bin:/opt/redmine-3.0.3-0/subversion/bin:/opt/redmine-3.0.3-0/postgresql/bin:/opt/redmine-3.0.3-0/php/bin:/opt/redmine-3.0.3-0/mysql/bin:/opt/redmine-3.0.3-0/apache2/bin:/opt/redmine-3.0.3-0/common/bin:$PATH"
18
BITNAMI_ROOT="/opt/redmine-3.0.3-0"
19
export BITNAMI_ROOT
20
21
cd /opt/redmine-3.0.3-0/apps/redmine/htdocs
22
bundle exec rake redmine:email:receive_imap RAILS_ENV="production" ssl=true host=mail.example.com port=993 username=redmine@example.com password=mySecret4711 unknown_user=create no_permission_check=1
23
</code></pre>
24
25
 this setup will accept mails from everyone and automagically register unknown users.
26
27
add following cron-file @/etc/cron.d/redmine_mail_recv@
28
29
<pre><code class="bash">
30
 */15 * * * * root /usr/local/bin/redmine_recv_mail.sh
31
</code></pre>
32
33 6 Jeremias Keihsler
if you get an error about SSL-certificate (self signed) you may bypass SSL-verify by adding this file to @/opt/redmine-3.0.3-0/apps/redmine/htdocs/config/initializers/avoid_ssl_verification.rb@
34 5 Jeremias Keihsler
35
<pre><code class="ruby">
36
    require 'openssl'
37
    OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
38
</code></pre>
39
40 1 Jeremias Keihsler
h2. Troubleshoot imap
41
42
change @/opt/redmine-3.0.3-0/ruby/lib/ruby/2.0.0/net/imap.rb@ line ~1429
43
44
<pre><code class="ruby">
45
    def create_ssl_params(certs = nil, verify = true)
46
      params = {}
47
      if certs
48
        if File.file?(certs)
49
          params[:ca_file] = certs
50
        elsif File.directory?(certs)
51
          params[:ca_path] = certs
52
        end
53
      end
54
      if verify
55
      #  params[:verify_mode] = VERIFY_PEER
56
      #  taken out by JKE 2015-07-06
57
        params[:verify_mode] = VERIFY_NONE
58
      else
59
        params[:verify_mode] = VERIFY_NONE
60
      end
61
      return params
62
    end
63
</code></pre>
64 2 Jeremias Keihsler
65 10 Jeremias Keihsler
h1. setup log-rotating
66 2 Jeremias Keihsler
67 10 Jeremias Keihsler
h2. Redmine
68 2 Jeremias Keihsler
69
The Bitnami-Stack does not preconfigure log-rotating for the @production.log@ located in @/opt/redmine-3.0.3-0/apps/redmine/htdocs/log@. Although you could use the standard Logrotate it's recommended (http://www.redmine.org/boards/2/topics/11836) to use the Ruby-functionality. Add following parameter to @/opt/redmine-3.0.3-0/apps/redmine/htdocs/config/environments/production.rb@ and restart the Bitnami-Stack.
70
71
According to http://www.redmine.org/issues/11603 you have to provide a file directly to @Logger.new@ instead of the sample in the @production.rb@.
72
73
<pre><code class="ruby">
74
# 7 log-files, 20MB each
75
config.logger = Logger.new('/opt/redmine-3.0.3-0/apps/redmine/htdocs/log/production.log', 7, 20971520)
76
config.logger.level = Logger::INFO
77
</code></pre>
78
79
<pre>
80
[root@redmine ~]# cd /opt/redmine-3.0.3-0/apps/redmine/htdocs/log/
81
[root@redmine log]# ll
82
total 1120
83
-rwxrwxr-x. 1 root   daemon      36 Jun 18  2012 delete.me
84
-rw-r--r--. 1 daemon daemon   12158 Jul  9 09:36 production.log
85
-rw-rw-r--. 1 root   daemon   30053 Jul  9 09:28 production.log.0
86
-rwxrwxr-x. 1 root   daemon 1093571 Jul  9 08:59 production.log.1
87
</pre>
88 3 Jeremias Keihsler
89 10 Jeremias Keihsler
h2. apache / mysql
90 3 Jeremias Keihsler
91
let's use @logrotate@ for this task. There is @.conf@-files already shipped with the bitnami-stack.
92 4 Jeremias Keihsler
https://docs.bitnami.com/installer/components/logrotate/
93 3 Jeremias Keihsler
94
<pre><code class="bash">
95
ln -s /opt/redmine-3.0.3-0/config/logrotate/logrotate.d/apache.conf /etc/logrotate.d/bitnami_3.0.3-0_apache.conf
96
ln -s /opt/redmine-3.0.3-0/config/logrotate/logrotate.d/mysql.conf /etc/logrotate.d/bitnami_3.0.3-0_mysql.conf
97
</code></pre>
98 7 Jeremias Keihsler
99 9 Jeremias Keihsler
h2. setup Redmine-Logo
100
101
http://www.redmine.org/projects/redmine/wiki/Howto_add_a_logo_to_your_Redmine_banner
102
103
edit following file @/opt/redmine-3.0.3-0/apps/redmine/htdocs/app/views/layouts/base.html.erb@
104
105
<pre><code class="html">
106
#line 44
107
<h1><img src="<%= Redmine::Utils.relative_url_root %>/images/logo.png" style="top-margin: 15px; left-margin: 15px;"/> <%= page_header_title %></h1>
108
</code></pre>
109
110
copy @logo.png@ to @/opt/redmine-3.0.3-0/apps/redmine/htdocs/public/images@
111
112 7 Jeremias Keihsler
h1. Nagging
113
114
There are a couple of plugins available, we are trying to do our own thing. 
115
116
h2. create a read only user
117
118
<pre><code class="sql">
119
mysql -u root -p
120
grant select on bitnami_redmine.* to 'redmine_reader'@'localhost';
121
</code></pre>
122
123
h2. create a sql-statement
124
125
http://www.redmine.org/projects/redmine/wiki/DatabaseModel
126
!Redmine_2_5_2_2_ER-databasemodel.png!
127
128
This statement lists all open issues from the project with the internal ID 33 and all sub-projects with a due-date earlier than today+7days. All issue-IDs will be click-able links in the nag-mail. 
129
130
<pre><code class="sql">
131 8 Jeremias Keihsler
SELECT CONCAT('@@@1@http://www.example.com/redmine/issues/',_i.id,'@@@2@',_i.id,'@@@3@') AS ID,_is.name AS STATUS,_p.name AS Projekt ,LEFT(_i.subject,100) AS Thema,_i.due_date AS Zieldatum, _e.address AS mail
132 7 Jeremias Keihsler
FROM (SELECT DISTINCT _b.id,_b.name 
133
      FROM (SELECT _p.name,_p.id 
134
            FROM projects AS _p 
135
            WHERE _p.id=33 OR _p.parent_id=33
136
           ) AS pp, projects AS _b 
137
      WHERE _b.parent_id=pp.id OR _b.id=33 ORDER BY _b.name
138
     ) AS _p,
139
     issues AS _i, 
140 1 Jeremias Keihsler
     issue_statuses AS _is , 
141 8 Jeremias Keihsler
     users AS _u,
142
     email_addresses AS _e
143
WHERE _p.id = _i.project_id 
144
  AND _i.status_id=_is.id 
145
  AND _u.id=_i.assigned_to_id 
146
  AND _u.id=_e.user_id 
147
  AND _is.is_closed=0 
148
  AND _i.due_date<=ADDDATE(curdate(),7) 
149 7 Jeremias Keihsler
ORDER BY _p.name,_i.id;
150
</code></pre>
151
152
the funny @@@n@ groups are used later on.
153
154
h2. create a html-mail
155
156
create a little shell-sript @redmine_send_mail.sh@ that
157
* fetches the data from the database
158
* forms a valid html-mail
159
* sends the mail to one recipient
160
161
<pre><code class="bash">
162
#!/bin/sh
163
164
PATH="/opt/redmine-2.5.2-2/perl/bin:/opt/redmine-2.5.2-2/git/bin:/opt/redmine-2.5.2-2/sqlite/bin:/opt/redmine-2.5.2-2/ruby/bin:/opt/redmine-2.5.2-2/subversion/bin:/opt/redmine-2.5.2-2/postgresql/bin:/opt/redmine-2.5.2-2/php/bin:/opt/redmine-2.5.2-2/mysql/bin:/opt/redmine-2.5.2-2/apache2/bin:/opt/redmine-2.5.2-2/common/bin:$PATH"
165
166
#export List from DB
167
mysql -u redmine_reader -H -B bitnami_redmine < list.sql > /tmp/redmine_mysql_output
168
169
#replace special stuff
170
sed -i -e 's/@@@1@/<a href="/g' /tmp/redmine_mysql_output
171
sed -i -e 's/@@@2@/">/g' /tmp/redmine_mysql_output
172
sed -i -e 's/@@@3@/<\/a>/g' /tmp/redmine_mysql_output
173
174
echo 'Subject: weekly audit "all open issues due within the next 7 days"' > /tmp/redmine_mail_raw
175
echo 'to: user@example.com' >> /tmp/redmine_mail_raw
176
echo 'MIME-Version: 1.0' >> /tmp/redmine_mail_raw
177
echo 'Content-Type: text/html; charset=utf-8' >> /tmp/redmine_mail_raw
178
179
echo '' >> /tmp/redmine_mail_raw
180
echo '<html>' >> /tmp/redmine_mail_raw
181
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' >> /tmp/redmine_mail_raw
182
183
#export List from DB
184
cat /tmp/redmine_mysql_output >> /tmp/redmine_mail_raw
185
echo '</html>' >> /tmp/redmine_mail_raw
186
187
#send mail
188
cat /tmp/redmine_mail_raw | sendmail -t
189
</code></pre>
190
191
h2. use cron to nag periodically
192
193
run the shell-script from above every monday at 8:00am. @/etc/cron.d/redmine_audit@
194
195
<pre><code class="bash">
196
# JKE 2014-10-22
197
#
198
# minute hour day month dayofweek
199
# m h d m d
200
# - - - - -
201
# | | | | |
202
# | | | | +-day of week (0-7) sunday=0 or 7
203
# | | | +---month (1-12)
204
# | | +-----day of month (1-31)
205
# | +-------hour (0-23)
206
# +---------min (0-59)
207
# 
208
	00	08	*	*	1	root	/usr/local/bin/redmine_send_mail.sh
209
</code></pre>