Skip to content

Instantly share code, notes, and snippets.

@DoriftoShoes
Created June 3, 2015 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DoriftoShoes/4ee35515f5cdd549bee2 to your computer and use it in GitHub Desktop.
Save DoriftoShoes/4ee35515f5cdd549bee2 to your computer and use it in GitHub Desktop.
#!/bin/bash
MISTRAL_STABLE_BRANCH=$1
DEBTEST=`lsb_release -a 2> /dev/null | grep Distributor | awk '{print $3}'`
if [[ "$DEBTEST" == "Ubuntu" ]]; then
TYPE="debs"
PYTHONPACK="/usr/lib/python2.7/dist-packages"
echo "###########################################################################################"
echo "# Detected Distro is ${DEBTEST}"
elif [[ -f "/etc/redhat-release" ]]; then
TYPE="rpms"
PYTHONPACK="/usr/lib/python2.7/site-packages"
echo "###########################################################################################"
echo "# Detected linux distribution is RedHat compatible"
systemctl stop firewalld
systemctl disable firewalld
setenforce permissive
else
echo "Unknown Operating System"
exit 2
fi
setup_mysql() {
if [[ "$TYPE" == "debs" ]]; then
service mysql restart
elif [[ "$TYPE" == "rpms" ]]; then
service mysqld restart
fi
if [ $(mysql -uroot -e 'show databases' &> /dev/null; echo $?) == 0 ]
then
mysqladmin -u root password StackStorm
fi
mysql -uroot -pStackStorm -e "DROP DATABASE IF EXISTS mistral"
mysql -uroot -pStackStorm -e "CREATE DATABASE mistral"
mysql -uroot -pStackStorm -e "GRANT ALL PRIVILEGES ON mistral.* TO 'mistral'@'localhost' IDENTIFIED BY 'StackStorm'"
mysql -uroot -pStackStorm -e "FLUSH PRIVILEGES"
}
setup_mistral_config()
{
config=/etc/mistral/mistral.conf
if [ -e "$config" ]; then
rm $config
fi
touch $config
cat <<mistral_config >$config
[database]
connection=mysql://mistral:StackStorm@localhost/mistral
max_pool_size=50
[pecan]
auth_enable=false
mistral_config
}
setup_mistral_log_config()
{
log_config=/etc/mistral/wf_trace_logging.conf
if [ -e "$log_config" ]; then
rm $log_config
fi
cp /opt/openstack/mistral/etc/wf_trace_logging.conf.sample $log_config
sed -i "s~tmp~var/log~g" $log_config
}
setup_mistral_upstart()
{
upstart=/etc/init/mistral.conf
if [ -e "$upstart" ]; then
rm $upstart
fi
touch $upstart
cat <<mistral_upstart >$upstart
description "Mistral Workflow Service"
start on runlevel [2345]
stop on runlevel [016]
respawn
exec /opt/openstack/mistral/.venv/bin/python /opt/openstack/mistral/mistral/cmd/launch.py --config-file /etc/mistral/mistral.conf --log-config-append /etc/mistral/wf_trace_logging.conf
mistral_upstart
}
setup_mistral_systemd()
{
systemd=/etc/systemd/system/mistral.service
if [ -e "$systemd" ]; then
rm $systemd
fi
touch $systemd
cat <<mistral_systemd >$systemd
[Unit]
Description=Mistral Workflow Service
[Service]
ExecStart=/opt/openstack/mistral/.venv/bin/python /opt/openstack/mistral/mistral/cmd/launch.py --config-file /etc/mistral/mistral.conf --log-file /var/log/mistral.log --log-config-append /etc/mistral/wf_trace_logging.conf
Restart=on-abort
[Install]
WantedBy=multi-user.target
mistral_systemd
systemctl enable mistral
}
setup_mistral() {
echo "###########################################################################################"
echo "# Setting up Mistral"
# Install prerequisites.
if [[ "$TYPE" == "debs" ]]; then
apt-get -y install libssl-dev libyaml-dev libffi-dev libxml2-dev libxslt1-dev python-dev libmysqlclient-dev
elif [[ "$TYPE" == "rpms" ]]; then
yum -y install openssl-devel libyaml-devel libffi-devel libxml2-devel libxslt-devel python-devel mysql-devel
# Needed because of mysql-python library
yum -y install redhat-rpm-config
fi
# Clone mistral from github.
mkdir -p /opt/openstack
cd /opt/openstack
if [ -d "/opt/openstack/mistral" ]; then
rm -r /opt/openstack/mistral
fi
git clone -b ${MISTRAL_STABLE_BRANCH} https://github.com/StackStorm/mistral.git
# Setup virtualenv for running mistral.
cd /opt/openstack/mistral
virtualenv --no-site-packages .venv
. /opt/openstack/mistral/.venv/bin/activate
pip install -q -r requirements.txt
pip install -q mysql-python
python setup.py develop
# Setup plugins for actions.
mkdir -p /etc/mistral/actions
if [ -d "/etc/mistral/actions/st2mistral" ]; then
rm -r /etc/mistral/actions/st2mistral
fi
cd /etc/mistral/actions
git clone -b ${MISTRAL_STABLE_BRANCH} https://github.com/StackStorm/st2mistral.git
cd /etc/mistral/actions/st2mistral
python setup.py develop
# Create configuration files.
mkdir -p /etc/mistral
setup_mistral_config
setup_mistral_log_config
# Setup database.
cd /opt/openstack/mistral
setup_mysql
python ./tools/sync_db.py --config-file /etc/mistral/mistral.conf
# Setup service.
if [[ "$TYPE" == "debs" ]]; then
setup_mistral_upstart
elif [[ "$TYPE" == "rpms" ]]; then
setup_mistral_systemd
fi
# Deactivate venv.
deactivate
# Setup mistral client.
pip install -q -U git+https://github.com/StackStorm/python-mistralclient.git@${MISTRAL_STABLE_BRANCH}
}
setup_mistral
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment