Starting Tomcat Service when starting CentOS/RHEL/Fedora The 2019 Stack Overflow Developer...

How can I autofill dates in Excel excluding Sunday?

When should I buy a clipper card after flying to OAK?

Am I thawing this London Broil safely?

Why do we hear so much about the Trump administration deciding to impose and then remove tariffs?

Does a dangling wire really electrocute me if I'm standing in water?

Is bread bad for ducks?

Which Sci-Fi work first showed weapon of galactic-scale mass destruction?

Shouldn't "much" here be used instead of "more"?

Feature engineering suggestion required

Can a rogue use sneak attack with weapons that have the thrown property even if they are not thrown?

Pokemon Turn Based battle (Python)

Can a flute soloist sit?

Are there any other methods to apply to solving simultaneous equations?

Why did Acorn's A3000 have red function keys?

How technical should a Scrum Master be to effectively remove impediments?

Did Section 31 appear in Star Trek: The Next Generation?

How to answer pointed "are you quitting" questioning when I don't want them to suspect

What does ひと匙 mean in this manga and has it been used colloquially?

A poker game description that does not feel gimmicky

Does the shape of a die affect the probability of a number being rolled?

The difference between dialogue marks

Right tool to dig six foot holes?

Is a "Democratic" Oligarchy-Style System Possible?

Return to UK after being refused entry years previously



Starting Tomcat Service when starting CentOS/RHEL/Fedora



The 2019 Stack Overflow Developer Survey Results Are InWhat's the difference between /sbin/nologin and /bin/falseCentOS VPS not starting after installing zPanelRunning tomcat under tomcat service account in CentOSCreating Group and User for Tomcat RHEL/CentOSCentOS 6 stuck at starting service (sendmail) & cannot loginOpenfire Service Starting then crashing on CentOSStarting Tomcat 8 on Raspbian - Job for tomcat8.service failedCan not open tomcat default page CentOSCan't start tomcat in digital ocean's CentOS server?Solaris 5.10 shell replacement for Centos 7 migrationTomcat startup.sh file works but starting tomcat.service does not





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







3















I want to install tomcat 8 and run it at startup time



I am following these tutorials:




  1. Install Tomcat 7 on CentOS, RHEL, or Fedora

  2. How to install Tomcat 8 on a CentOS 6 VPS


I created the tomcat user:



# useradd -U -r -M -d /usr/local/ServerWeb/tomcat -s /sbin/nologin tomcat


The file was in /etc/init.d/tomcat



In the option 1:



#!/bin/bash  
# description: Tomcat Start Stop Restart
# processname: tomcat
# chkconfig: 234 20 80
JAVA_HOME=/opt/jdk
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
TOMCAT_HOME=/usr/local/tomcat
TOMCAT_USER=tomcat

case $1 in
start)
/bin/su $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh
;;
stop)
/bin/su $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh
;;
restart)
/bin/su $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh
/bin/su $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh
;;
esac
exit 0


In the Option 2:



#!/bin/bash
#
# tomcat
#
# chkconfig: - 80 20
#
### BEGIN INIT INFO
# Provides: tomcat
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start:
# Default-Stop:
# Description: Tomcat
# Short-Description: start and stop tomcat
### END INIT INFO

## Source function library.
#. /etc/rc.d/init.d/functions
export JAVA_HOME=/opt/jdk
export JAVA_OPTS="-Dfile.encoding=UTF-8
-Dnet.sf.ehcache.skipUpdateCheck=true
-XX:+UseConcMarkSweepGC
-XX:+CMSClassUnloadingEnabled
-XX:+UseParNewGC
-XX:MaxPermSize=128m
-Xms512m -Xmx512m"
export PATH=$JAVA_HOME/bin:$PATH
TOMCAT_HOME=/usr/local/tomcat
TOMCAT_USER=tomcat
SHUTDOWN_WAIT=20

tomcat_pid() {
echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'`
}

start() {
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo "Tomcat is already running (pid: $pid)"
else
# Start tomcat
echo "Starting tomcat"
ulimit -n 100000
umask 007
/bin/su -p -s /bin/sh $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh
fi


return 0
}

stop() {
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo "Stoping Tomcat"
/bin/su -p -s /bin/sh $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh

let kwait=$SHUTDOWN_WAIT
count=0;
until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
do
echo -n -e "nwaiting for processes to exit";
sleep 1
let count=$count+1;
done

if [ $count -gt $kwait ]; then
echo -n -e "nkilling processes which didn't stop after $SHUTDOWN_WAIT seconds"
kill -9 $pid
fi
else
echo "Tomcat is not running"
fi

return 0
}

case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo "Tomcat is running with pid: $pid"
else
echo "Tomcat is not running"
fi
;;
esac
exit 0


I don't understand why this is needed in the start of option 2:



ulimit -n 100000
umask 007


I changed the ownership with chown -Rvh tomcat: /usr/local/tomcat/



Later



# chmod +x /etc/init.d/tomcat
# chkconfig --add tomcat`


But after restarting the CentOS 6.6, the service is not running.



Testing:



$ echo $JAVA_HOME
$

$ echo $PATH
/usr/lib/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/IntUser/bin
$


In other words $JAVA_HOME and $PATH aren't assigned!!!



Trying to start manually (I did not assign password to tomcat user, which password should I use?):



$ service tomcat start
Password:
/bin/su: incorrect password
$


Running as root, I was checking:



# service tomcat start
This account is currently not available.
#


Checking the account:



# finger tomcat
Login: tomcat Name: Tomcat User
Directory: /usr/local/tomcat Shell: /sbin/nologin
Never logged in.
No mail.
No Plan.
#


# more /etc/passwd | grep tomcat
tomcat:x:493:490:Tomcat User:/usr/local/tomcat:/sbin/nologin
#


Checking the ownership:



# ls -al /usr/local/tomcat/
total 120
drwxr-xr-x. 9 tomcat tomcat 4096 Jun 27 09:29 .
drwxr-xr-x. 20 root root 4096 Jun 27 09:29 ..
drwxr-xr-x. 2 tomcat tomcat 4096 Jun 27 09:29 bin
drwxr-xr-x. 3 tomcat tomcat 4096 Jun 27 11:04 conf
drwxr-xr-x. 2 tomcat tomcat 4096 Jun 27 09:29 lib
-rw-r--r--. 1 tomcat tomcat 56977 May 19 15:03 LICENSE
drwxr-xr-x. 2 tomcat tomcat 4096 Jun 27 11:04 logs
-rw-r--r--. 1 tomcat tomcat 1397 May 19 15:03 NOTICE
-rw-r--r--. 1 tomcat tomcat 6741 May 19 15:03 RELEASE-NOTES
-rw-r--r--. 1 tomcat tomcat 16204 May 19 15:03 RUNNING.txt
drwxr-xr-x. 2 tomcat tomcat 4096 Jun 27 09:29 temp
drwxr-xr-x. 7 tomcat tomcat 4096 May 19 15:00 webapps
drwxr-xr-x. 3 tomcat tomcat 4096 Jun 27 11:04 work
#


Please help me.



Question 1:
The script was created in: /etc/init.d/tomcat. Why were $JAVA_HOME and $PATH not assigned?



Question 2
Is there a method to install a service without root privileges, that starts at boot time without intervention (e.g., sudo, su, etc)?










share|improve this question
















bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






















    3















    I want to install tomcat 8 and run it at startup time



    I am following these tutorials:




    1. Install Tomcat 7 on CentOS, RHEL, or Fedora

    2. How to install Tomcat 8 on a CentOS 6 VPS


    I created the tomcat user:



    # useradd -U -r -M -d /usr/local/ServerWeb/tomcat -s /sbin/nologin tomcat


    The file was in /etc/init.d/tomcat



    In the option 1:



    #!/bin/bash  
    # description: Tomcat Start Stop Restart
    # processname: tomcat
    # chkconfig: 234 20 80
    JAVA_HOME=/opt/jdk
    export JAVA_HOME
    PATH=$JAVA_HOME/bin:$PATH
    export PATH
    TOMCAT_HOME=/usr/local/tomcat
    TOMCAT_USER=tomcat

    case $1 in
    start)
    /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh
    ;;
    stop)
    /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh
    ;;
    restart)
    /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh
    /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh
    ;;
    esac
    exit 0


    In the Option 2:



    #!/bin/bash
    #
    # tomcat
    #
    # chkconfig: - 80 20
    #
    ### BEGIN INIT INFO
    # Provides: tomcat
    # Required-Start: $network $syslog
    # Required-Stop: $network $syslog
    # Default-Start:
    # Default-Stop:
    # Description: Tomcat
    # Short-Description: start and stop tomcat
    ### END INIT INFO

    ## Source function library.
    #. /etc/rc.d/init.d/functions
    export JAVA_HOME=/opt/jdk
    export JAVA_OPTS="-Dfile.encoding=UTF-8
    -Dnet.sf.ehcache.skipUpdateCheck=true
    -XX:+UseConcMarkSweepGC
    -XX:+CMSClassUnloadingEnabled
    -XX:+UseParNewGC
    -XX:MaxPermSize=128m
    -Xms512m -Xmx512m"
    export PATH=$JAVA_HOME/bin:$PATH
    TOMCAT_HOME=/usr/local/tomcat
    TOMCAT_USER=tomcat
    SHUTDOWN_WAIT=20

    tomcat_pid() {
    echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'`
    }

    start() {
    pid=$(tomcat_pid)
    if [ -n "$pid" ]
    then
    echo "Tomcat is already running (pid: $pid)"
    else
    # Start tomcat
    echo "Starting tomcat"
    ulimit -n 100000
    umask 007
    /bin/su -p -s /bin/sh $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh
    fi


    return 0
    }

    stop() {
    pid=$(tomcat_pid)
    if [ -n "$pid" ]
    then
    echo "Stoping Tomcat"
    /bin/su -p -s /bin/sh $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh

    let kwait=$SHUTDOWN_WAIT
    count=0;
    until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
    do
    echo -n -e "nwaiting for processes to exit";
    sleep 1
    let count=$count+1;
    done

    if [ $count -gt $kwait ]; then
    echo -n -e "nkilling processes which didn't stop after $SHUTDOWN_WAIT seconds"
    kill -9 $pid
    fi
    else
    echo "Tomcat is not running"
    fi

    return 0
    }

    case $1 in
    start)
    start
    ;;
    stop)
    stop
    ;;
    restart)
    stop
    start
    ;;
    status)
    pid=$(tomcat_pid)
    if [ -n "$pid" ]
    then
    echo "Tomcat is running with pid: $pid"
    else
    echo "Tomcat is not running"
    fi
    ;;
    esac
    exit 0


    I don't understand why this is needed in the start of option 2:



    ulimit -n 100000
    umask 007


    I changed the ownership with chown -Rvh tomcat: /usr/local/tomcat/



    Later



    # chmod +x /etc/init.d/tomcat
    # chkconfig --add tomcat`


    But after restarting the CentOS 6.6, the service is not running.



    Testing:



    $ echo $JAVA_HOME
    $

    $ echo $PATH
    /usr/lib/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/IntUser/bin
    $


    In other words $JAVA_HOME and $PATH aren't assigned!!!



    Trying to start manually (I did not assign password to tomcat user, which password should I use?):



    $ service tomcat start
    Password:
    /bin/su: incorrect password
    $


    Running as root, I was checking:



    # service tomcat start
    This account is currently not available.
    #


    Checking the account:



    # finger tomcat
    Login: tomcat Name: Tomcat User
    Directory: /usr/local/tomcat Shell: /sbin/nologin
    Never logged in.
    No mail.
    No Plan.
    #


    # more /etc/passwd | grep tomcat
    tomcat:x:493:490:Tomcat User:/usr/local/tomcat:/sbin/nologin
    #


    Checking the ownership:



    # ls -al /usr/local/tomcat/
    total 120
    drwxr-xr-x. 9 tomcat tomcat 4096 Jun 27 09:29 .
    drwxr-xr-x. 20 root root 4096 Jun 27 09:29 ..
    drwxr-xr-x. 2 tomcat tomcat 4096 Jun 27 09:29 bin
    drwxr-xr-x. 3 tomcat tomcat 4096 Jun 27 11:04 conf
    drwxr-xr-x. 2 tomcat tomcat 4096 Jun 27 09:29 lib
    -rw-r--r--. 1 tomcat tomcat 56977 May 19 15:03 LICENSE
    drwxr-xr-x. 2 tomcat tomcat 4096 Jun 27 11:04 logs
    -rw-r--r--. 1 tomcat tomcat 1397 May 19 15:03 NOTICE
    -rw-r--r--. 1 tomcat tomcat 6741 May 19 15:03 RELEASE-NOTES
    -rw-r--r--. 1 tomcat tomcat 16204 May 19 15:03 RUNNING.txt
    drwxr-xr-x. 2 tomcat tomcat 4096 Jun 27 09:29 temp
    drwxr-xr-x. 7 tomcat tomcat 4096 May 19 15:00 webapps
    drwxr-xr-x. 3 tomcat tomcat 4096 Jun 27 11:04 work
    #


    Please help me.



    Question 1:
    The script was created in: /etc/init.d/tomcat. Why were $JAVA_HOME and $PATH not assigned?



    Question 2
    Is there a method to install a service without root privileges, that starts at boot time without intervention (e.g., sudo, su, etc)?










    share|improve this question
















    bumped to the homepage by Community yesterday


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      3












      3








      3


      2






      I want to install tomcat 8 and run it at startup time



      I am following these tutorials:




      1. Install Tomcat 7 on CentOS, RHEL, or Fedora

      2. How to install Tomcat 8 on a CentOS 6 VPS


      I created the tomcat user:



      # useradd -U -r -M -d /usr/local/ServerWeb/tomcat -s /sbin/nologin tomcat


      The file was in /etc/init.d/tomcat



      In the option 1:



      #!/bin/bash  
      # description: Tomcat Start Stop Restart
      # processname: tomcat
      # chkconfig: 234 20 80
      JAVA_HOME=/opt/jdk
      export JAVA_HOME
      PATH=$JAVA_HOME/bin:$PATH
      export PATH
      TOMCAT_HOME=/usr/local/tomcat
      TOMCAT_USER=tomcat

      case $1 in
      start)
      /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh
      ;;
      stop)
      /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh
      ;;
      restart)
      /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh
      /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh
      ;;
      esac
      exit 0


      In the Option 2:



      #!/bin/bash
      #
      # tomcat
      #
      # chkconfig: - 80 20
      #
      ### BEGIN INIT INFO
      # Provides: tomcat
      # Required-Start: $network $syslog
      # Required-Stop: $network $syslog
      # Default-Start:
      # Default-Stop:
      # Description: Tomcat
      # Short-Description: start and stop tomcat
      ### END INIT INFO

      ## Source function library.
      #. /etc/rc.d/init.d/functions
      export JAVA_HOME=/opt/jdk
      export JAVA_OPTS="-Dfile.encoding=UTF-8
      -Dnet.sf.ehcache.skipUpdateCheck=true
      -XX:+UseConcMarkSweepGC
      -XX:+CMSClassUnloadingEnabled
      -XX:+UseParNewGC
      -XX:MaxPermSize=128m
      -Xms512m -Xmx512m"
      export PATH=$JAVA_HOME/bin:$PATH
      TOMCAT_HOME=/usr/local/tomcat
      TOMCAT_USER=tomcat
      SHUTDOWN_WAIT=20

      tomcat_pid() {
      echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'`
      }

      start() {
      pid=$(tomcat_pid)
      if [ -n "$pid" ]
      then
      echo "Tomcat is already running (pid: $pid)"
      else
      # Start tomcat
      echo "Starting tomcat"
      ulimit -n 100000
      umask 007
      /bin/su -p -s /bin/sh $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh
      fi


      return 0
      }

      stop() {
      pid=$(tomcat_pid)
      if [ -n "$pid" ]
      then
      echo "Stoping Tomcat"
      /bin/su -p -s /bin/sh $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh

      let kwait=$SHUTDOWN_WAIT
      count=0;
      until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
      do
      echo -n -e "nwaiting for processes to exit";
      sleep 1
      let count=$count+1;
      done

      if [ $count -gt $kwait ]; then
      echo -n -e "nkilling processes which didn't stop after $SHUTDOWN_WAIT seconds"
      kill -9 $pid
      fi
      else
      echo "Tomcat is not running"
      fi

      return 0
      }

      case $1 in
      start)
      start
      ;;
      stop)
      stop
      ;;
      restart)
      stop
      start
      ;;
      status)
      pid=$(tomcat_pid)
      if [ -n "$pid" ]
      then
      echo "Tomcat is running with pid: $pid"
      else
      echo "Tomcat is not running"
      fi
      ;;
      esac
      exit 0


      I don't understand why this is needed in the start of option 2:



      ulimit -n 100000
      umask 007


      I changed the ownership with chown -Rvh tomcat: /usr/local/tomcat/



      Later



      # chmod +x /etc/init.d/tomcat
      # chkconfig --add tomcat`


      But after restarting the CentOS 6.6, the service is not running.



      Testing:



      $ echo $JAVA_HOME
      $

      $ echo $PATH
      /usr/lib/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/IntUser/bin
      $


      In other words $JAVA_HOME and $PATH aren't assigned!!!



      Trying to start manually (I did not assign password to tomcat user, which password should I use?):



      $ service tomcat start
      Password:
      /bin/su: incorrect password
      $


      Running as root, I was checking:



      # service tomcat start
      This account is currently not available.
      #


      Checking the account:



      # finger tomcat
      Login: tomcat Name: Tomcat User
      Directory: /usr/local/tomcat Shell: /sbin/nologin
      Never logged in.
      No mail.
      No Plan.
      #


      # more /etc/passwd | grep tomcat
      tomcat:x:493:490:Tomcat User:/usr/local/tomcat:/sbin/nologin
      #


      Checking the ownership:



      # ls -al /usr/local/tomcat/
      total 120
      drwxr-xr-x. 9 tomcat tomcat 4096 Jun 27 09:29 .
      drwxr-xr-x. 20 root root 4096 Jun 27 09:29 ..
      drwxr-xr-x. 2 tomcat tomcat 4096 Jun 27 09:29 bin
      drwxr-xr-x. 3 tomcat tomcat 4096 Jun 27 11:04 conf
      drwxr-xr-x. 2 tomcat tomcat 4096 Jun 27 09:29 lib
      -rw-r--r--. 1 tomcat tomcat 56977 May 19 15:03 LICENSE
      drwxr-xr-x. 2 tomcat tomcat 4096 Jun 27 11:04 logs
      -rw-r--r--. 1 tomcat tomcat 1397 May 19 15:03 NOTICE
      -rw-r--r--. 1 tomcat tomcat 6741 May 19 15:03 RELEASE-NOTES
      -rw-r--r--. 1 tomcat tomcat 16204 May 19 15:03 RUNNING.txt
      drwxr-xr-x. 2 tomcat tomcat 4096 Jun 27 09:29 temp
      drwxr-xr-x. 7 tomcat tomcat 4096 May 19 15:00 webapps
      drwxr-xr-x. 3 tomcat tomcat 4096 Jun 27 11:04 work
      #


      Please help me.



      Question 1:
      The script was created in: /etc/init.d/tomcat. Why were $JAVA_HOME and $PATH not assigned?



      Question 2
      Is there a method to install a service without root privileges, that starts at boot time without intervention (e.g., sudo, su, etc)?










      share|improve this question
















      I want to install tomcat 8 and run it at startup time



      I am following these tutorials:




      1. Install Tomcat 7 on CentOS, RHEL, or Fedora

      2. How to install Tomcat 8 on a CentOS 6 VPS


      I created the tomcat user:



      # useradd -U -r -M -d /usr/local/ServerWeb/tomcat -s /sbin/nologin tomcat


      The file was in /etc/init.d/tomcat



      In the option 1:



      #!/bin/bash  
      # description: Tomcat Start Stop Restart
      # processname: tomcat
      # chkconfig: 234 20 80
      JAVA_HOME=/opt/jdk
      export JAVA_HOME
      PATH=$JAVA_HOME/bin:$PATH
      export PATH
      TOMCAT_HOME=/usr/local/tomcat
      TOMCAT_USER=tomcat

      case $1 in
      start)
      /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh
      ;;
      stop)
      /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh
      ;;
      restart)
      /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh
      /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh
      ;;
      esac
      exit 0


      In the Option 2:



      #!/bin/bash
      #
      # tomcat
      #
      # chkconfig: - 80 20
      #
      ### BEGIN INIT INFO
      # Provides: tomcat
      # Required-Start: $network $syslog
      # Required-Stop: $network $syslog
      # Default-Start:
      # Default-Stop:
      # Description: Tomcat
      # Short-Description: start and stop tomcat
      ### END INIT INFO

      ## Source function library.
      #. /etc/rc.d/init.d/functions
      export JAVA_HOME=/opt/jdk
      export JAVA_OPTS="-Dfile.encoding=UTF-8
      -Dnet.sf.ehcache.skipUpdateCheck=true
      -XX:+UseConcMarkSweepGC
      -XX:+CMSClassUnloadingEnabled
      -XX:+UseParNewGC
      -XX:MaxPermSize=128m
      -Xms512m -Xmx512m"
      export PATH=$JAVA_HOME/bin:$PATH
      TOMCAT_HOME=/usr/local/tomcat
      TOMCAT_USER=tomcat
      SHUTDOWN_WAIT=20

      tomcat_pid() {
      echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'`
      }

      start() {
      pid=$(tomcat_pid)
      if [ -n "$pid" ]
      then
      echo "Tomcat is already running (pid: $pid)"
      else
      # Start tomcat
      echo "Starting tomcat"
      ulimit -n 100000
      umask 007
      /bin/su -p -s /bin/sh $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh
      fi


      return 0
      }

      stop() {
      pid=$(tomcat_pid)
      if [ -n "$pid" ]
      then
      echo "Stoping Tomcat"
      /bin/su -p -s /bin/sh $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh

      let kwait=$SHUTDOWN_WAIT
      count=0;
      until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
      do
      echo -n -e "nwaiting for processes to exit";
      sleep 1
      let count=$count+1;
      done

      if [ $count -gt $kwait ]; then
      echo -n -e "nkilling processes which didn't stop after $SHUTDOWN_WAIT seconds"
      kill -9 $pid
      fi
      else
      echo "Tomcat is not running"
      fi

      return 0
      }

      case $1 in
      start)
      start
      ;;
      stop)
      stop
      ;;
      restart)
      stop
      start
      ;;
      status)
      pid=$(tomcat_pid)
      if [ -n "$pid" ]
      then
      echo "Tomcat is running with pid: $pid"
      else
      echo "Tomcat is not running"
      fi
      ;;
      esac
      exit 0


      I don't understand why this is needed in the start of option 2:



      ulimit -n 100000
      umask 007


      I changed the ownership with chown -Rvh tomcat: /usr/local/tomcat/



      Later



      # chmod +x /etc/init.d/tomcat
      # chkconfig --add tomcat`


      But after restarting the CentOS 6.6, the service is not running.



      Testing:



      $ echo $JAVA_HOME
      $

      $ echo $PATH
      /usr/lib/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/IntUser/bin
      $


      In other words $JAVA_HOME and $PATH aren't assigned!!!



      Trying to start manually (I did not assign password to tomcat user, which password should I use?):



      $ service tomcat start
      Password:
      /bin/su: incorrect password
      $


      Running as root, I was checking:



      # service tomcat start
      This account is currently not available.
      #


      Checking the account:



      # finger tomcat
      Login: tomcat Name: Tomcat User
      Directory: /usr/local/tomcat Shell: /sbin/nologin
      Never logged in.
      No mail.
      No Plan.
      #


      # more /etc/passwd | grep tomcat
      tomcat:x:493:490:Tomcat User:/usr/local/tomcat:/sbin/nologin
      #


      Checking the ownership:



      # ls -al /usr/local/tomcat/
      total 120
      drwxr-xr-x. 9 tomcat tomcat 4096 Jun 27 09:29 .
      drwxr-xr-x. 20 root root 4096 Jun 27 09:29 ..
      drwxr-xr-x. 2 tomcat tomcat 4096 Jun 27 09:29 bin
      drwxr-xr-x. 3 tomcat tomcat 4096 Jun 27 11:04 conf
      drwxr-xr-x. 2 tomcat tomcat 4096 Jun 27 09:29 lib
      -rw-r--r--. 1 tomcat tomcat 56977 May 19 15:03 LICENSE
      drwxr-xr-x. 2 tomcat tomcat 4096 Jun 27 11:04 logs
      -rw-r--r--. 1 tomcat tomcat 1397 May 19 15:03 NOTICE
      -rw-r--r--. 1 tomcat tomcat 6741 May 19 15:03 RELEASE-NOTES
      -rw-r--r--. 1 tomcat tomcat 16204 May 19 15:03 RUNNING.txt
      drwxr-xr-x. 2 tomcat tomcat 4096 Jun 27 09:29 temp
      drwxr-xr-x. 7 tomcat tomcat 4096 May 19 15:00 webapps
      drwxr-xr-x. 3 tomcat tomcat 4096 Jun 27 11:04 work
      #


      Please help me.



      Question 1:
      The script was created in: /etc/init.d/tomcat. Why were $JAVA_HOME and $PATH not assigned?



      Question 2
      Is there a method to install a service without root privileges, that starts at boot time without intervention (e.g., sudo, su, etc)?







      centos software-installation startup tomcat






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 25 '15 at 16:47









      Thomas Dickey

      54.2k5106179




      54.2k5106179










      asked Jun 29 '15 at 16:46









      QA_ColQA_Col

      210411




      210411





      bumped to the homepage by Community yesterday


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community yesterday


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Neither of the tutorials you mentioned suggest using useradd with all of those options. By setting the login shell to /sbin/nologin you encounter:



          incorrect password 


          and



          This account is currently not available


          The following command will cause tomcat to be a system account without a /home/tomcat directory:



          useradd -r tomcat --shell /bin/false


          And this command will create a non-system tomcat account with a /home/tomcat directory:



          useradd tomcat --shell /bin/false


          EDIT:



          You are correct about the similarities of /sbin/nologin and /bin/false. The install instructions from Option #2 in the OP seem to be somewhat incomplete. I suggest using just one set of instructions until tomcat is working.



          This is the Tomcat 8 version of Option #1 you provided. I suggest using only these instructions to get your installation working. (It looks like mixing and matching is causing some grief.) By doing this, you will avoid other issues like your $JAVA_HOME and $PATH not being exported (Question 1) and Question 2 will be answered as well.



          Notice in your Option #1 script, you have lines like this:



          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh
          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh
          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh
          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh


          However the Option #1 link you provided has these lines:



          sh $CATALINA_HOME/bin/startup.sh       
          sh $CATALINA_HOME/bin/shutdown.sh
          sh $CATALINA_HOME/bin/shutdown.sh
          sh $CATALINA_HOME/bin/startup.sh





          share|improve this answer


























          • Thank you, Is bad idea to use --shell /bin/false ? and with creating the account -r is better to use System account or not?

            – QA_Col
            Jun 29 '15 at 22:31













          • This does a great job of explaining /sbin/nologin and /bin/false. As for -r or not, perhaps someone else can answer.

            – Timothy Martin
            Jun 29 '15 at 23:30













          • I was check your link your post and it has the same effect (only the difference is the additional message for -s /sbin/nologin). And Option 2 uses # useradd -r tomcat8 --shell /bin/false ... In other words -s /sbin/nologin or --shell /bin/false will cause the same problem. This post shows this.

            – QA_Col
            Jun 30 '15 at 1:30












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f212904%2fstarting-tomcat-service-when-starting-centos-rhel-fedora%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Neither of the tutorials you mentioned suggest using useradd with all of those options. By setting the login shell to /sbin/nologin you encounter:



          incorrect password 


          and



          This account is currently not available


          The following command will cause tomcat to be a system account without a /home/tomcat directory:



          useradd -r tomcat --shell /bin/false


          And this command will create a non-system tomcat account with a /home/tomcat directory:



          useradd tomcat --shell /bin/false


          EDIT:



          You are correct about the similarities of /sbin/nologin and /bin/false. The install instructions from Option #2 in the OP seem to be somewhat incomplete. I suggest using just one set of instructions until tomcat is working.



          This is the Tomcat 8 version of Option #1 you provided. I suggest using only these instructions to get your installation working. (It looks like mixing and matching is causing some grief.) By doing this, you will avoid other issues like your $JAVA_HOME and $PATH not being exported (Question 1) and Question 2 will be answered as well.



          Notice in your Option #1 script, you have lines like this:



          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh
          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh
          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh
          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh


          However the Option #1 link you provided has these lines:



          sh $CATALINA_HOME/bin/startup.sh       
          sh $CATALINA_HOME/bin/shutdown.sh
          sh $CATALINA_HOME/bin/shutdown.sh
          sh $CATALINA_HOME/bin/startup.sh





          share|improve this answer


























          • Thank you, Is bad idea to use --shell /bin/false ? and with creating the account -r is better to use System account or not?

            – QA_Col
            Jun 29 '15 at 22:31













          • This does a great job of explaining /sbin/nologin and /bin/false. As for -r or not, perhaps someone else can answer.

            – Timothy Martin
            Jun 29 '15 at 23:30













          • I was check your link your post and it has the same effect (only the difference is the additional message for -s /sbin/nologin). And Option 2 uses # useradd -r tomcat8 --shell /bin/false ... In other words -s /sbin/nologin or --shell /bin/false will cause the same problem. This post shows this.

            – QA_Col
            Jun 30 '15 at 1:30
















          0














          Neither of the tutorials you mentioned suggest using useradd with all of those options. By setting the login shell to /sbin/nologin you encounter:



          incorrect password 


          and



          This account is currently not available


          The following command will cause tomcat to be a system account without a /home/tomcat directory:



          useradd -r tomcat --shell /bin/false


          And this command will create a non-system tomcat account with a /home/tomcat directory:



          useradd tomcat --shell /bin/false


          EDIT:



          You are correct about the similarities of /sbin/nologin and /bin/false. The install instructions from Option #2 in the OP seem to be somewhat incomplete. I suggest using just one set of instructions until tomcat is working.



          This is the Tomcat 8 version of Option #1 you provided. I suggest using only these instructions to get your installation working. (It looks like mixing and matching is causing some grief.) By doing this, you will avoid other issues like your $JAVA_HOME and $PATH not being exported (Question 1) and Question 2 will be answered as well.



          Notice in your Option #1 script, you have lines like this:



          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh
          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh
          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh
          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh


          However the Option #1 link you provided has these lines:



          sh $CATALINA_HOME/bin/startup.sh       
          sh $CATALINA_HOME/bin/shutdown.sh
          sh $CATALINA_HOME/bin/shutdown.sh
          sh $CATALINA_HOME/bin/startup.sh





          share|improve this answer


























          • Thank you, Is bad idea to use --shell /bin/false ? and with creating the account -r is better to use System account or not?

            – QA_Col
            Jun 29 '15 at 22:31













          • This does a great job of explaining /sbin/nologin and /bin/false. As for -r or not, perhaps someone else can answer.

            – Timothy Martin
            Jun 29 '15 at 23:30













          • I was check your link your post and it has the same effect (only the difference is the additional message for -s /sbin/nologin). And Option 2 uses # useradd -r tomcat8 --shell /bin/false ... In other words -s /sbin/nologin or --shell /bin/false will cause the same problem. This post shows this.

            – QA_Col
            Jun 30 '15 at 1:30














          0












          0








          0







          Neither of the tutorials you mentioned suggest using useradd with all of those options. By setting the login shell to /sbin/nologin you encounter:



          incorrect password 


          and



          This account is currently not available


          The following command will cause tomcat to be a system account without a /home/tomcat directory:



          useradd -r tomcat --shell /bin/false


          And this command will create a non-system tomcat account with a /home/tomcat directory:



          useradd tomcat --shell /bin/false


          EDIT:



          You are correct about the similarities of /sbin/nologin and /bin/false. The install instructions from Option #2 in the OP seem to be somewhat incomplete. I suggest using just one set of instructions until tomcat is working.



          This is the Tomcat 8 version of Option #1 you provided. I suggest using only these instructions to get your installation working. (It looks like mixing and matching is causing some grief.) By doing this, you will avoid other issues like your $JAVA_HOME and $PATH not being exported (Question 1) and Question 2 will be answered as well.



          Notice in your Option #1 script, you have lines like this:



          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh
          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh
          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh
          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh


          However the Option #1 link you provided has these lines:



          sh $CATALINA_HOME/bin/startup.sh       
          sh $CATALINA_HOME/bin/shutdown.sh
          sh $CATALINA_HOME/bin/shutdown.sh
          sh $CATALINA_HOME/bin/startup.sh





          share|improve this answer















          Neither of the tutorials you mentioned suggest using useradd with all of those options. By setting the login shell to /sbin/nologin you encounter:



          incorrect password 


          and



          This account is currently not available


          The following command will cause tomcat to be a system account without a /home/tomcat directory:



          useradd -r tomcat --shell /bin/false


          And this command will create a non-system tomcat account with a /home/tomcat directory:



          useradd tomcat --shell /bin/false


          EDIT:



          You are correct about the similarities of /sbin/nologin and /bin/false. The install instructions from Option #2 in the OP seem to be somewhat incomplete. I suggest using just one set of instructions until tomcat is working.



          This is the Tomcat 8 version of Option #1 you provided. I suggest using only these instructions to get your installation working. (It looks like mixing and matching is causing some grief.) By doing this, you will avoid other issues like your $JAVA_HOME and $PATH not being exported (Question 1) and Question 2 will be answered as well.



          Notice in your Option #1 script, you have lines like this:



          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh
          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh
          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh
          /bin/su $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh


          However the Option #1 link you provided has these lines:



          sh $CATALINA_HOME/bin/startup.sh       
          sh $CATALINA_HOME/bin/shutdown.sh
          sh $CATALINA_HOME/bin/shutdown.sh
          sh $CATALINA_HOME/bin/startup.sh






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jun 30 '15 at 21:50

























          answered Jun 29 '15 at 19:44









          Timothy MartinTimothy Martin

          5,4242430




          5,4242430













          • Thank you, Is bad idea to use --shell /bin/false ? and with creating the account -r is better to use System account or not?

            – QA_Col
            Jun 29 '15 at 22:31













          • This does a great job of explaining /sbin/nologin and /bin/false. As for -r or not, perhaps someone else can answer.

            – Timothy Martin
            Jun 29 '15 at 23:30













          • I was check your link your post and it has the same effect (only the difference is the additional message for -s /sbin/nologin). And Option 2 uses # useradd -r tomcat8 --shell /bin/false ... In other words -s /sbin/nologin or --shell /bin/false will cause the same problem. This post shows this.

            – QA_Col
            Jun 30 '15 at 1:30



















          • Thank you, Is bad idea to use --shell /bin/false ? and with creating the account -r is better to use System account or not?

            – QA_Col
            Jun 29 '15 at 22:31













          • This does a great job of explaining /sbin/nologin and /bin/false. As for -r or not, perhaps someone else can answer.

            – Timothy Martin
            Jun 29 '15 at 23:30













          • I was check your link your post and it has the same effect (only the difference is the additional message for -s /sbin/nologin). And Option 2 uses # useradd -r tomcat8 --shell /bin/false ... In other words -s /sbin/nologin or --shell /bin/false will cause the same problem. This post shows this.

            – QA_Col
            Jun 30 '15 at 1:30

















          Thank you, Is bad idea to use --shell /bin/false ? and with creating the account -r is better to use System account or not?

          – QA_Col
          Jun 29 '15 at 22:31







          Thank you, Is bad idea to use --shell /bin/false ? and with creating the account -r is better to use System account or not?

          – QA_Col
          Jun 29 '15 at 22:31















          This does a great job of explaining /sbin/nologin and /bin/false. As for -r or not, perhaps someone else can answer.

          – Timothy Martin
          Jun 29 '15 at 23:30







          This does a great job of explaining /sbin/nologin and /bin/false. As for -r or not, perhaps someone else can answer.

          – Timothy Martin
          Jun 29 '15 at 23:30















          I was check your link your post and it has the same effect (only the difference is the additional message for -s /sbin/nologin). And Option 2 uses # useradd -r tomcat8 --shell /bin/false ... In other words -s /sbin/nologin or --shell /bin/false will cause the same problem. This post shows this.

          – QA_Col
          Jun 30 '15 at 1:30





          I was check your link your post and it has the same effect (only the difference is the additional message for -s /sbin/nologin). And Option 2 uses # useradd -r tomcat8 --shell /bin/false ... In other words -s /sbin/nologin or --shell /bin/false will cause the same problem. This post shows this.

          – QA_Col
          Jun 30 '15 at 1:30


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f212904%2fstarting-tomcat-service-when-starting-centos-rhel-fedora%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

          Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

          Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...