Last active
June 10, 2021 12:00
-
-
Save hatappi/92c27bd03ff282dbd731c0436876cb93 to your computer and use it in GitHub Desktop.
airflow webserver init script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
EXEC_SCRIPT=/opt/local/bin/airflow | |
CMDNAME=`basename $0` | |
LOG_DIR=/var/log/airflow | |
PID_DIR=/var/run | |
PID_FILE="$PID_DIR"/airflow_webserver.pid | |
LOG_FILE="$LOG_DIR"/webserver.log | |
PORT=8888 | |
RUN_USER=vagrant | |
if ! grep "^$RUN_USER:" /etc/passwd > /dev/null | |
then | |
echo "no user : $RUN_USER" | |
exit | |
fi | |
# Source function library. | |
. /etc/init.d/functions | |
# Source run_user profile | |
. /home/$RUN_USER/.bash_profile | |
test -d $LOG_DIR || mkdir $LOG_DIR; chmod -R 777 $LOG_DIR | |
RETVAL=0 | |
case "$1" in | |
start) | |
if [ ! -f "$PID_FILE" ]; then | |
echo -n "Starting Airflow WebServer" | |
sudo -u vagrant nohup $EXEC_SCRIPT webserver -p $PORT 0<&- &> $LOG_FILE & | |
ps aux | grep "airflow webserver" | grep -v grep | awk '{ print $2 }' > $PID_FILE | |
success | |
else | |
echo -n "Airflow WebServer is already running" | |
RETVAL=1 | |
failure | |
fi | |
;; | |
stop) | |
if [ -f "$PID_FILE" ]; then | |
echo -n "Stopping Airflow WebServer" | |
test -f $PID_FILE && cat $PID_FILE | xargs kill -s SIGKILL | |
ps aux | grep "gunicorn: master \[airflow.www.app:cached_app()\]" | awk '{ print $2 }' | xargs kill -s SIGKILL | |
ps aux | grep "gunicorn: worker \[airflow.www.app:cached_app()\]" | awk '{ print $2 }' | xargs kill -s SIGKILL | |
rm -f $PID_FILE | |
success | |
else | |
echo -n "Airflow WebServer is not running" | |
RETVAL=1 | |
failure | |
fi | |
echo | |
;; | |
restart) | |
$0 stop | |
$0 start | |
;; | |
status) | |
status airflow server | |
RETVAL=$? | |
;; | |
*) | |
echo "Usage: $0 {start|stop|status|restart|reload}" | |
exit 1 | |
;; | |
esac | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment