How to restart/start/stop tomcat as non-root when tomcat is running as service under root?
<p>I have seen lots of tutorials and tips around running tomcat on centos/ubuntu/linux.</p>

<p>I am using centos image in aws to run tomcat. 
I did NOT do <code>sudo yum install tomcat7*</code>. This would have created a tomcat service account under with tomcat run will run. The reason I did not do this is because I need to copy (scp) the war file into webapps directory and I cannot scp directly as tomcat user. </p>

<p>Instead, I created a tomcat user with password. 
I downloaded the tar.gz, unzipped and moved tomcat into /usr/share/tomcat7.</p>

<p>Following the instructions by this <a href="https://alextheedom.wordpress.com/cloud/amazon-free-usage-tier-installing-tomcat-7-on-an-ec2-linux-instance/" rel="nofollow">blog</a>, I edited /etc/rc.d/init.d/tomcat as follows.</p>

<pre><code>!/bin/sh
# Tomcat init script for Linux.
#
# chkconfig: 2345 96 14
# description: The Apache Tomcat servlet/JSP container.
JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64
CATALINA_HOME=/usr/share/tomcat7
export JAVA_HOME CATALINA_HOME
exec $CATALINA_HOME/bin/catalina.sh $*
</code></pre>

<p>Then I executed the following commands</p>

<pre><code>sudo chmod 755 /etc/rc.d/init.d/tomcat
sudo chkconfig --level 2345 tomcat on
</code></pre>

<p>I rebooted the machine and on startup tomcat is fired by root user.</p>

<p>I could also see the tomcat page showing corectly.</p>

<p>Now, I scp'ed my war into webapps directory (as tomcat user).
stopped the tomcat and restarted</p>

<pre><code>sudo /etc/init.d/tomcat stop
sudo /etc/init.d/tomcat start
</code></pre>

<p>I get permission denied error when trying to write to <code>catalina.out</code>. This is because the <code>catalina.out</code> file is touched by root after centos reboot and now when I restarted tomcat as "tomcat" user, it does not have permission to write to it.</p>

<p>I changed the ownership on catalina.out (<code>chown tomcat:tomcat catalina.out)</code>. After this change, I see tomcat starting and logging correctly.</p>

<p>Now the question is what is the right way to do it.
1) I will have jenkins jobs copying the war file to tomcat. so to restart the service, I need to sudo, which I cant from jenkins.</p>

<p>2) changing ownership of catalina.out is not right thing to do. if machine reboots, catalina.out is owned by tomcat and root cannot write to it. so there are problems of this catalina.out owned by either root or tomcat user.</p>

<p>Thanks for suggestions</p>