Skip to content

Commit

Permalink
Updating the setup scripts to work in Ubuntu and updating documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
rssanders3 committed Dec 10, 2016
1 parent 4a56af1 commit ede21f2
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 24 deletions.
9 changes: 6 additions & 3 deletions scripts/systemd/README.md
Expand Up @@ -2,17 +2,20 @@

## Steps to Deploy

### Automatic
### Scripted

Follow the instructions under the {PROJECT_HOME}/scripts/systemd/deploy/ directory
We have built scripts to help facilitate the deployment of the systemd scripts. Follow the instructions under the {PROJECT_HOME}/scripts/systemd/deploy/ directory.

### Manually

1. Login to each of the machines acting as Scheduler Failover Controllers

2. Login as root

3. Copy the **scheduler_failover_controller.service** to the **/usr/lib/systemd/system** directory
3. Copy the **scheduler_failover_controller.service** file to the systemd directory. See the bellow list for the correct location based off your environment.

* **/usr/lib/systemd/system/** for CentOS
* **/lib/systemd/system/** for Ubuntu

4. Edit the **scheduler_failover_controller.service** and change any configurations you would like

Expand Down
12 changes: 7 additions & 5 deletions scripts/systemd/deploy/README.md
Expand Up @@ -13,13 +13,15 @@ This directory contains scripts to help you deploy the systemd service scripts q

wget https://raw.githubusercontent.com/teamclairvoyant/airflow-scheduler-failover-controller/master/scripts/systemd/deploy/setup_scheduler_failover_controller_systemd_scripts.sh

2. Update the scripts with the version of Airflow and the Airflow Scheduler Failover Controller you're using
2. Update the scripts with the version of Airflow and the Airflow Scheduler Failover Controller you're using as well as the user and group you would like the job to be running as.

3. Run the scripts as Root
3. Run the scripts as Root with BASH

4. Upon completion of installing the scripts, update the **/usr/lib/systemd/system/airflow-*.service** and **/usr/lib/systemd/system/scheduler_failover_controller.service** files with the user and group you want the processes to run as.

* Note: You need to be Root to make this type of change
bash setup_airflow_systemd_scripts.sh
bash setup_scheduler_failover_controller_systemd_scripts.sh

4. You're done!


## Helpful Tips
Expand Down
65 changes: 54 additions & 11 deletions scripts/systemd/deploy/setup_airflow_systemd_scripts.sh
Expand Up @@ -2,6 +2,8 @@

AIRFLOW_VERSION="1.7.0"
REPO_ARCHIVE_URL="https://github.com/apache/incubator-airflow/archive/"
USERNAME="airflow"
GROUP="airflow"

echo "Deploying the systemd services for Airflow v${AIRFLOW_VERSION}"

Expand All @@ -22,26 +24,67 @@ unzip ${AIRFLOW_VERSION}.zip

cd incubator-airflow-${AIRFLOW_VERSION}/scripts/systemd/

echo "Deploying the Airflow config file to /etc/sysconfig/airflow"
cp airflow /etc/sysconfig/
ENV_DIR=""
POSSIBLE_ENV_DIR_LOCATIONS=( "/etc/sysconfig/" "/etc/systemd/" "/etc/default/" )
for POSSIBLE_ENV_DIR in "${POSSIBLE_ENV_DIR_LOCATIONS[@]}"; do
if [[ -a "${POSSIBLE_ENV_DIR}" ]]; then
ENV_DIR="${POSSIBLE_ENV_DIR}"
break
fi
done
if [[ "${ENV_DIR}" == "" ]]; then
echo "Unable to find a place to put the ENV_DIR"
exit 1
fi

echo "Deploying the Airflow config file to ${ENV_DIR}/airflow"
cp airflow ${ENV_DIR}

echo "Updating systemd service scripts content"
for service_file in `ls -1 *.service`; do
echo "Updating systemd service file ${service_file}"
sed -i -e "s/User=airflow/User=${USERNAME}/g" ${service_file}
sed -i -e "s/Group=airflow/Group=${GROUP}/g" ${service_file}
sed -i -e "s/EnvironmentFile=\\/etc\\/sysconfig\\/airflow/EnvironmentFile=${ENV_DIR//\//\\/}airflow/g" ${service_file}
done

SYSTEMD_SERVICES_DIR=""
POSSIBLE_SYSTEMD_SERVICES_DIR_LOCATIONS=( "/usr/lib/systemd/system/" "/lib/systemd/system/" )
for POSSIBLE_SYSTEMD_SERVICES_DIR in "${POSSIBLE_SYSTEMD_SERVICES_DIR_LOCATIONS[@]}"; do
if [[ -a ${POSSIBLE_SYSTEMD_SERVICES_DIR} ]]; then
SYSTEMD_SERVICES_DIR="${POSSIBLE_SYSTEMD_SERVICES_DIR}"
break
fi
done
if [[ "${SYSTEMD_SERVICES_DIR}" == "" ]]; then
echo "Unable to find a place to put the Systemd Service Files"
exit 1
fi

echo "Deploying systemd service files to ${SYSTEMD_SERVICES_DIR}"
cp *.service ${SYSTEMD_SERVICES_DIR}

echo "Deploying systemd service files to /usr/lib/systemd/system/"
cp *.service /usr/lib/systemd/system/
AIRFLOW_BIN="`which airflow`"

if [ "${AIRFLOW_BIN}" != "/bin/airflow" ] && ! [ -a "/bin/airflow" ]; then
if [[ "${AIRFLOW_BIN}" == "" ]]; then
echo "Airflow has not been installed. Skipping creation of Symlink."
else
ln -s ${AIRFLOW_BIN} /bin/airflow
fi
fi

echo "Deploy is complete!"
echo ""

echo "To Enable the Services to Startup Automatcially on Restart:"
for line in `ls -1 *.service`; do
echo "$ systemctl enable ${line//.service/}"
for service_file in `ls -1 *.service`; do
echo "$ systemctl enable ${service_file//.service/}"
done
echo ""

echo "To Start the Services:"
for line in `ls -1 *.service`; do
echo "$ systemctl start ${line//.service/}"
for service_file in `ls -1 *.service`; do
echo "$ systemctl start ${service_file//.service/}"
done
echo ""

echo "Please update the contents of the /usr/lib/systemd/system/airflow-*.service files with the desired user you wish to run it as:"
echo "$ sudo nano /usr/lib/systemd/system/airflow-*.service"
Expand Up @@ -2,6 +2,8 @@

SCHEDULER_FAILOVER_CONTROLLER_VERSION="v1.0.1"
REPO_ARCHIVE_URL="https://github.com/teamclairvoyant/airflow-scheduler-failover-controller/archive/"
USERNAME="airflow"
GROUP="airflow"

echo "Deploying the systemd services for Airflow Scheduler Failover Controller ${SCHEDULER_FAILOVER_CONTROLLER_VERSION}"

Expand All @@ -22,8 +24,36 @@ unzip ${SCHEDULER_FAILOVER_CONTROLLER_VERSION}.zip

cd airflow-scheduler-failover-controller-${SCHEDULER_FAILOVER_CONTROLLER_VERSION//v/}/scripts/systemd/

echo "Deploying systemd service files to /usr/lib/systemd/system/"
cp *.service /usr/lib/systemd/system/
echo "Updating systemd service scripts content"
for service_file in `ls -1 *.service`; do
echo "Updating systemd service file ${service_file}"
sed -i -e "s/User=airflow/User=${USERNAME}/g" ${service_file}
sed -i -e "s/Group=airflow/Group=${GROUP}/g" ${service_file}
done

SYSTEMD_SERVICES_DIR=""
POSSIBLE_SYSTEMD_SERVICES_DIR_LOCATIONS=( "/usr/lib/systemd/system/" "/lib/systemd/system/" )
for POSSIBLE_SYSTEMD_SERVICES_DIR in "${POSSIBLE_SYSTEMD_SERVICES_DIR_LOCATIONS[@]}"; do
if [[ -a ${POSSIBLE_SYSTEMD_SERVICES_DIR} ]]; then
SYSTEMD_SERVICES_DIR="${POSSIBLE_SYSTEMD_SERVICES_DIR}"
break
fi
done
if [[ "${SYSTEMD_SERVICES_DIR}" == "" ]]; then
echo "Unable to find a place to put the Systemd Service Files"
exit 1
fi

echo "Deploying systemd service files to ${SYSTEMD_SERVICES_DIR}"
cp *.service ${SYSTEMD_SERVICES_DIR}

if [ "${SCHEDULER_FAILOVER_CONTROLLER_VERSION_BIN}" != "/bin/scheduler_failover_controller" ] && ! [ -a "/bin/scheduler_failover_controller" ]; then
if [[ "${SCHEDULER_FAILOVER_CONTROLLER_VERSION_BIN}" == "" ]]; then
echo "The Scheduler Failover Controller has not been installed. Skipping creation of Symlink."
else
ln -s ${SCHEDULER_FAILOVER_CONTROLLER_VERSION_BIN} /bin/scheduler_failover_controller
fi
fi

echo "Deploy is complete!"
echo ""
Expand All @@ -39,6 +69,3 @@ for line in `ls -1 *.service`; do
echo "$ systemctl start ${line//.service/}"
done
echo ""

echo "Please update the contents of the /usr/lib/systemd/system/scheduler_failover_controller.service files with the desired user you wish to run it as:"
echo "$ sudo nano /usr/lib/systemd/system/scheduler_failover_controller.service"

0 comments on commit ede21f2

Please sign in to comment.