Projekt

Allgemein

Profil

Redmine bitnami 3 4 4 1 » Historie » Version 1

Jeremias Keihsler, 14.02.2018 14:51

1 1 Jeremias Keihsler
h1. Bitnami Redmine 3.4.4-1
2
3
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.4.4-1/perl/bin:/opt/redmine-3.4.4-1/git/bin:/opt/redmine-3.4.4-1/sqlite/bin:/opt/redmine-3.4.4-1/ruby/bin:/opt/redmine-3.4.4-1/subversion/bin:/opt/redmine-3.4.4-1/postgresql/bin:/opt/redmine-3.4.4-1/php/bin:/opt/redmine-3.4.4-1/mysql/bin:/opt/redmine-3.4.4-1/apache2/bin:/opt/redmine-3.4.4-1/common/bin:$PATH"
18
BITNAMI_ROOT="/opt/redmine-3.4.4-1"
19
export BITNAMI_ROOT
20
21
cd /opt/redmine-3.4.4-1/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
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
35
<pre><code class="ruby">
36
    require 'openssl'
37
    OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
38
</code></pre>
39
40
h2. Troubleshoot imap
41
42
change @/opt/redmine-3.4.4-1/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
65
h1. setup log-rotating
66
67
h2. Redmine
68
69
The Bitnami-Stack does not preconfigure log-rotating for the @production.log@ located in @/opt/redmine-3.4.4-1/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.4.4-1/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.4.4-1/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
89
h2. apache / mysql
90
91
let's use @logrotate@ for this task. There is @.conf@-files already shipped with the bitnami-stack.
92
https://docs.bitnami.com/installer/components/logrotate/
93
94
<pre><code class="bash">
95
ln -s /opt/redmine-3.4.4-1/config/logrotate/logrotate.d/apache.conf /etc/logrotate.d/bitnami_3.4.4-1_apache.conf
96
ln -s /opt/redmine-3.4.4-1/config/logrotate/logrotate.d/mysql.conf /etc/logrotate.d/bitnami_3.4.4-1_mysql.conf
97
</code></pre>
98
99
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.4.4-1/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.4.4-1/apps/redmine/htdocs/public/images@
111
112
h1. setup service
113
114
add following service-unit @/etc/systemd/system/bitnami-redmine.service@
115
116
<pre><code class="ini">
117
[Unit]
118
Description=run bitnami redmine
119
After=network.target
120
121
[Service]
122
Type=oneshot
123
RemainAfterExit=yes
124
ExecStart=/opt/redmine-3.4.4-1/ctlscript.sh start
125
ExecStop=/opt/redmine-3.4.4-1/ctlscript.sh stop
126
127
[Install]
128
WantedBy=multi-user.target
129
</code></pre>
130
131
enable the unit by
132
133
<pre><code class="bash">
134
systemctl enable bitnami-redmine
135
</code></pre>
136
137
138
h1. Nagging
139
140
There are a couple of plugins available, we are trying to do our own thing. 
141
142
h2. create a read only user
143
144
<pre><code class="sql">
145
mysql -u root -p
146
grant select on bitnami_redmine.* to 'redmine_reader'@'localhost';
147
</code></pre>
148
149
h2. create a sql-statement
150
151
http://www.redmine.org/projects/redmine/wiki/DatabaseModel
152
!Redmine_2_5_2_2_ER-databasemodel.png!
153
154
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. 
155
156
<pre><code class="sql">
157
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
158
FROM (SELECT DISTINCT _b.id,_b.name 
159
      FROM (SELECT _p.name,_p.id 
160
            FROM projects AS _p 
161
            WHERE _p.id=33 OR _p.parent_id=33
162
           ) AS pp, projects AS _b 
163
      WHERE _b.parent_id=pp.id OR _b.id=33 ORDER BY _b.name
164
     ) AS _p,
165
     issues AS _i, 
166
     issue_statuses AS _is , 
167
     users AS _u,
168
     email_addresses AS _e
169
WHERE _p.id = _i.project_id 
170
  AND _i.status_id=_is.id 
171
  AND _u.id=_i.assigned_to_id 
172
  AND _u.id=_e.user_id 
173
  AND _is.is_closed=0 
174
  AND _i.due_date<=ADDDATE(curdate(),7) 
175
ORDER BY _p.name,_i.id;
176
</code></pre>
177
178
the funny @@@n@ groups are used later on.
179
180
h2. create a html-mail
181
182
create a little shell-sript @redmine_send_mail.sh@ that
183
* fetches the data from the database
184
* forms a valid html-mail
185
* sends the mail to one recipient
186
187
<pre><code class="bash">
188
#!/bin/sh
189
190
PATH="/opt/redmine-3.4.4-1/perl/bin:/opt/redmine-3.4.4-1/git/bin:/opt/redmine-3.4.4-1/sqlite/bin:/opt/redmine-3.4.4-1/ruby/bin:/opt/redmine-3.4.4-1/subversion/bin:/opt/redmine-3.4.4-1/postgresql/bin:/opt/redmine-3.4.4-1/php/bin:/opt/redmine-3.4.4-1/mysql/bin:/opt/redmine-3.4.4-1/apache2/bin:/opt/redmine-3.4.4-1/common/bin:$PATH"
191
192
#export List from DB
193
mysql -u redmine_reader -H -B bitnami_redmine < list.sql > /tmp/redmine_mysql_output
194
195
#replace special stuff
196
sed -i -e 's/@@@1@/<a href="/g' /tmp/redmine_mysql_output
197
sed -i -e 's/@@@2@/">/g' /tmp/redmine_mysql_output
198
sed -i -e 's/@@@3@/<\/a>/g' /tmp/redmine_mysql_output
199
200
echo 'Subject: weekly audit "all open issues due within the next 7 days"' > /tmp/redmine_mail_raw
201
echo 'to: user@example.com' >> /tmp/redmine_mail_raw
202
echo 'MIME-Version: 1.0' >> /tmp/redmine_mail_raw
203
echo 'Content-Type: text/html; charset=utf-8' >> /tmp/redmine_mail_raw
204
205
echo '' >> /tmp/redmine_mail_raw
206
echo '<html>' >> /tmp/redmine_mail_raw
207
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' >> /tmp/redmine_mail_raw
208
209
#export List from DB
210
cat /tmp/redmine_mysql_output >> /tmp/redmine_mail_raw
211
echo '</html>' >> /tmp/redmine_mail_raw
212
213
#send mail
214
cat /tmp/redmine_mail_raw | sendmail -t
215
</code></pre>
216
217
h2. use cron to nag periodically
218
219
run the shell-script from above every monday at 8:00am. @/etc/cron.d/redmine_audit@
220
221
<pre><code class="bash">
222
# JKE 2014-10-22
223
#
224
# minute hour day month dayofweek
225
# m h d m d
226
# - - - - -
227
# | | | | |
228
# | | | | +-day of week (0-7) sunday=0 or 7
229
# | | | +---month (1-12)
230
# | | +-----day of month (1-31)
231
# | +-------hour (0-23)
232
# +---------min (0-59)
233
# 
234
	00	08	*	*	1	root	/usr/local/bin/redmine_send_mail.sh
235
</code></pre>