Skip to content
Snippets Groups Projects
Commit 15305227 authored by Jan Mach's avatar Jan Mach
Browse files

Improvements in provisioning scripts.

(Redmine issue: #7041)
parent 2d708954
No related branches found
No related tags found
No related merge requests found
...@@ -120,3 +120,13 @@ if ! shopt -oq posix; then ...@@ -120,3 +120,13 @@ if ! shopt -oq posix; then
. /etc/bash_completion . /etc/bash_completion
fi fi
fi fi
## Display banner and print some usefull statistics to anyone that connects via SSH:
if [ ! -z "$SSH_CONNECTION" ]; then
echo ""
echo ""
if [ -x /vagrant/.vagrantenv/system-banner.sh ]; then
/vagrant/.vagrantenv/system-banner.sh
fi
echo ""
fi
#!/bin/bash #!/bin/bash
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Installing environment suitable for Mentat development # Final provisioning of Vagrant environment suitable for Mentat development.
# #
# Copyright (C) since 2011 CESNET, z.s.p.o # Copyright (C) since 2011 CESNET, z.s.p.o
# Use of this source is governed by the MIT license, see LICENSE file. # Use of this source is governed by the MIT license, see LICENSE file.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
echo "==========> <BEGIN> finalize.sh" . /etc/default/mentat
. /etc/mentat/scripts/lib.sh
sudo -u mentat /var/mentat/venv/bin/python /vagrant/bin/mentat-dbmngr.py --command init
sudo -u mentat bash -c "source /var/mentat/venv/bin/activate ; hawat-cli db stamp head"
sudo -u mentat bash -c "source /var/mentat/venv/bin/activate ; /etc/mentat/scripts/sqldb-migrate.sh stamp head"
sudo -u mentat /var/mentat/venv/bin/python /vagrant/bin/mentat-precache.py --allow-empty echo "==========> <BEGIN> finalize.sh"
echo "==========> Bootstraping database schema and configuration"
sudo -u mentat ${MENTAT_VENV}/python /vagrant/bin/mentat-dbmngr.py --command init
sudo -u mentat bash -c "source ${MENTAT_VENV}/activate ; hawat-cli db stamp head"
sudo -u mentat bash -c "source ${MENTAT_VENV}/activate ; /etc/mentat/scripts/sqldb-migrate.sh stamp head"
/etc/mentat/scripts/sqldb-optimize.sh /etc/mentat/scripts/sqldb-optimize.sh
echo "==========> Pregenerating application data"
sudo -u mentat ${MENTAT_VENV}/python /vagrant/bin/mentat-precache.py --allow-empty
echo "==========> Tweaking database users"
sudo -u postgres psql -c "SELECT usename FROM pg_catalog.pg_user;" | grep root > /dev/null sudo -u postgres psql -c "SELECT usename FROM pg_catalog.pg_user;" | grep root > /dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Creating default PostgreSQL user 'root'" echo "Creating default PostgreSQL user 'root'"
sudo -u postgres psql -c "CREATE USER root SUPERUSER WITH PASSWORD 'root';" sudo -u postgres psql -c "CREATE USER root SUPERUSER WITH PASSWORD 'root';"
fi fi
echo "==========> Configuring Apache to serve development server"
if [ ! -L /etc/apache2/sites-enabled/site_mentat_vagrant.conf ] ; then
ensure_linked_file /vagrant/conf/apache/site_mentat_vagrant.conf /etc/apache2/sites-available/site_mentat_vagrant.conf
sed -i.bak s/APACHE_RUN_USER=www-data/APACHE_RUN_USER=mentat/g /etc/apache2/envvars
sed -i.bak s/APACHE_RUN_GROUP=www-data/APACHE_RUN_GROUP=mentat/g /etc/apache2/envvars
rm -f /etc/apache2/envvars.bak
a2enmod rewrite
a2enmod ssl
a2enmod wsgi
a2dissite 000-default.conf
a2dissite default-ssl.conf
a2ensite site_mentat_vagrant.conf
systemctl restart apache2.service
fi
echo "==========> <DONE> finalize.sh" echo "==========> <DONE> finalize.sh"
#!/bin/bash #!/bin/bash
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Installing environment suitable for Mentat development # Initial provisioning of Vagrant environment suitable for Mentat development.
# #
# Copyright (C) since 2011 CESNET, z.s.p.o # Copyright (C) since 2011 CESNET, z.s.p.o
# Use of this source is governed by the MIT license, see LICENSE file. # Use of this source is governed by the MIT license, see LICENSE file.
...@@ -8,6 +8,15 @@ ...@@ -8,6 +8,15 @@
echo "==========> <BEGIN> provision.sh" echo "==========> <BEGIN> provision.sh"
echo "==========> Configuring timezone and locales"
echo "Europe/Prague" > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata && \
sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
sed -i -e 's/# cs_CZ.UTF-8 UTF-8/cs_CZ.UTF-8 UTF-8/' /etc/locale.gen && \
echo 'LANG="en_US.UTF-8"'>/etc/default/locale && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8
echo "==========> Linking default configurations" echo "==========> Linking default configurations"
if [ ! -L /etc/default/mentat ] ; then if [ ! -L /etc/default/mentat ] ; then
ln -s /vagrant/etc/default/mentat /etc/default/mentat ln -s /vagrant/etc/default/mentat /etc/default/mentat
...@@ -18,28 +27,19 @@ fi ...@@ -18,28 +27,19 @@ fi
. /etc/default/mentat . /etc/default/mentat
. /etc/mentat/scripts/lib.sh . /etc/mentat/scripts/lib.sh
echo "==========> Configuring timezone and locales" echo "==========> Creating Mentat user for development"
echo "Europe/Prague" > /etc/timezone if ! getent passwd ${MENTAT_USER} > /dev/null 2>&1; then
dpkg-reconfigure -f noninteractive tzdata && \ useradd -m -s /bin/bash -U ${MENTAT_USER} --groups sudo
sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \ cp -pr /home/vagrant/.ssh /home/${MENTAT_USER}/
sed -i -e 's/# cs_CZ.UTF-8 UTF-8/cs_CZ.UTF-8 UTF-8/' /etc/locale.gen && \ chown -R ${MENTAT_USER}:${MENTAT_USER} /home/${MENTAT_USER}
echo 'LANG="en_US.UTF-8"'>/etc/default/locale && \ echo "%${MENTAT_USER} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/mentat
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8
echo "==========> Creating Mentat user"
if ! getent passwd mentat > /dev/null 2>&1; then
useradd -m -s /bin/bash -U mentat --groups sudo
cp -pr /home/vagrant/.ssh /home/mentat/
chown -R mentat:mentat /home/mentat
echo "%mentat ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/mentat
fi fi
echo "==========> Linking additional configuration files" echo "==========> Linking additional configuration files"
ensure_linked_file /vagrant/.vagrantenv/.bashrc /home/vagrant/.bashrc ensure_linked_file /vagrant/.vagrantenv/.bashrc /home/vagrant/.bashrc
ensure_linked_file /vagrant/.vagrantenv/.bashrc /home/mentat/.bashrc ensure_linked_file /vagrant/.vagrantenv/.bashrc /home/mentat/.bashrc
echo "==========> Installing common dependencies" echo "==========> Installing essential dependencies"
apt-get update -qq \ apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade \ && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \ && DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
...@@ -50,8 +50,6 @@ apt-get update -qq \ ...@@ -50,8 +50,6 @@ apt-get update -qq \
less \ less \
git \ git \
vim \ vim \
bash-completion \
sudo \
openssl \ openssl \
ssl-cert \ ssl-cert \
&& apt-get clean \ && apt-get clean \
...@@ -77,6 +75,8 @@ fi ...@@ -77,6 +75,8 @@ fi
echo "==========> Installing application dependencies" echo "==========> Installing application dependencies"
apt-get update -qq \ apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \ && DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
sudo \
bash-completion \
python3 \ python3 \
python3-dev \ python3-dev \
python3-setuptools \ python3-setuptools \
...@@ -117,23 +117,6 @@ if [ ! -f /etc/mentat/install.pip ] ; then ...@@ -117,23 +117,6 @@ if [ ! -f /etc/mentat/install.pip ] ; then
echo '--editable "/vagrant/"' > /etc/mentat/install.pip echo '--editable "/vagrant/"' > /etc/mentat/install.pip
fi fi
echo "==========> Configuring Apache to serve development server"
if [ ! -L /etc/apache2/sites-enabled/site_mentat_vagrant.conf ] ; then
ensure_linked_file /vagrant/conf/apache/site_mentat_vagrant.conf /etc/apache2/sites-available/site_mentat_vagrant.conf
sed -i.bak s/APACHE_RUN_USER=www-data/APACHE_RUN_USER=mentat/g /etc/apache2/envvars
sed -i.bak s/APACHE_RUN_GROUP=www-data/APACHE_RUN_GROUP=mentat/g /etc/apache2/envvars
rm -f /etc/apache2/envvars.bak
a2enmod rewrite
a2enmod ssl
a2enmod wsgi
a2dissite 000-default.conf
a2dissite default-ssl.conf
a2ensite site_mentat_vagrant.conf
systemctl restart apache2.service
fi
echo "==========> Preparing Python development environment" echo "==========> Preparing Python development environment"
if ! [ -d "${MENTAT_VENV}" ]; then if ! [ -d "${MENTAT_VENV}" ]; then
python3 -m venv "${MENTAT_VENV}" python3 -m venv "${MENTAT_VENV}"
......
echo ""
echo " ███╗ ███╗███████╗███╗ ██╗████████╗ █████╗ ████████╗"
echo " ████╗ ████║██╔════╝████╗ ██║╚══██╔══╝██╔══██╗╚══██╔══╝"
echo " ██╔████╔██║█████╗ ██╔██╗ ██║ ██║ ███████║ ██║"
echo " ██║╚██╔╝██║██╔══╝ ██║╚██╗██║ ██║ ██╔══██║ ██║"
echo " ██║ ╚═╝ ██║███████╗██║ ╚████║ ██║ ██║ ██║ ██║"
echo " ╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝"
echo " Copyright (C) since 2011 CESNET, z.s.p.o"
echo ""
echo " Welcome to Mentat development environment"
echo " https://alchemist.cesnet.cz/mentat/doc/development/html/_doclib/development.html"
echo ""
...@@ -5,11 +5,11 @@ Vagrant.configure('2') do |config| ...@@ -5,11 +5,11 @@ Vagrant.configure('2') do |config|
config.vm.hostname = 'mentat-devel.local' config.vm.hostname = 'mentat-devel.local'
config.vm.box = 'debian/contrib-buster64' config.vm.box = 'debian/contrib-buster64'
# Flask development server # Host port 5000: Flask development server
config.vm.network 'forwarded_port', guest: 5000, host: 5000 config.vm.network 'forwarded_port', guest: 5000, host: 5000
# Apache web server # Host port 4443: Apache web server
config.vm.network 'forwarded_port', guest: 443, host: 4443 config.vm.network 'forwarded_port', guest: 443, host: 4443
# Sendria # Host port 1080: Sendria mailtrap service for development
config.vm.network 'forwarded_port', guest: 1080, host: 1080 config.vm.network 'forwarded_port', guest: 1080, host: 1080
# Create a private network, which allows host-only access to the machine # Create a private network, which allows host-only access to the machine
...@@ -45,10 +45,8 @@ Vagrant.configure('2') do |config| ...@@ -45,10 +45,8 @@ Vagrant.configure('2') do |config|
bash /vagrant/packaging/debian/postinst bash /vagrant/packaging/debian/postinst
bash /vagrant/.vagrantenv/finalize.sh bash /vagrant/.vagrantenv/finalize.sh
SHELL SHELL
#config.vm.provision :ansible do |ansible|
# ansible.playbook = '.vagrantenv/provision.yml'
#end
# Automatically connect as 'mentat' user with ssh command.
VAGRANT_COMMAND = ARGV[0] VAGRANT_COMMAND = ARGV[0]
config.ssh.username = 'mentat' if VAGRANT_COMMAND == 'ssh' config.ssh.username = 'mentat' if VAGRANT_COMMAND == 'ssh'
end end
...@@ -13,8 +13,8 @@ set -e ...@@ -13,8 +13,8 @@ set -e
. /etc/default/mentat . /etc/default/mentat
# Add restricted mentat user # Add restricted mentat user
if ! getent passwd mentat > /dev/null 2>&1; then if ! getent passwd ${MENTAT_USER} > /dev/null 2>&1; then
adduser --quiet --system --home /var/mentat/spool --no-create-home --disabled-login --group mentat adduser --quiet --system --home /var/mentat/spool --no-create-home --disabled-login --group ${MENTAT_USER}
fi fi
if ! [ -d "${MENTAT_VENV}" ]; then if ! [ -d "${MENTAT_VENV}" ]; then
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment