Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save diegocortassa/6a0adca6f9abaddbe76f4ee73b82072d to your computer and use it in GitHub Desktop.
Save diegocortassa/6a0adca6f9abaddbe76f4ee73b82072d to your computer and use it in GitHub Desktop.
Tatctic install - Centos 7 - Python 3 virtualenv - Postgres 11 in docker
##
## A recipe to install tactic 4.7 BETA
##
## This is not a script, commands are supposed to be lunched one by one
## some commanda will ask for interactive input.
##
## --- First install a centos 7 minimal 64bit
## --- login as root
# Disable selinux (only for test environments!)
sed -i 's/enforcing/disabled/g' /etc/selinux/config
# Open used ports
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --reload
#
yum -y update
reboot
##
## -- Install utility packages
yum -y install httpd ImageMagick unzip git vim
# ffmpeg
curl -L -O https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
tar xf ffmpeg-release-amd64-static.tar.xz
cp ffmpeg-*-static/ffmpeg ffmpeg-*-static/ffprobe ffmpeg-*-static/qt-faststart /usr/local/bin/
rm -rf ffmpeg-*-static*
##
## -- Install docker and postgres (needed for postgres >9.5 as tactic 4.7 uses jsonb datatype)
yum -y install postgresql-contrib docker
systemctl start docker
systemctl enable docker
docker run -p 5432:5432 -v /home/apache/postgres-data:/var/lib/postgresql/data --name tactic-postgres -t -d postgres:11
## NOTE, to connect to db with command line use:
## docker exec -it --user=postgres tactic-postgres psql
##
### -- Create a virtualenv for tactic
yum -y install gcc openldap-devel centos-release-scl
yum -y install rh-python36
source /opt/rh/rh-python36/enable
python3 -m venv /home/apache/tactic-python3-venv
source /home/apache/tactic-python3-venv/bin/activate
pip install psycopg2-binary pillow lxml python-ldap pycryptodomex six pytz jaraco.functools
###
## -- Install tactic
git clone --depth 1 --branch 4.7 https://github.com/Southpaw-TACTIC/TACTIC.git
/home/apache/tactic-python3-venv/bin/python TACTIC/src/install/install.py --defaults
rm -f /home/apache/tactic_data/config/tactic-license.xml
cp TACTIC/src/install/start/config/tactic-license.xml /home/apache/tactic_data/config/tactic-license.xml
# edit /home/apache/tactic_data/config/tactic-conf.xml
# change
<python>python</python>
# to
<python>/home/apache/tactic-python3-venv/bin/python</python>
###
## -- Configure apache
cp /home/apache/tactic_data/config/tactic.conf /etc/httpd/conf.d/
## Launch apache
systemctl enable httpd
systemctl start httpd
###
# You can test tactic with:
# activate apache user
chsh -s /bin/bash apache
su - apache -c "/home/apache/tactic-python3-venv/bin/python /home/apache/tactic/src/bin/startup_dev.py"
# ctrl-c to exit
## Create /etc/systemd/system/docker_tactic-postgres.service
########################################
[Unit]
Description=Tactic database Server
After=docker.service
Requires=docker.service
[Service]
RemainAfterExit=yes
ExecStart=/usr/bin/docker start tactic-postgres
ExecStop=/usr/bin/docker stop tactic-postgres
[Install]
WantedBy=multi-user.target
########################################
## Create /etc/systemd/system/tactic.service:
########################################
[Unit]
Description=Tactic Server
After=syslog.target network.target docker_tactic-postgres.service
Requires=docker_tactic-postgres.service
[Service]
Type=simple
Restart=always
StandardOutput=syslog
SyslogIdentifier=Tactic
WorkingDirectory=/home/apache
User=apache
UMask=0002
#ExecStart=/home/apache/pypy-venv-7.1.0/bin/pypy /home/apache/tactic/src/bin/monitor.py
ExecStart=/home/apache/tactic-python3-venv/bin/python /home/apache/tactic/src/bin/monitor.py
[Install]
WantedBy=multi-user.target
########################################
# Start tactic
systemctl daemon-reload
systemctl enable tactic
systemctl start tactic
## Log rotation
vim /etc/logrotate.d/tactic
###
/home/apache/tactic_temp/log/stdout.log {
su apache apache
copytruncate
missingok
notifempty
compress
}
/home/apache/tactic_temp/log/stderr.log {
su apache apache
copytruncate
missingok
notifempty
compress
}
/home/apache/tactic_temp/log/tactic_ldap.log {
su apache apache
copytruncate
missingok
notifempty
compress
}
###
chown root:root /etc/logrotate.d/tactic
chmod 0644 /etc/logrotate.d/tactic
## Clean temp files
vim /etc/crontab
###
0 6 * * * root /root/backup_tactic.sh
0 4 * * * root find /home/apache/tactic_temp/temp -mindepth 1 -maxdepth 1 -mtime +2 -exec rm -rf {} \;
10 4 * * * root find /home/apache/tactic_temp/upload -mindepth 1 -maxdepth 1 -mtime +2 -exec rm -rf {} \;
20 4 * * * root find /home/apache/tactic_temp/cache -mindepth 1 -maxdepth 1 -mtime +2 -exec rm -rf {} \;
###
##########################################################
## Sync and old tactic with a clean the new installation:
## on the NEW server reset the postgres server and delete db:
unalias cp
systemctl stop tactic
docker stop tactic-postgres
docker rm tactic-postgres
rm -rf /home/apache/postgres-data
docker run -p 5432:5432 -v /home/apache/postgres-data:/var/lib/postgresql/data --name tactic-postgres -t -d postgres:11
# on the OLD server dump the db:
pg_dumpall > db_dump.sql
# or if the old server is using docker
docker exec -i --user=postgres tactic-postgres pg_dumpall > db_dump.sql
# copy db_dump.sql to the NEW server
# Copy any asset or setup any remote filesystem for asset storage
# on the NEW server restore the db:
cat db_dump.sql | docker exec -i --user=postgres tactic-postgres psql
# Upgrade the db:
su - apache -c "/home/apache/tactic-python3-venv/bin/python /home/apache/tactic/src/bin/upgrade_db.py"
systemctl start tactic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment