Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two scripts /etc/init.d/puma_a.sh and /etc/init.d/puma_b.sh with identical configs. I try to set both boot like this, but one of them doesn't load on boot. If I manually launch it from console it works. Any idea?

root@site:~# update-rc.d puma_a.sh defaults 98
 Adding system startup for /etc/init.d/puma_a.sh ...
   /etc/rc0.d/K98puma_a.sh -> ../init.d/puma_a.sh
   /etc/rc1.d/K98puma_a.sh -> ../init.d/puma_a.sh
   /etc/rc6.d/K98puma_a.sh -> ../init.d/puma_a.sh
   /etc/rc2.d/S98puma_a.sh -> ../init.d/puma_a.sh
   /etc/rc3.d/S98puma_a.sh -> ../init.d/puma_a.sh
   /etc/rc4.d/S98puma_a.sh -> ../init.d/puma_a.sh
   /etc/rc5.d/S98puma_a.sh -> ../init.d/puma_a.sh


#! /bin/sh

# Provides:   pumacontrol
# 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 

# Simple move this file into /etc/init.d/pumacontrol.sh
# Also make sure you `chmod +x pumacontrol.sh`.

# If you need to start puma at boot time run this in debian/ubuntu: update-rc.d pumacontrol.sh defaults
# It will create some links to execute /etc/init.d/pumacontrol.sh start at the begining

# I use this in a system where the rails app is running by a normal user,  where puma is 
# configured in PUMA_CONFIG_FILE. In PUMA_CONFIG_FILE is stated to create a pid file with the PID of 
# puma in the PUMA_PID_FILE file. The socket where nginx is redirecting the web traffic and puma is 
# listening is PUMA_SOCKET

# You need to specify a location for the PUMA_CONFIG_FILE

# /etc/init.d/puma_a.sh
PUMA_CONFIG_FILE=/var/www/site_a.com/current/config/puma.rb # WRITE HERE PUMA CONFIG FILE LOCATION
# strip out quotes, remove comments, initial spaces, and get only the filename
# if desired write here the path to the desired file for example:
# PUMA_PID_FILE=/path/foo.pid
if [ $1 -a $2 ] ; then # If passed 2 params the second one should be the puma config file

#------------------------ checkings -------------------------------------
if [ ! -r $PUMA_CONFIG_FILE ] ; then # if not readable
  echo "File $PUMA_CONFIG_FILE not found or not readable"
  echo "You should write in pumacontrol.sh the location of your config/puma.rb"
  echo "or run this script like this 'pumacontrol.sh start /path/railsapp/config/puma.rb'"
  exit 1
if [ -z $PUMA_PID_FILE ] ; then # if empty string
  echo "pidfile option in $PUMA_PID_FILE not found. You should write something like"
  echo 'pidfile "/path/puma.pid"'
  exit 1
if [ -z $PUMA_SOCKET ] ; then # if empty string
  echo "bind option in $PUMA_SOCKET not found. You should write something like"
  echo 'bind "unix://path/railsAppName.sock"'
  exit 1
if [ -z $WORKING_DIR ] ; then # if empty string
  echo "directory option in $WORKING_DIR not found. You should write something like"
  echo "directory '/path/yourRailsAppRootDir/'"
  exit 1

#------------------------ functions -------------------------------------
# check if puma process is running
puma_is_running() {
  if [ -S $PUMA_SOCKET ] ; then # if file exist and its a socket
    if [ -r $PUMA_PID_FILE ] ; then # if file exist and readable
      if cat $PUMA_PID_FILE | xargs pgrep -P > /dev/null ; then
        return 0
        echo "No puma process found"
      echo "No puma pid file found"
    echo "No puma socket found"

  return 1

#------------------------ script -------------------------------------
case "$1" in
    echo "Starting puma..."
      if [ -e $PUMA_SOCKET  ] ; then # if socket exists
        rm -f $PUMA_SOCKET
        echo "removed $PUMA_SOCKET"
      # Exec puma as the owner, so we need to be either root or the real owner"*
      if [ `whoami` = $PUMA_CONFIGFILE_OWNER ] # owner
        /bin/bash --login -c "(cd $WORKING_DIR && bundle exec puma -C $PUMA_CONFIG_FILE)" 2>&1 >> /var/log/site_a.log
      elif [ `whoami` = root ] # root
        su -l $PUMA_CONFIGFILE_OWNER -c "(cd $WORKING_DIR && bundle exec puma -C $PUMA_CONFIG_FILE)"
      else # error
        echo "you should be root or the owner of the file to have the gemset ready to start the rails stack"

    echo "done"

      if [ -e $PUMA_PID_FILE ] ; then # if pid file exists
        echo "Stopping puma..."
        /bin/bash --login -c " kill -s SIGTERM `cat $PUMA_PID_FILE` "
        echo "Killed puma PID `cat $PUMA_PID_FILE`"
        rm -f $PUMA_PID_FILE
        echo "removed $PUMA_PID_FILE"
      if [ -e $PUMA_SOCKET ] ; then # if socket exists
        rm -f $PUMA_SOCKET
        echo "removed  $PUMA_SOCKET"
    echo "done"

    if puma_is_running ; then
      echo "Hot-restarting puma..."
      if [ -e $PUMA_PID_FILE ] ; then
        /bin/bash --login -c " kill -s SIGUSR2 `cat $PUMA_PID_FILE` "
        echo "Killed puma PID `cat $PUMA_PID_FILE`"
      echo "Doublechecking the process restart..."
      sleep 5
      if puma_is_running ; then
        echo "done"
        exit 0
        echo "Puma restart failed :/"
        exit 1 # return error

    echo "Trying cold reboot"
    $0 start

    if puma_is_running ; then
      echo "puma is running"
      exit 0
      echo "puma is not running"
      exit 1 # return error

    echo "Usage: script/puma.sh {start|stop|restart|status}" >&2


ls -l /etc/init.d/puma
-rwxr-xr-x 1 root root  4995 Sep 19 20:26 puma_a.sh
-rwxr-xr-x 1 root root  4985 Sep 19 19:21 puma_b.sh

Update: By looking into the logs I can see puma is unable to launch. Its weird because when I do /etc/init.d/puma_a.sh start manually it works.

[1791] Puma starting in cluster mode...
[1791] * Version 2.5.1, codename: Astronaut Shoelaces
[1791] * Min threads: 8, max threads: 32
[1791] * Environment: production
[1791] * Process workers: 6
[1791] * Preloading application
[1791] ! Unable to load application

Update 2: Result of diff puma_{a,b}.sh

<         /bin/bash --login -c "(cd $WORKING_DIR && bundle exec puma -C $PUMA_CONFIG_FILE)" 2>&1 >> /var/log/site_a.log
>         /bin/bash --login -c "(cd $WORKING_DIR && bundle exec puma -C $PUMA_CONFIG_FILE)" 2>&1 >> /var/log/site_b.log
<         su -l $PUMA_CONFIGFILE_OWNER -c "(cd $WORKING_DIR && bundle exec puma -C $PUMA_CONFIG_FILE)" 2>&1 >> /var/log/site_a.log
>         su -l $PUMA_CONFIGFILE_OWNER -c "(cd $WORKING_DIR && bundle exec puma -C $PUMA_CONFIG_FILE)"
share|improve this question
Can you add the contents of /etc/init.d/puma_a.sh and the output of ls -l /etc/init.d/puma* to your question? – Martin von Wittich Sep 19 '13 at 21:54
@Martin von Wittich Please see updated question. – Martin Sep 19 '13 at 22:00
I can see your scripts expecting a second user argument ... Do you run it with this second argument? or just with start/stop? – Bichoy Sep 19 '13 at 22:07
just start/stop. Its weird because on of them launch automatically and the other dont. Both are the same. To launch it manually I just run /etc/init.d/puma_a.sh start – Martin Sep 19 '13 at 22:10
Just a second ... You have both of them in the boot sequence, and both launch the same daemon? Are you sure you can run multiple instance of this daemon? Basically at boot, both of them will be started. Are you able to start both of them, without stopping the other and having both running together? – Bichoy Sep 19 '13 at 22:13

You need to make the script executable in the first place.

chmod +x puma_a.sh

Putting a script in the boot sequence without execution permission will be ignored.

share|improve this answer
Already did, without that I could not launch it manually. – Martin Sep 19 '13 at 21:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.