Page 1 of 1

How to configure Tomcat to run not as root

PostPosted:Mon Jul 07, 2014 7:03 am
by tiopourtu
Dear jllort,

I want to run tomcat not as root and start it up on boot. I have been searching in the forum and trial and error my self but no luck. I was using this instruction: http://wiki.openkm.com/index.php/Config ... vice_linux but it seems not working. Here's is my steps:
  1. Adding user openkm with
    Code: Select all
    $ sudo adduser openkm
  2. Create tomcat in /etc/init.d with
    Code: Select all
    $ sudo nano /etc/init.d/tomcat
  3. Change TOMCAT_HOME=/opt/openkm/tomcat
    Code: Select all
    #!/bin/sh
     
    ### BEGIN INIT INFO
    # Provides:          tomcat
    # Required-Start:    $remote_fs $syslog
    # Required-Stop:     $remote_fs $syslog
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: Start and stop Apache Tomcat
    # Description:       Enable Apache Tomcat service provided by daemon.
    ### END INIT INFO
     
    ECHO=/bin/echo
    TEST=/usr/bin/test
    TOMCAT_USER=openkm
    TOMCAT_HOME=/opt/openkm/tomcat
    TOMCAT_START_SCRIPT=$TOMCAT_HOME/bin/startup.sh
    TOMCAT_STOP_SCRIPT=$TOMCAT_HOME/bin/shutdown.sh
     
    $TEST -x $TOMCAT_START_SCRIPT || exit 0
    $TEST -x $TOMCAT_STOP_SCRIPT || exit 0
     
    start() {
        $ECHO -n "Starting Tomcat"
        su - $TOMCAT_USER -c "$TOMCAT_START_SCRIPT &"
        $ECHO "."
    }
     
    stop() {
        $ECHO -n "Stopping Tomcat"
        su - $TOMCAT_USER -c "$TOMCAT_STOP_SCRIPT 60 -force &"
        while [ "$(ps -fu $TOMCAT_USER | grep java | grep tomcat | wc -l)" -gt "0" ]; do
            sleep 5; $ECHO -n "."
        done
        $ECHO "."
    }
     
    case "$1" in
        start)
            start
            ;;
        stop)
            stop
            ;;
        restart)
            stop
            sleep 30
            start
            ;;
        *)
            $ECHO "Usage: tomcat {start|stop|restart}"
            exit 1
    esac
    exit 0
    
  4. Make it executeable with
    Code: Select all
    $ sudo chmod 755 /etc/init.d/tomcat
  5. Update the run levels with
    Code: Select all
    $ sudo update-rc.d tomcat defaults
  6. Run service with
    Code: Select all
    $ sudo service tomcat start
  7. Then I got this error message:
    Code: Select all
    Starting Tomcat.
    touch: cannot touch ‘/opt/openkm/tomcat/logs/catalina.out’: Permission denied
    /opt/openkm/tomcat/bin/catalina.sh: 385: /opt/openkm/tomcat/bin/catalina.sh: cannot create /opt/openkm/tomcat/logs/catalina.out: Permission denied
    
So what am I supposed to do ?

Regards,
Tio

Re: How to configure Tomcat to run not as root

PostPosted:Wed Jul 09, 2014 7:20 am
by jllort
you must execute
chown openkm:openkm -R /opt/openkm

Re: How to configure Tomcat to run not as root

PostPosted:Wed Jul 09, 2014 6:35 pm
by tiopourtu
Dear jllort,

Great! I should have realized from the error message at the first time that this is a matter of ownership...
It works now... thanks.

Regards,
Tio