Search code examples
tomcatcentosboot

Start Tomcat on reboot with different user


Which is the fastest way to automatically start Tomcat on reboot, without use the root user (I created a specific user for it called 'openam') and without using JSVC. I'm running a Centos 6.


Solution

  • For anyone intereset, I set this in /etc/init.t/tomcat

    #!/bin/sh
    
    # Purpose: Start or stop the Tomcat service.
    # chkconfig: 345 95 5
    # Check the path of Tomcat and set enviorment variables as follows in the .bashrc profile
    export CATALINA_HOME="/path/tomcat"
    export CATALINA_BASE="/path/tomcat"
    JAVA_HOME="/usr/java/jdk1.8.0_131"
    export JAVA_HOME
    
    case $1 in
    start)
    su user -c /path/tomcat/bin/startup.sh
    ;;
    stop)
    su user -c /path/bin/shutdown.sh
    ;;
    restart)
    su user -c /path/tomcat/bin/shutdown.sh
    su user -c /path/tomcat/bin/startup.sh
    ;;
    esac
    exit 0
    

    Where user is your startup user. And then

    chkconfig --add tomcat