# Deploy Redmine owning GMail notification and GIT integration
## Preliminary
* [Ubuntu 22.04](https://www.releases.ubuntu.com/22.04/)
* [Redmine](https://www.redmine.org/releases/)
* GMail account
---
## System Installation
System is installed in a disk, and other disks will be constructed as RAID1 and used for Redmine
* Download from the above [Ubuntu 22.04](https://www.releases.ubuntu.com/22.04/)
* Burn ISO into CDROM or USB to install
* The configuration steps after installation:
1. Time
sudo date -s "<CURRENT_TIME>"
sudo hwclock -w
2. Message display
sudo vi /etc/default/locales
# Commit all LC_ strings and only reserve LANG
3. Install essential packages
sudo apt update
sudo apt install vim net-tools mdadm
4. Prepare RAID 1
Please refer to [Soft RAID 在 Linux上的建置 - mdadm](https://hackmd.io/@cwhu/SkpHEAy9u)
5. Mount RAID 1 on /opt during booting
# This will show <RAID1_ID> on this system
ls -ld /dev/md*
# This will get UUID of RAID1
sudo blkid /dev/md<RAID1_ID>
# Let RAID1 is mounted automatically during booting
sudo vim /etc/fstab

---
## Redmini Installation
* Installing dependency
# update & upgrade
sudo apt update && sudo apt upgrade -y
# install required packages
sudo apt install -y apache2 ruby ruby-dev build-essential libapache2-mod-passenger libmysqlclient-dev
# if you want to install mysql server locally
sudo apt install -y mysql-server
* Download & Extract Redmine
# download and extract
cd ~/Downloads
wget https://redmine.org/releases/redmine-5.0.4.tar.gz
cd /opt
sudo tar -xvzf ~/Downloads/redmine-5.0.4.tar.gz
# symlink to remove version reference
sudo ln -s redmine-5.0.4 redmine
* Create a database and create a user for redmine
sudo mysql
mysql>
CREATE DATABASE redmine CHARACTER SET utf8mb4;
CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'secretPassword';
GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';
FLUSH PRIVILEGES;
mysql> quit
* Database configuration file
# copy the example file
cd /opt/redmine
cp config/database.yml.example config/database.yml
# edit config file in vi
vim config/database.yml
# Replace or update the production part
production:
adapter: mysql2
database: redmine
host: localhost
username: redmine
password: "secretPassword"
# Use "utf8" instead of "utfmb4" for MySQL prior to 5.7.7
encoding: utf8mb4
* Install Ruby dependencies in Redmine path
# install bundler
sudo gem install bundler
# install redmine bundle
sudo bundle install
* Run Redmine scripts
# generate secret token
sudo bundle exec rake generate_secret_token
# migrate database
RAILS_ENV=production bundle exec rake db:migrate
# load default data
RAILS_ENV=production bundle exec rake redmine:load_default_data
* Create an apache configuration file in /etc/apache2/sites-available (e.g. redmine.conf) with the following content
sudo vim /etc/apache2/sites-available/redmine.conf
# Create a redmine.conf and add the below content
<VirtualHost *:80>
ServerName redmine.example.com
RailsEnv production
DocumentRoot /opt/redmine/public
<Directory "/opt/redmine/public">
Allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/redmine_error.log
CustomLog ${APACHE_LOG_DIR}/redmine_access.log combined
</VirtualHost>
* Disable default config and enable the redmine config created above
# disable default apache sites
sudo a2dissite 000-default.conf
# enable redmine
sudo a2ensite redmine.conf
# reload apache
sudo systemctl reload apache2
* Test Redmine
Point your browser to the IP/DNS Name of the server and it should show the default Redmine screen. Login with admin/admin

---
## GMail configuration
Will use GMail as E-Mail notification in Redmine
* Prepare configuration.yml
cp /opt/redmine/config/configuration.yml{.example,}
* Get applicatioin password for GMail




* Modify E-Mail configuration within configuration.yml

application password will be used on "password:" part
# reload apache
sudo systemctl reload apache2
* Test E-Mail

---
## GIT integration
## Backup
Scribe a shell script where in `/backup/backup_redmine.sh` which is soft-linked `/usr/local/bin/backup_redmine` and adopt crontab schedule to execute.
Main functions are as below:
sudo /usr/bin/mysqldump -uroot -psecretPassword redmine > /opt/redmine/`date +%Y%m%d`_redmine.sql
tar -cJpPvf /backup/`date +%Y%m%d`_redmine.tar.xz /opt/redmine-5.0.4
## References
* [Soft RAID 在 Linux上的建置 - mdadm](https://hackmd.io/@cwhu/SkpHEAy9u)
* [How To Install Redmine 5.0.x on Ubuntu 20.04 with Apache2](https://redmine.org/projects/redmine/wiki/HowTo_Install_Redmine_50x_on_Ubuntu_2004_with_Apache2)
* [[教學] 如何設定 Redmine 電子信箱,開啟郵件通知功能](https://www.jinnsblog.com/2021/08/redmine-set-email-notification.html)