Service is not starting on Centos on boot

I have a service installed to start jasper reporting server on boot. I believe it is correctly setup.

here is the startup script placed in /etc/init.d/jasperserver

#!/bin/sh
### BEGIN INIT INFO
# Provides:          jasperserver
# Required-Start:
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start JasperServer at boot time
# Description:       Enable service provided by JasperServer.
### END INIT INFO

JASPER_HOME="/opt/jaspersoft/jasperreports-server-5.5"

case "$1" in
  start)
    if [ -f $JASPER_HOME/ctlscript.sh ]; then
      echo "Starting JasperServer"
      sudo -u ec2-user $JASPER_HOME/ctlscript.sh start
    fi
    ;;
  stop)
    if [ -f $JASPER_HOME/ctlscript.sh ]; then
      echo "Stopping JasperServer"
      sudo -u ec2-user $JASPER_HOME/ctlscript.sh stop

    fi
    ;;
  restart)
    if [ -f $JASPER_HOME/ctlscript.sh ]; then
      echo "Restarting JasperServer"
      sudo -u ec2-user $JASPER_HOME/ctlscript.sh restart
    fi
    ;;
  status)
    if [ -f $JASPER_HOME/ctlscript.sh ]; then
      sudo -u ec2-user $JASPER_HOME/ctlscript.sh status
    fi
    ;;
  *)
    echo $"Usage: $0 {start|stop|restart|status}"
    exit 1
    ;;
esac

Also, I run the command

sudo chmod +x /etc/init.d/jasperserver

I then have run the commands

sudo chkconfig --add jasperserver
sudo chkconfig jasperserver on

If I run:

chkconfig --list  | grep jasper

I see:

jasperserver    0:off   1:off   2:on    3:on    4:on    5:on    6:off

I can also run:

sudo service jasperserver (start|stop|restart) 

successfully

However when I issue a reboot, the service isn't running. I wondered if there's a way I can get logging information or enable logging to be able to tackle this.


More detail

uname -a
Linux jaspersoft.localdomain 3.10.42-52.145.amzn1.x86_64 #1 SMP Tue Jun 10 23:46:43 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

Also after adding the line:

# chkconfig: 2345 70 30

the symlinks are as follows:

[ec2-user@jaspersoft ~]$ ls -laF /etc/rc.d/rc3.d/*jasper*
lrwxrwxrwx 1 root root 22 Aug  6 08:09 /etc/rc.d/rc3.d/S70jasperserver -> ../init.d/jasperserver*

and likewise for /etc/rc.d/rc[2-5].d/jasper


I don't see a # chkconfig: - 30 60 line in your start-up script mandating the order number in the startup sequence (30) or shutdown (60) sequence.

What symlinks are being set up in /etc/rc[0-6].d/ for your service?

IIRC when none is defined prio 50 is used. That could result in trying to start your service before other dependancies have been started.


A stock CentOS installation will typically have Defaults requiretty set in /etc/sudoers. This will cause sudo -u $user $command to fail inside an init script on startup, as the script isn't necessarily running in a "complete" tty.

Usefully, CentOS provides a common init functions file (/etc/rc.d/init.d/functions) that contains the daemon function - a wrapper for running programs with different options (e.g., user, nice, pid files, etc.).

Try modifying your script as follows:

# Source function library.
. /etc/rc.d/init.d/functions

...

  start)
    if [ -f $JASPER_HOME/ctlscript.sh ]; then
      echo "Starting JasperServer"
      daemon --user $JASPER_USER $JASPER_HOME/ctlscript.sh start
    fi
  ;;

This will use runuser -s /bin/bash $user to create a shell with the correct permissions in order to run the command, neatly avoiding any environment-meddling or security issues with su or sudo.