diff --git a/History.md b/History.md index 7d5d569e00..2fab78af9a 100644 --- a/History.md +++ b/History.md @@ -13,6 +13,7 @@ * `--control` has been removed. Use `--control-url` (#1487) * `worker_directory` has been removed. Use `directory`. * `tcp_mode` has been removed without replacement. (#2169) + * Daemonization has been removed without replacement. (#2170) * Changed #connected_port to #connected_ports (#2076) * Bugfixes diff --git a/README.md b/README.md index b111ada84c..38012e486d 100644 --- a/README.md +++ b/README.md @@ -270,7 +270,7 @@ It is common to use process monitors with Puma. Modern process monitors like sys provide continuous monitoring and restarts for increased reliability in production environments: -* [tools/jungle](https://github.com/puma/puma/tree/master/tools/jungle) for sysvinit (init.d) and upstart +* [docs/jungle](https://github.com/puma/puma/tree/master/docs/jungle) for rc.d and upstart * [docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md) ## Community Extensions diff --git a/docs/deployment.md b/docs/deployment.md index 2a868b04d6..c237f93080 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -74,7 +74,9 @@ thread to become available. * haproxy: `%Th` (TLS handshake time) and `%Ti` (idle time before request) can can also be added as headers. -## Daemonizing +## Should I daemonize? + +Daemonization was removed in Puma 5.0. For alternatives, continue reading. I prefer to not daemonize my servers and use something like `runit` or `upstart` to monitor them as child processes. This gives them fast response to crashes and diff --git a/docs/jungle/README.md b/docs/jungle/README.md new file mode 100644 index 0000000000..dcb3822670 --- /dev/null +++ b/docs/jungle/README.md @@ -0,0 +1,13 @@ +# Puma as a service + +## Upstart + +See `/docs/jungle/upstart` for Ubuntu's upstart scripts. + +## Systemd + +See [/docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md). + +## rc.d + +See `/docs/jungle/rc.d` for FreeBSD's rc.d scripts diff --git a/tools/jungle/rc.d/README.md b/docs/jungle/rc.d/README.md similarity index 100% rename from tools/jungle/rc.d/README.md rename to docs/jungle/rc.d/README.md diff --git a/tools/jungle/rc.d/puma b/docs/jungle/rc.d/puma similarity index 100% rename from tools/jungle/rc.d/puma rename to docs/jungle/rc.d/puma diff --git a/tools/jungle/rc.d/puma.conf b/docs/jungle/rc.d/puma.conf similarity index 100% rename from tools/jungle/rc.d/puma.conf rename to docs/jungle/rc.d/puma.conf diff --git a/tools/jungle/upstart/README.md b/docs/jungle/upstart/README.md similarity index 100% rename from tools/jungle/upstart/README.md rename to docs/jungle/upstart/README.md diff --git a/tools/jungle/upstart/puma-manager.conf b/docs/jungle/upstart/puma-manager.conf similarity index 100% rename from tools/jungle/upstart/puma-manager.conf rename to docs/jungle/upstart/puma-manager.conf diff --git a/tools/jungle/upstart/puma.conf b/docs/jungle/upstart/puma.conf similarity index 100% rename from tools/jungle/upstart/puma.conf rename to docs/jungle/upstart/puma.conf diff --git a/docs/systemd.md b/docs/systemd.md index 88944877d4..1f5791c257 100644 --- a/docs/systemd.md +++ b/docs/systemd.md @@ -209,66 +209,6 @@ Apr 07 08:40:19 hx puma[28320]: * Activated ssl://0.0.0.0:9234?key=key.pem&cert= Apr 07 08:40:19 hx puma[28320]: Use Ctrl-C to stop ~~~~ -## Alternative Forking Configuration - -Other systems/tools might expect or need puma to be run as a -"traditional" forking server, for example so that the `pumactl` -command can be used directly and outside of systemd for -stop/start/restart. This use case is incompatible with systemd socket -activation, so it should not be configured. Below is an alternative -puma.service config sample, using `Type=forking` and the `--daemon` -flag in `ExecStart`. Here systemd is playing a role more equivalent to -SysV init.d, where it is responsible for starting Puma on boot -(multi-user.target) and stopping it on shutdown, but is not performing -continuous restarts. Therefore running Puma in cluster mode, where the -master can restart workers, is highly recommended. See the systemd -[Restart] directive for details. - -~~~~ ini -[Unit] -Description=Puma HTTP Forking Server -After=network.target - -[Service] -# Background process configuration (use with --daemon in ExecStart) -Type=forking - -# Preferably configure a non-privileged user -# User= - -# The path to the puma application root -# Also replace the "" place holders below with this path. -WorkingDirectory= - -# The command to start Puma -# (replace "" below) -ExecStart=bundle exec puma -C /shared/puma.rb --daemon - -# The command to stop Puma -# (replace "" below) -ExecStop=bundle exec pumactl -S /shared/tmp/pids/puma.state stop - -# Path to PID file so that systemd knows which is the master process -PIDFile=/shared/tmp/pids/puma.pid - -# Should systemd restart puma? -# Use "no" (the default) to ensure no interference when using -# stop/start/restart via `pumactl`. The "on-failure" setting might -# work better for this purpose, but you must test it. -# Use "always" if only `systemctl` is used for start/stop/restart, and -# reconsider if you actually need the forking config. -Restart=no - -# `puma_ctl restart` wouldn't work without this. It's because `pumactl` -# changes PID on restart and systemd stops the service afterwards -# because of the PID change. This option prevents stopping after PID -# change. -RemainAfterExit=yes - -[Install] -WantedBy=multi-user.target -~~~~ - ### capistrano3-puma By default, diff --git a/lib/puma/cli.rb b/lib/puma/cli.rb index c7ddf9dff3..45c421b1bc 100644 --- a/lib/puma/cli.rb +++ b/lib/puma/cli.rb @@ -117,11 +117,6 @@ def setup_options @control_options[:auth_token] = arg end - o.on "-d", "--daemon", "Daemonize the server into the background" do - user_config.daemonize - user_config.quiet - end - o.on "--debug", "Log lowlevel debugging information" do user_config.debug end diff --git a/lib/puma/cluster.rb b/lib/puma/cluster.rb index f535571030..b65d4c3a73 100644 --- a/lib/puma/cluster.rb +++ b/lib/puma/cluster.rb @@ -469,12 +469,7 @@ def run # @check_pipe, @suicide_pipe = Puma::Util.pipe - if daemon? - log "* Daemonizing..." - Process.daemon(true) - else - log "Use Ctrl-C to stop" - end + log "Use Ctrl-C to stop" redirect_io diff --git a/lib/puma/configuration.rb b/lib/puma/configuration.rb index 70f97e65f0..5e01c3b0aa 100644 --- a/lib/puma/configuration.rb +++ b/lib/puma/configuration.rb @@ -175,7 +175,6 @@ def puma_default_options :debug => false, :binds => ["tcp://#{DefaultTCPHost}:#{DefaultTCPPort}"], :workers => 0, - :daemon => false, :mode => :http, :worker_timeout => DefaultWorkerTimeout, :worker_boot_timeout => DefaultWorkerTimeout, diff --git a/lib/puma/dsl.rb b/lib/puma/dsl.rb index 5644ac2169..6dc9e9ecd4 100644 --- a/lib/puma/dsl.rb +++ b/lib/puma/dsl.rb @@ -210,20 +210,6 @@ def clean_thread_locals(which=true) @options[:clean_thread_locals] = which end - # Daemonize the server into the background. It's highly recommended to - # use this in combination with +pidfile+ and +stdout_redirect+. - # - # The default is "false". - # - # @example - # daemonize - # - # @example - # daemonize false - def daemonize(which=true) - @options[:daemon] = which - end - # When shutting down, drain the accept socket of pending # connections and process them. This loops over the accept # socket until there are no more read events and then stops diff --git a/lib/puma/jruby_restart.rb b/lib/puma/jruby_restart.rb index c199ac9f7d..af16d5b1f2 100644 --- a/lib/puma/jruby_restart.rb +++ b/lib/puma/jruby_restart.rb @@ -22,63 +22,5 @@ def self.chdir_exec(dir, argv) execlp(cmd, *argv) raise SystemCallError.new(FFI.errno) end - - PermKey = 'PUMA_DAEMON_PERM' - RestartKey = 'PUMA_DAEMON_RESTART' - - # Called to tell things "Your now always in daemon mode, - # don't try to reenter it." - # - def self.perm_daemonize - ENV[PermKey] = "1" - end - - def self.daemon? - ENV.key?(PermKey) || ENV.key?(RestartKey) - end - - def self.daemon_init - return true if ENV.key?(PermKey) - - return false unless ENV.key? RestartKey - - master = ENV[RestartKey] - - # In case the master disappears early - begin - Process.kill "SIGUSR2", master.to_i - rescue SystemCallError => e - end - - ENV[RestartKey] = "" - - setsid - - null = File.open "/dev/null", "w+" - STDIN.reopen null - STDOUT.reopen null - STDERR.reopen null - - true - end - - def self.daemon_start(dir, argv) - ENV[RestartKey] = Process.pid.to_s - - if k = ENV['PUMA_JRUBY_DAEMON_OPTS'] - ENV['JRUBY_OPTS'] = k - end - - cmd = argv.first - argv = ([:string] * argv.size).zip(argv).flatten - argv << :string - argv << nil - - chdir(dir) - ret = fork - return ret if ret != 0 - execlp(cmd, *argv) - raise SystemCallError.new(FFI.errno) - end end end diff --git a/lib/puma/launcher.rb b/lib/puma/launcher.rb index 20a34c1a4e..99fe1db13f 100644 --- a/lib/puma/launcher.rb +++ b/lib/puma/launcher.rb @@ -70,10 +70,6 @@ def initialize(conf, launcher_args={}) unsupported "worker mode not supported on #{RUBY_ENGINE} on this platform" end - if @options[:daemon] && Puma.windows? - unsupported 'daemon mode not supported on Windows' - end - Dir.chdir(@restart_dir) prune_bundler if prune_bundler? diff --git a/lib/puma/rack/builder.rb b/lib/puma/rack/builder.rb index 74c8aa40c2..cf00d97570 100644 --- a/lib/puma/rack/builder.rb +++ b/lib/puma/rack/builder.rb @@ -67,10 +67,6 @@ def parse!(args) options[:environment] = e } - opts.on("-D", "--daemonize", "run daemonized in the background") { |d| - options[:daemonize] = d ? true : false - } - opts.on("-P", "--pid FILE", "file to store PID") { |f| options[:pid] = ::File.expand_path(f) } diff --git a/lib/puma/runner.rb b/lib/puma/runner.rb index 004d116990..4695aa9803 100644 --- a/lib/puma/runner.rb +++ b/lib/puma/runner.rb @@ -18,10 +18,6 @@ def initialize(cli, events) @started_at = Time.now end - def daemon? - @options[:daemon] - end - def development? @options[:environment] == "development" end @@ -130,7 +126,6 @@ def load_and_bind exit 1 end - # Load the app before we daemonize. begin @app = @launcher.config.app rescue Exception => e diff --git a/lib/puma/single.rb b/lib/puma/single.rb index 6689703150..064b864d05 100644 --- a/lib/puma/single.rb +++ b/lib/puma/single.rb @@ -42,64 +42,10 @@ def stop_blocked @server.stop(true) if @server end - def jruby_daemon? - daemon? and Puma.jruby? - end - - def jruby_daemon_start - require 'puma/jruby_restart' - JRubyRestart.daemon_start(@restart_dir, @launcher.restart_args) - end - def run - already_daemon = false - - if jruby_daemon? - require 'puma/jruby_restart' - - if JRubyRestart.daemon? - # load and bind before redirecting IO so errors show up on stdout/stderr - load_and_bind - redirect_io - end - - already_daemon = JRubyRestart.daemon_init - end - output_header "single" - if jruby_daemon? - if already_daemon - JRubyRestart.perm_daemonize - else - pid = nil - - Signal.trap "SIGUSR2" do - log "* Started new process #{pid} as daemon..." - - # Must use exit! so we don't unwind and run the ensures - # that will be run by the new child (such as deleting the - # pidfile) - exit!(true) - end - - Signal.trap "SIGCHLD" do - log "! Error starting new process as daemon, exiting" - exit 1 - end - - jruby_daemon_start - sleep - end - else - if daemon? - log "* Daemonizing..." - Process.daemon(true) - redirect_io - end - - load_and_bind - end + load_and_bind Plugins.fire_background @@ -109,10 +55,9 @@ def run @server = server = start_server - unless daemon? - log "Use Ctrl-C to stop" - redirect_io - end + + log "Use Ctrl-C to stop" + redirect_io @launcher.events.fire_on_booted! diff --git a/test/shell/t2.rb b/test/shell/t2.rb index e173d9eb6f..de28730f76 100644 --- a/test/shell/t2.rb +++ b/test/shell/t2.rb @@ -1,4 +1,4 @@ -system "ruby -rrubygems -Ilib bin/pumactl -F test/shell/t2_conf.rb start" +system "ruby -rrubygems -Ilib bin/pumactl -F test/shell/t2_conf.rb start &" sleep 5 system "curl http://localhost:10103/" diff --git a/test/shell/t2_conf.rb b/test/shell/t2_conf.rb index d4de7ff704..40937207ba 100644 --- a/test/shell/t2_conf.rb +++ b/test/shell/t2_conf.rb @@ -3,4 +3,3 @@ pidfile "t2-pid" bind "tcp://0.0.0.0:10103" rackup File.expand_path('../rackup/hello.ru', File.dirname(__FILE__)) -daemonize diff --git a/tools/docker/Dockerfile b/tools/Dockerfile similarity index 100% rename from tools/docker/Dockerfile rename to tools/Dockerfile diff --git a/tools/jungle/README.md b/tools/jungle/README.md deleted file mode 100644 index 51ac163f9a..0000000000 --- a/tools/jungle/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# Puma as a service - -## Upstart - -See `/tools/jungle/upstart` for Ubuntu's upstart scripts. - -## Systemd - -See [/docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md). - -## Init.d - -Deprecatation Warning : `init.d` was replaced by `systemd` since Debian 8 and Ubuntu 16.04, you should look into [/docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md) unless you are on an older OS. - -See `/tools/jungle/init.d` for tools to use with init.d and start-stop-daemon. - -## rc.d - -See `/tools/jungle/rc.d` for FreeBSD's rc.d scripts diff --git a/tools/jungle/init.d/README.md b/tools/jungle/init.d/README.md deleted file mode 100644 index 50ca7cdacf..0000000000 --- a/tools/jungle/init.d/README.md +++ /dev/null @@ -1,61 +0,0 @@ -# Puma daemon service - -Deprecatation Warning : `init.d` was replaced by `systemd` since Debian 8 and Ubuntu 16.04, you should look into [/docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md) unless you are on an older OS. - -Init script to manage multiple Puma servers on the same box using start-stop-daemon. - -## Installation - - # Copy the init script to services directory - sudo cp puma /etc/init.d - sudo chmod +x /etc/init.d/puma - - # Make it start at boot time. - sudo update-rc.d -f puma defaults - - # Copy the Puma runner to an accessible location - sudo cp run-puma /usr/local/bin - sudo chmod +x /usr/local/bin/run-puma - - # Create an empty configuration file - sudo touch /etc/puma.conf - -## Managing the jungle - -Puma apps are held in /etc/puma.conf by default. It's mainly a CSV file and every line represents one app. Here's the syntax: - - app-path,user,config-file-path,log-file-path,environment-variables - -You can add an instance by editing the file or running the following command: - - sudo /etc/init.d/puma add /path/to/app user /path/to/app/config/puma.rb /path/to/app/log/puma.log - -The config and log paths, as well as the environment variables, are optional parameters and default to: - -* config: /path/to/app/*config/puma.rb* -* log: /path/to/app/*log/puma.log* -* environment: (empty) - -Multiple environment variables need to be separated by a semicolon, e.g. - - FOO=1;BAR=2 - -To remove an app, simply delete the line from the config file or run: - - sudo /etc/init.d/puma remove /path/to/app - -The command will make sure the Puma instance stops before removing it from the jungle. - -## Assumptions - -* The script expects a temporary folder named /path/to/app/*tmp/puma* to exist. Create it if it's not there by default. -The pid and state files should live there and must be called: *tmp/puma/pid* and *tmp/puma/state*. -You can change those if you want but you'll have to adapt the script for it to work. - -* Here's what a minimal app's config file should have: - -``` -pidfile "/path/to/app/tmp/puma/pid" -state_path "/path/to/app/tmp/puma/state" -activate_control_app -``` diff --git a/tools/jungle/init.d/puma b/tools/jungle/init.d/puma deleted file mode 100755 index 32fe85d683..0000000000 --- a/tools/jungle/init.d/puma +++ /dev/null @@ -1,421 +0,0 @@ -#! /bin/sh -### BEGIN INIT INFO -# Provides: puma -# Required-Start: $remote_fs $syslog -# Required-Stop: $remote_fs $syslog -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Puma web server -# Description: A ruby web server built for concurrency http://puma.io -# initscript to be placed in /etc/init.d. -### END INIT INFO - -# Author: DarĂ­o Javier Cravero -# -# Do NOT "set -e" - -# PATH should only include /usr/* if it runs after the mountnfs.sh script -PATH=/usr/local/bin:/usr/local/sbin/:/sbin:/usr/sbin:/bin:/usr/bin -DESC="Puma rack web server" -NAME=puma -DAEMON=$NAME -SCRIPTNAME=/etc/init.d/$NAME -CONFIG=/etc/puma.conf -JUNGLE=`cat $CONFIG` -RUNPUMA=/usr/local/bin/run-puma -USE_LOCAL_BUNDLE=0 - -# Load the VERBOSE setting and other rcS variables -. /lib/init/vars.sh - -# Define LSB log_* functions. -# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. -. /lib/lsb/init-functions - -# -# Function that starts the jungle -# -do_start() { - log_daemon_msg "=> Running the jungle..." - for i in $JUNGLE; do - dir=`echo $i | cut -d , -f 1` - do_start_one $dir - done -} - -do_start_one() { - PIDFILE=$1/tmp/puma/pid - if [ -e $PIDFILE ]; then - PID=`cat $PIDFILE` - # If the puma is running, restart it, otherwise run it. - if ps -p $PID > /dev/null; then - do_restart_one $1 - else - do_start_one_do $1 - fi - else - do_start_one_do $1 - fi -} - -do_start_one_do() { - i=`grep $1 $CONFIG` - dir=`echo $i | cut -d , -f 1` - user=`echo $i | cut -d , -f 2` - config_file=`echo $i | cut -d , -f 3` - if [ "$config_file" = "" ]; then - config_file="$dir/config/puma.rb" - fi - log_file=`echo $i | cut -d , -f 4` - if [ "$log_file" = "" ]; then - log_file="$dir/log/puma.log" - fi - environment=`echo $i | cut -d , -f 5` - - log_daemon_msg "--> Woke up puma $dir" - log_daemon_msg "user $user" - log_daemon_msg "log to $log_file" - - if [ ! -z "$environment" ]; then - for e in $(echo "$environment" | tr ';' '\n'); do - log_daemon_msg "environment $e" - v=${e%%\=*} ; eval "$e" ; export $v - done - fi - - start-stop-daemon --verbose --start --chdir $dir --chuid $user --background --exec $RUNPUMA -- $dir $config_file $log_file -} - -# -# Function that stops the jungle -# -do_stop() { - log_daemon_msg "=> Putting all the beasts to bed..." - for i in $JUNGLE; do - dir=`echo $i | cut -d , -f 1` - do_stop_one $dir - done -} -# -# Function that stops the daemon/service -# -do_stop_one() { - log_daemon_msg "--> Stopping $1" - PIDFILE=$1/tmp/puma/pid - STATEFILE=$1/tmp/puma/state - if [ -e $PIDFILE ]; then - PID=`cat $PIDFILE` - if ps -p $PID > /dev/null; then - log_daemon_msg "---> About to kill PID `cat $PIDFILE`" - if [ "$USE_LOCAL_BUNDLE" -eq 1 ]; then - cd $1 && bundle exec pumactl --state $STATEFILE stop - else - pumactl --state $STATEFILE stop - fi - # Many daemons don't delete their pidfiles when they exit. - rm -f $PIDFILE $STATEFILE - else - log_daemon_msg "---> Puma $1 isn't running." - fi - else - log_daemon_msg "---> No puma here..." - fi - return 0 -} - -# -# Function that restarts the jungle -# -do_restart() { - for i in $JUNGLE; do - dir=`echo $i | cut -d , -f 1` - do_restart_one $dir - done -} - -# -# Function that sends a SIGUSR2 to the daemon/service -# -do_restart_one() { - PIDFILE=$1/tmp/puma/pid - - if [ -e $PIDFILE ]; then - log_daemon_msg "--> About to restart puma $1" - kill -s USR2 `cat $PIDFILE` - # TODO Check if process exist - else - log_daemon_msg "--> Your puma was never playing... Let's get it out there first" - do_start_one $1 - fi - return 0 -} - -# -# Function that phased restarts the jungle -# -do_phased_restart() { - for i in $JUNGLE; do - dir=`echo $i | cut -d , -f 1` - do_phased_restart_one $dir - done -} - -# -# Function that sends a SIGUSR1 to the daemon/service -# -do_phased_restart_one() { - PIDFILE=$1/tmp/puma/pid - - if [ -e $PIDFILE ]; then - log_daemon_msg "--> About to restart puma $1" - kill -s USR1 `cat $PIDFILE` - # TODO Check if process exist - else - log_daemon_msg "--> Your puma was never playing... Let's get it out there first" - do_start_one $1 - fi - return 0 -} - -# -# Function that statuss the jungle -# -do_status() { - for i in $JUNGLE; do - dir=`echo $i | cut -d , -f 1` - do_status_one $dir - done -} - -# -# Function that sends a SIGUSR2 to the daemon/service -# -do_status_one() { - PIDFILE=$1/tmp/puma/pid - i=`grep $1 $CONFIG` - dir=`echo $i | cut -d , -f 1` - - if [ -e $PIDFILE ]; then - log_daemon_msg "--> About to status puma $1" - if [ "$USE_LOCAL_BUNDLE" -eq 1 ]; then - cd $1 && bundle exec pumactl --state $dir/tmp/puma/state stats - else - pumactl --state $dir/tmp/puma/state stats - fi - # kill -s USR2 `cat $PIDFILE` - # TODO Check if process exist - else - log_daemon_msg "--> $1 isn't there :(..." - fi - return 0 -} - -do_add() { - str="" - # App's directory - if [ -d "$1" ]; then - if [ "`grep -c "^$1" $CONFIG`" -eq 0 ]; then - str=$1 - else - echo "The app is already being managed. Remove it if you want to update its config." - exit 1 - fi - else - echo "The directory $1 doesn't exist." - exit 1 - fi - # User to run it as - if [ "`grep -c "^$2:" /etc/passwd`" -eq 0 ]; then - echo "The user $2 doesn't exist." - exit 1 - else - str="$str,$2" - fi - # Config file - if [ "$3" != "" ]; then - if [ -e $3 ]; then - str="$str,$3" - else - echo "The config file $3 doesn't exist." - exit 1 - fi - fi - # Log file - if [ "$4" != "" ]; then - str="$str,$4" - fi - - # Environment variables - if [ "$5" != "" ]; then - str="$str,$5" - fi - - # Add it to the jungle - echo $str >> $CONFIG - log_daemon_msg "Added a Puma to the jungle: $str. You still have to start it though." -} - -do_remove() { - if [ "`grep -c "^$1" $CONFIG`" -eq 0 ]; then - echo "There's no app $1 to remove." - else - # Stop it first. - do_stop_one $1 - # Remove it from the config. - sed -i "\\:^$1:d" $CONFIG - log_daemon_msg "Removed a Puma from the jungle: $1." - fi -} - -config_bundler() { - HOME="$(eval echo ~$(id -un))" - - if [ -d "$1/.rbenv/bin" ]; then - PATH="$1/.rbenv/bin:$1/.rbenv/shims:$1" - eval "$(rbenv init -)" - USE_LOCAL_BUNDLE=1 - return 0 - - elif [ -d "/usr/local/rbenv/bin" ]; then - PATH="/usr/local/rbenv/bin:/usr/local/rbenv/shims:$PATH" - eval "$(rbenv init -)" - USE_LOCAL_BUNDLE=1 - return 0 - - elif [ -d "$HOME/.rbenv/bin" ]; then - PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH" - eval "$(rbenv init -)" - USE_LOCAL_BUNDLE=1 - return 0 - - # TODO: test rvm - # elif [ -f /etc/profile.d/rvm.sh ]; then - # source /etc/profile.d/rvm.sh - # elif [ -f /usr/local/rvm/scripts/rvm ]; then - # source /etc/profile.d/rvm.sh - # elif [ -f "$HOME/.rvm/scripts/rvm" ]; then - # source "$HOME/.rvm/scripts/rvm" - # TODO: don't know what to do with chruby - # elif [ -f /usr/local/share/chruby/chruby.sh ]; then - # source /usr/local/share/chruby/chruby.sh - # if [ -f /usr/local/share/chruby/auto.sh ]; then - # source /usr/local/share/chruby/auto.sh - # fi - # if you aren't using auto, set your version here - # chruby 2.0.0 - fi - - return 1 -} - -config_bundler - -case "$1" in - start) - [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" - if [ "$#" -eq 1 ]; then - do_start - else - i=`grep $2 $CONFIG` - dir=`echo $i | cut -d , -f 1` - do_start_one $dir - fi - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; - esac - ;; - stop) - [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" - if [ "$#" -eq 1 ]; then - do_stop - else - i=`grep $2 $CONFIG` - dir=`echo $i | cut -d , -f 1` - do_stop_one $dir - fi - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; - esac - ;; - status) - # TODO Implement. - log_daemon_msg "Status $DESC" "$NAME" - if [ "$#" -eq 1 ]; then - do_status - else - i=`grep $2 $CONFIG` - dir=`echo $i | cut -d , -f 1` - do_status_one $dir - fi - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; - esac - ;; - restart) - log_daemon_msg "Restarting $DESC" "$NAME" - if [ "$#" -eq 1 ]; then - do_restart - else - i=`grep $2 $CONFIG` - dir=`echo $i | cut -d , -f 1` - do_restart_one $dir - fi - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; - esac - ;; - phased-restart) - log_daemon_msg "Restarting (phased) $DESC" "$NAME" - if [ "$#" -eq 1 ]; then - do_phased_restart - else - i=`grep $2 $CONFIG` - dir=`echo $i | cut -d , -f 1` - do_phased_restart_one $dir - fi - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; - esac - ;; - add) - if [ "$#" -lt 3 ]; then - echo "Please, specify the app's directory and the user that will run it at least." - echo " Usage: $SCRIPTNAME add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log" - echo " config and log are optionals." - exit 1 - else - do_add $2 $3 $4 $5 - fi - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; - esac - ;; - remove) - if [ "$#" -lt 2 ]; then - echo "Please, specify the app's directory to remove." - exit 1 - else - do_remove $2 - fi - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; - esac - ;; - *) - echo "Usage:" >&2 - echo " Run the jungle: $SCRIPTNAME {start|stop|status|restart|phased-restart}" >&2 - echo " Add a Puma: $SCRIPTNAME add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log" - echo " config and log are optionals." - echo " Remove a Puma: $SCRIPTNAME remove /path/to/app" - echo " On a Puma: $SCRIPTNAME {start|stop|status|restart|phased-restart} PUMA-NAME" >&2 - exit 3 - ;; -esac -: diff --git a/tools/jungle/init.d/run-puma b/tools/jungle/init.d/run-puma deleted file mode 100755 index 9b873d37a4..0000000000 --- a/tools/jungle/init.d/run-puma +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -# on system boot, and root have no rbenv installed, -# after start-stop-daemon switched to current user, we have to init rbenv -if [ -d "$HOME/.rbenv/bin" ]; then - PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH" - eval "$(rbenv init -)" -elif [ -d "/usr/local/rbenv/bin" ]; then - PATH="/usr/local/rbenv/bin:/usr/local/rbenv/shims:$PATH" - eval "$(rbenv init -)" -elif [ -f /usr/local/rvm/scripts/rvm ]; then - source /etc/profile.d/rvm.sh -elif [ -f "$HOME/.rvm/scripts/rvm" ]; then - source "$HOME/.rvm/scripts/rvm" -fi - -app=$1; config=$2; log=$3; -cd $app && exec bundle exec puma -C $config >> $log 2>&1