- Yapılandırmalar eski yerinde
/etc/unicorn unicorn-multi.sh(şimdilik)/etc/unicornaltında (executable olması gerekmiyorunicorn-multibetiği/etc/init.daltında- Bu sistemin çalışması için mevcut
unicornbetiğini kaldırmak gerekmiyor ama kaldırılırsa daha güvenli olabilir.
Created
July 25, 2012 20:25
-
-
Save roktas/3178449 to your computer and use it in GitHub Desktop.
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/sh | |
| ### BEGIN INIT INFO | |
| # Provides: unicorn | |
| # Required-Start: $local_fs $remote_fs | |
| # Required-Stop: $local_fs $remote_fs | |
| # Default-Start: 2 3 4 5 | |
| # Default-Stop: 0 1 6 | |
| # Short-Description: unicorn initscript | |
| # Description: unicorn | |
| ### END INIT INFO | |
| set -e | |
| NAME=unicorn-multi | |
| DESC="Unicorn web server for multiple applications" | |
| . /lib/lsb/init-functions | |
| if [ -f /etc/default/unicorn-multi ]; then | |
| . /etc/default/unicorn-multi | |
| fi | |
| RUNNER=/etc/unicorn/unicorn-multi.sh | |
| CONFDIR=${CONFDIR-/etc/unicorn} | |
| [ -f $RUNNER ] || exit_with_message "Unicorn initializer $RUNNER is not exist." | |
| [ -d $CONFDIR ] || exit_with_message "Configuration directory $CONFDIR is not exist." | |
| list() { | |
| local f | |
| for f in ${CONFDIR}/${1}; do | |
| case "$f" in | |
| "${CONFDIR}/"'*' | *.* | *[A-Z]*) | |
| continue | |
| ;; | |
| *) | |
| [ -f "$f" ] || continue | |
| echo "$f" | |
| ;; | |
| esac | |
| done | |
| } | |
| run() { | |
| sh $RUNNER "$1" "$2" || { | |
| log_warning_msg "Action $1 failed for configuration $2" || true | |
| ERR=1 | |
| } | |
| } | |
| ERR= | |
| if [ $# -ge 1 ]; then | |
| conffiles=$(list ${2-'*'}) | |
| if [ -n "$conffiles" ]; then | |
| for conf in $conffiles; do | |
| run "$1" "$conf" | |
| done | |
| else | |
| log_warning_msg "No configuration file found." || true | |
| ERR=1 | |
| fi | |
| else | |
| log_action_msg "Usage: $0 <start|stop|restart|force-reload|reload|force-stop|reopen-logs|status> [<conffile>]" || true | |
| ERR=1 | |
| fi | |
| exit $ERR |
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/sh | |
| set -e | |
| . /lib/lsb/init-functions | |
| usage() { | |
| log_action_msg "Usage: $0 <start|stop|restart|force-reload|reload|force-stop|reopen-logs|status> <conffile>" || true | |
| exit 1 | |
| } | |
| [ $# -eq 2 ] || usage | |
| [ -f "$2" ] || exit_with_message "Configuration file '$2' not found." | |
| ACTION=$1 | |
| CONFFILE=$2 | |
| APP_NAME=${CONFFILE##*/} | |
| NAME=unicorn | |
| DESC="Unicorn web server for $APP_NAME" | |
| . $CONFFILE | |
| DAEMON=/usr/bin/unicorn | |
| PID=${PID-/run/unicorn-${APP_NAME}.pid} | |
| run_by_init() { | |
| ([ "${previous-}" ] && [ "${runlevel-}" ]) || [ "${runlevel-}" = S ] | |
| } | |
| exit_with_message() { | |
| if ! run_by_init; then | |
| log_action_msg "$1 Not starting." | |
| fi | |
| exit 0 | |
| } | |
| check_app_root() { | |
| if ! [ -d $APP_ROOT ]; then | |
| exit_with_message "Application directory $APP_ROOT is not exist." | |
| fi | |
| } | |
| set -u | |
| case "$ACTION" in | |
| start) | |
| check_app_root | |
| log_daemon_msg "Starting $DESC" $NAME || true | |
| if start-stop-daemon --start --quiet --oknodo --pidfile $PID --exec $DAEMON -- $UNICORN_OPTS; then | |
| log_end_msg 0 || true | |
| else | |
| log_end_msg 1 || true | |
| fi | |
| ;; | |
| stop) | |
| log_daemon_msg "Stopping $DESC" $NAME || true | |
| if start-stop-daemon --stop --signal QUIT --quiet --oknodo --pidfile $PID; then | |
| log_end_msg 0 || true | |
| else | |
| log_end_msg 1 || true | |
| fi | |
| ;; | |
| force-stop) | |
| log_daemon_msg "Forcing stop of $DESC" $NAME || true | |
| if start-stop-daemon --stop --quiet --oknodo --pidfile $PID; then | |
| log_end_msg 0 || true | |
| else | |
| log_end_msg 1 || true | |
| fi | |
| ;; | |
| restart|force-reload) | |
| log_daemon_msg "Restarting $DESC" $NAME || true | |
| start-stop-daemon --stop --quiet --oknodo --pidfile $PID | |
| sleep 1 | |
| if start-stop-daemon --start --quiet --oknodo --pidfile $PID --exec $DAEMON -- $UNICORN_OPTS; then | |
| log_end_msg 0 || true | |
| else | |
| log_end_msg 1 || true | |
| fi | |
| ;; | |
| reload) | |
| log_daemon_msg "Reloading $DESC" $NAME || true | |
| if start-stop-daemon --stop --signal HUP --quiet --oknodo --pidfile $PID; then | |
| log_end_msg 0 || true | |
| else | |
| log_end_msg 1 || true | |
| fi | |
| ;; | |
| reopen-logs) | |
| log_daemon_msg "Relopening log files of $DESC" $NAME || true | |
| if start-stop-daemon --stop --signal USR1 --quiet --oknodo --pidfile $PID; then | |
| log_end_msg 0 || true | |
| else | |
| log_end_msg 1 || true | |
| fi | |
| ;; | |
| status) | |
| status_of_proc -p $PID $DAEMON $NAME && exit 0 || exit $? | |
| ;; | |
| *) | |
| usage | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment