Last active
December 7, 2021 09:00
-
-
Save marvwhere/e0e21a84cbf10fee765c93e125c731be to your computer and use it in GitHub Desktop.
passenger-standalone ubuntu installation helper files
This file contains hidden or 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
| your-domain.tld { | |
| header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" | |
| tls [email protected] | |
| root * /home/app/YOUR-ENV/current/public | |
| encode gzip | |
| @static { | |
| file | |
| path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff | |
| } | |
| header @static Cache-Control max-age=5184000 | |
| @notStatic { | |
| not { | |
| file { | |
| try_files {path} | |
| } | |
| } | |
| } | |
| reverse_proxy @notStatic unix//run/passenger/app.YOUR-ENV.sock | |
| file_server | |
| } |
This file contains hidden or 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 | |
| warn () { echo -e "$1" >&2; } | |
| usage() { | |
| cat <<EOD | |
| Usage: passenger-app <app> <command> [<args>] | |
| Commands: | |
| start Start application <app> | |
| reload Reload application <app> | |
| stop Stop application <app> | |
| restart Restart application <app> | |
| status Run passenger-status with <args> | |
| config Run passenger-config with <args> | |
| EOD | |
| } | |
| config() { | |
| exec passenger-config "$@" | |
| } | |
| status() { | |
| exec passenger-status "$@" | |
| } | |
| start() { | |
| cd "$APPDIR" | |
| exec /usr/bin/passenger start current --instance-registry-dir ${PASSENGER_INSTANCE_REGISTRY_DIR} --engine builtin --socket ${PASSENGER_INSTANCE_REGISTRY_DIR}/app.${APP}.sock --pid-file ${PASSENGER_INSTANCE_REGISTRY_DIR}/app.${APP}.pid --log-file ${APPDIR}/shared/log/passenger.log --environment ${APP} --app-file-descriptor-ulimit 65536 --ruby /usr/local/bin/ruby ${ENV_VARS} $PASSENGER_OPTS | |
| } | |
| reload() { | |
| exec passenger-config restart-app "$APPDIR" | |
| } | |
| stop() { | |
| exec /usr/bin/passenger stop --pid-file ${PASSENGER_INSTANCE_REGISTRY_DIR}/app.${APP}.pid | |
| } | |
| restart() { | |
| echo "Shutting down application ..." | |
| /usr/bin/passenger stop --pid-file ${PASSENGER_INSTANCE_REGISTRY_DIR}/app.${APP}.pid | |
| sleep 5 | |
| start | |
| } | |
| APPPATH=$1; shift | |
| ACTION=$1; shift | |
| # sanity checks | |
| [ ! "$APPPATH" ] && warn "Please specify the application to use" && exit 1 | |
| if [ "$APPPATH" == "--help" ]; then | |
| usage && exit 0 | |
| fi | |
| APP=${APPPATH##*-} | |
| APPPATH=${APPPATH//-//} | |
| if [ ! -n "$PASSENGER_APPS_ROOT" ]; then | |
| PASSENGER_APPS_ROOT="/home/app" | |
| fi | |
| if [ ! -d "$PASSENGER_APPS_ROOT" ]; then | |
| warn "Passenger applications root not found at $PASSENGER_APPS_ROOT" | |
| warn "Check the PASSENGER_APPS_ROOT environment variable" | |
| exit 1 | |
| fi | |
| APPDIR="$PASSENGER_APPS_ROOT/$APP" | |
| if [ ! -d "$APPDIR" ]; then | |
| warn "Application $APP not found at $APPDIR" | |
| exit 1 | |
| fi | |
| PASSENGER_ENV="$PASSENGER_APPS_ROOT/$APP.env" | |
| if [ ! -f "$PASSENGER_ENV" ]; then | |
| warn "Passenger environment not found at $PASSENGER_ENV" | |
| else | |
| while read env; do | |
| # Remove single and double quotes from value | |
| value="${env#*=}" | |
| stripped="${value%\"}" | |
| stripped="${stripped#\"}" | |
| ENV_VARS+=" --envvar ${env%=*}=${stripped} " | |
| done <$PASSENGER_ENV | |
| fi | |
| export PATH | |
| export GEM_HOME | |
| export GEM_PATH | |
| export PASSENGER_ROOT | |
| export PASSENGER_OPTS | |
| export PASSENGER_INSTANCE_REGISTRY_DIR | |
| export ENV_VARS | |
| case "$ACTION" in | |
| help) | |
| usage && exit 0 | |
| ;; | |
| start) | |
| start | |
| ;; | |
| reload) | |
| reload | |
| ;; | |
| stop) | |
| stop | |
| ;; | |
| restart) | |
| restart | |
| ;; | |
| status) | |
| status $@ | |
| ;; | |
| config) | |
| config $@ | |
| ;; | |
| *) | |
| usage && exit 1 | |
| ;; | |
| esac | |
This file contains hidden or 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
| [Unit] | |
| Description=Passenger Standalone Application Server | |
| After=network.target | |
| [Service] | |
| Type=simple | |
| PrivateTmp=yes | |
| User=app | |
| Group=app | |
| RuntimeDirectory=passenger | |
| RuntimeDirectoryMode=0755 | |
| Environment="PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin" | |
| Environment="PASSENGER_OPTS=" | |
| Environment="PASSENGER_INSTANCE_REGISTRY_DIR=/run/passenger" | |
| ExecStart=/usr/bin/passenger-app %i start | |
| ExecReload=/usr/bin/passenger-app %i reload | |
| ExecStop=/usr/bin/passenger-app %i stop | |
| [Install] | |
| WantedBy=multi-user.target | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment