You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Anthony Bungeroth <an...@blumetech.com> on 2014/10/29 18:33:50 UTC

Tomcat Start script not starting from init.d or rc.local

I basically need a script to run automatically when I reboot the server.
I have tried the various ways to get it to work in init.d and it's not working.  When I go into init.d and run it manually it works though.

I think it has something to do with the fact that to run the script manually I am logged in as root, whereas for it to run automatically it has to run in the background.

I will include the script info in this email and see if you had an idea as to where the issue is.

So in /etc/init.d, there is a script called Tomcat, here is the "start" portion of the script.  Once again, when I run this manually while logged in as root it launches.

#!/bin/sh
# Apache Tomcat Startup Script
# chkconfig 234 20 80

JAVA_HOME=/opt/jdk1.6.0_45
CATALINA_HOME=/opt/tomcat
TOMCAT_USER=tomcat

start() {
        echo -n "Starting Tomcat:  "
        su $TOMCAT_USER $CATALINA_HOME/bin/startup.sh
        sleep 2
}

I tried creating a new script and putting that one in "rc.local".
Here is the "rc.local" command:

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

su tomcat /opt/tomcat/bin/startup.sh

This is a total rookie issue I am sure....but just in case you might be able to help with an easy enough fix, I would greatly appreciate it.  I don't even know where to look for error logs to troubleshoot this.
Thanks for any assistance.
Anthony
________________________________
Anthony Bungeroth
Systems Engineer

p: 347-762-5863 (347-76 BLUME)
f: 419-831-5614
e: anthony@blumetech.com
Our Blog<http://blogs.blumetech.com/>
[blumetech]
<http://www.blumetech.com>
<http://www.blumetech.com>[blumetech]
<http://www.aws-partner-directory.com/PartnerDirectory/PartnerDetail?Name=Blume+Technical+Consulting>
<http://www.aws-partner-directory.com/PartnerDirectory/PartnerDetail?Name=Blume+Technical+Consulting>

This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error, you are directed not to read, disclose, reproduce, distribute, disseminate or otherwise use this transmission, and we also request that you immediately delete this message and its attachments, if any. Delivery of this message to any person other than the intended recipient(s) is not intended in any way to waive privilege or confidentiality. Finally, the recipient should check this email and any attachments for the presence of viruses; Blumetech accepts no liability for any damage caused by any virus transmitted by this email.

Re: Tomcat Start script not starting from init.d or rc.local

Posted by Mark Eggers <it...@yahoo.com.INVALID>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chris,

On 10/30/2014 7:17 AM, Christopher Schultz wrote:
> Mark,
> 
> On 10/29/14 3:44 PM, Mark Eggers wrote:
> 
>> On 10/29/2014 10:33 AM, Anthony Bungeroth wrote:
> 
>>> I basically need a script to run automatically when I reboot
>>> the server. I have tried the various ways to get it to work in 
>>> init.d and it's not working.  When I go into init.d and run it 
>>> manually it works though.
> 
>>> I think it has something to do with the fact that to run the 
>>> script manually I am logged in as root, whereas for it to run 
>>> automatically it has to run in the background.
> 
>>> I will include the script info in this email and see if you
>>> had an idea as to where the issue is.
> 
>>> So in /etc/init.d, there is a script called Tomcat, here is the
>>>  "start" portion of the script.  Once again, when I run this 
>>> manually while logged in as root it launches.
> 
>>> #!/bin/sh # Apache Tomcat Startup Script # chkconfig 234 20 80
> 
>>> JAVA_HOME=/opt/jdk1.6.0_45 CATALINA_HOME=/opt/tomcat 
>>> TOMCAT_USER=tomcat
> 
>>> start() { echo -n "Starting Tomcat:  " su $TOMCAT_USER 
>>> $CATALINA_HOME/bin/startup.sh sleep 2 }
> 
>>> I tried creating a new script and putting that one in
>>> "rc.local". Here is the "rc.local" command:
> 
>>> #!/bin/sh # # This script will be executed *after* all the
>>> other init scripts. # You can put your own initialization stuff
>>> in here if you don't # want to do the full Sys V style init
>>> stuff.
> 
>>> su tomcat /opt/tomcat/bin/startup.sh
> 
>>> This is a total rookie issue I am sure....but just in case you
>>>  might be able to help with an easy enough fix, I would greatly
>>>  appreciate it.  I don't even know where to look for error logs
>>> to troubleshoot this. Thanks for any assistance. Anthony 
>>> ________________________________ Anthony Bungeroth Systems 
>>> Engineer
> 
>>> p: 347-762-5863 (347-76 BLUME) f: 419-831-5614 e: 
>>> anthony@blumetech.com Our Blog<http://blogs.blumetech.com/> 
>>> [blumetech] <http://www.blumetech.com> 
>>> <http://www.blumetech.com>[blumetech] 
>>> <http://www.aws-partner-directory.com/PartnerDirectory/PartnerDetail?Name=Blume+Technical+Consulting>
>
>>> 
>>> 
> 
> 
> 
>> <http://www.aws-partner-directory.com/PartnerDirectory/PartnerDetail?Name=Blume+Technical+Consulting>
>
>> 
> 
>>> This email and any files transmitted with it are confidential
>>> and intended solely for the use of the individual or entity to
>>> whom they are addressed. If you have received this email in
>>> error, you are directed not to read, disclose, reproduce,
>>> distribute, disseminate or otherwise use this transmission, and
>>> we also request that you immediately delete this message and
>>> its attachments, if any. Delivery of this message to any
>>> person other than the intended recipient(s) is not intended in
>>> any way to waive privilege or confidentiality. Finally, the
>>> recipient should check this email and any attachments for the
>>> presence of viruses; Blumetech accepts no liability for any
>>> damage caused by any virus transmitted by this email.
> 
> 
>> Anthony,
> 
>> My relevant line looks like this (all one line of course):
> 
>> $SU - $TOMCAT_USER -c "${CONFIG_OPTS} ${CAT_PID} 
>> ${TOMCAT_INSTANCE} start" >> $SERVICE_LOG 2>&1
> 
> 
> You may be using a different "su" than me, but here's the 
> documentation for the "-" switch for mine:
> 
> -, -l, --login Provide an environment similar to what the user
> would expect had the user logged in directly.
> 
> When - is used, it must be specified as the last su option. The 
> other forms (-l and --login) do not have this restriction.
> 
> So, first, I don't think you want a "login" shell: there is no
> reason to run /etc/profile, ~/.profile, etc. is there? Second, you
> aren't supposed to use "-" except as the last option on the line.
> You might want to check the manual page for your version of su.

- From my man page:

   -, -l, --login
      make  the  shell  a  login  shell, clears all envvars except for
      TERM, initializes HOME, SHELL, USER, LOGNAME and PATH

The login shell is a bit problematic, but initializing USER, LOGNAME,
and PATH (the Tomcat user has a restricted path) is useful.

I don't see the restriction on su for '-' that your man page mentions.
We're running CentOS 6.5 / 6.6 in production, and I run Fedora 20 on
my laptop. I'm working on vetting a CentOS 7 (systemd) script, but as
usual other things keep impacting my time.

> 
>> $SU                - set to su for non-SELinux, runuser for 
>> SELinux $TOMCAT_USER       - Tomcat user ${CONFIG_OPTS}     - 
>> CATALINA_HOME, CATALINA_BASE, JRE_HOME, etc. ${CAT_PID}
>> - PID, not used in startup ${TOMCAT_INSTANCE} - Tomcat command
>> based on CATALINA_HOME $SERVICE_LOG       - logs the start and
>> stop of the service
> 
> I would recommend using extra quotes around everything to avoid 
> problems with paths that might contain spaces.
> 

That's why the following line is in quotes:

"${CONFIG_OPTS} ${CAT_PID} ${TOMCAT_INSTANCE} start"

${CONFIG_OPTS} does contain spaces, and the resulting command
obviously contains spaces.

While the shell script is long and ugly, there are only a few places
where spaces crop up. I seem to have them all covered.

>> I stuff all of the options in a file which is parsed and placed 
>> into ${CONFIG_OPTS}. I could probably use setenv.sh, but this way
>> I have a root-controlled (and versioned) configuration file for
>> my service configuration.
> 
>> I use catalina.sh directly, which is buried in the 
>> ${TOMCAT_INSTANCE} variable. This is so I can do start and stop 
>> with one command setup.
> 
> +1
> 
> -chris

I'm looking at Chef to manage a lot of this in the future, depending
on how much Ruby programming is needed. I can then place everything in
version control, which makes me a much happier camper.

. . . just my two cents
/mde/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBAgAGBQJUUmPbAAoJEEFGbsYNeTwt2rYIAJN6w6vRbTWXu+dvFSrIRfRK
sehTvC+hQte5vBSYThWwwTTFOo0gk0+KpDqlbguRa/rTZvkSJqpBxmQW57tV3AV1
M+1xL80CIu8Q+2Z4emy4R5BJds8wlTgYkZ/IJJJ0yEkthVnGOX3AnythFkP6eOuZ
FxbV18VctDkZruI0SN9CVVAhC/Ibw41RvYVK9q91VtFph9MmRLqkGAhFqFgngFkj
cSNHOHfMRqWHIQbBkl3s+w/dXgiG0vs0mxGM5628QXL+rgxeqDibgRhYzkyOWwRk
qmFyFI33LxCzjfwUUSiEHD6zrdWgr7PTOnDtyCKfecRGQlnz73wmKSfFEeta+lw=
=IbQd
-----END PGP SIGNATURE-----

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Tomcat Start script not starting from init.d or rc.local

Posted by Anthony Bungeroth <an...@blumetech.com>.
Ah ok, thanks.

-----Original Message-----
From: Christopher Schultz [mailto:chris@christopherschultz.net]
Sent: Thursday, October 30, 2014 1:25 PM
To: Tomcat Users List
Subject: Re: Tomcat Start script not starting from init.d or rc.local

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Mathieu,

On 10/30/14 12:11 PM, Mathieu Larchet wrote:
> Your variables are not visible from the su user, you should export
> them as you launch your command :
>
> su tomcat -c "JAVA_HOME=... CATALINA_HOME=...
> $CATALINA_HOME/bin/startup.sh"

Not true: environment variables are replaced before the 'su' command is executed, so your issue not a problem. If you were to use 'single quotes' then the string wouldn't be processed in this way.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJUUnRzAAoJEBzwKT+lPKRYjnIP/jTRZcq7zwhFV2JebboeaUDW
Z8n2ofKwavV2cJKP/cUewjX66SCz+3YhQTRLl5uqzMtxpLRx2canrsyevbQslV4A
IMhJBrjMTCmIbOGKu2Iq3iuksuRbX9Ki5KTqEByPflWJJqYDj+/CthdHNxOLSLVH
0Pv5ls47xYaSllN+2Lgl8rYr1SuC2WsKY2mUSFzIIAD+nkZRGV0L3TnPKlyW8H1U
BeSauhvhykAiF6Syk+38pqmzwg0u/7UQgb1FdF8s4+m9akQ0/nZTh92BlZWjXzoY
9e66bMngWIHjIDiDeLnYCpuTIhMXcReabAjT1b98Rwj/dIjqYGc0EY2vpyMK/z72
/66lKzOEeF9Zx8QrQQdFrdAs6dT+0e99KbkaASQhzGT0bitkZR2AeR0SH8LS8OuL
D13beOI9g6zCt9pv40awCJEom5fE+cpZX8+Ywm0pxeE+J6VufNLRbXKOkQEjzjoR
l1RJ8EvWFMk5b9yMcw1DHF5kEBdE/vezOKCkpRUUAbjjiTfbr7reRi5mYwSST8qo
3KD9cGynrW3ZCHbNbcgpl6VdTrs6AL7PrZJXHmOWYtY1yv8Z/LTzQYzX0mh6cGY0
gNQY9R0JmgOH08FzfpqMaBsqIu9FtjMqb+J5NVgLrDgiQ0E3IFZEjNbRw/cJmUBT
SsgUPkmiq2nUzzECbBXu
=IMT0
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org

________________________________
 Anthony Bungeroth
Systems Engineer

p: 347-762-5863 (347-76 BLUME)
f: 419-831-5614
e: anthony@blumetech.com
Our Blog<http://blogs.blumetech.com/>
[blumetech]
<http://www.blumetech.com>
<http://www.blumetech.com>[blumetech]
<http://www.aws-partner-directory.com/PartnerDirectory/PartnerDetail?Name=Blume+Technical+Consulting>
<http://www.aws-partner-directory.com/PartnerDirectory/PartnerDetail?Name=Blume+Technical+Consulting>

This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error, you are directed not to read, disclose, reproduce, distribute, disseminate or otherwise use this transmission, and we also request that you immediately delete this message and its attachments, if any. Delivery of this message to any person other than the intended recipient(s) is not intended in any way to waive privilege or confidentiality. Finally, the recipient should check this email and any attachments for the presence of viruses; Blumetech accepts no liability for any damage caused by any virus transmitted by this email.

Re: Tomcat Start script not starting from init.d or rc.local

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Mathieu,

On 10/30/14 12:11 PM, Mathieu Larchet wrote:
> Your variables are not visible from the su user, you should export 
> them as you launch your command :
> 
> su tomcat -c "JAVA_HOME=... CATALINA_HOME=...
> $CATALINA_HOME/bin/startup.sh"

Not true: environment variables are replaced before the 'su' command
is executed, so your issue not a problem. If you were to use 'single
quotes' then the string wouldn't be processed in this way.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJUUnRzAAoJEBzwKT+lPKRYjnIP/jTRZcq7zwhFV2JebboeaUDW
Z8n2ofKwavV2cJKP/cUewjX66SCz+3YhQTRLl5uqzMtxpLRx2canrsyevbQslV4A
IMhJBrjMTCmIbOGKu2Iq3iuksuRbX9Ki5KTqEByPflWJJqYDj+/CthdHNxOLSLVH
0Pv5ls47xYaSllN+2Lgl8rYr1SuC2WsKY2mUSFzIIAD+nkZRGV0L3TnPKlyW8H1U
BeSauhvhykAiF6Syk+38pqmzwg0u/7UQgb1FdF8s4+m9akQ0/nZTh92BlZWjXzoY
9e66bMngWIHjIDiDeLnYCpuTIhMXcReabAjT1b98Rwj/dIjqYGc0EY2vpyMK/z72
/66lKzOEeF9Zx8QrQQdFrdAs6dT+0e99KbkaASQhzGT0bitkZR2AeR0SH8LS8OuL
D13beOI9g6zCt9pv40awCJEom5fE+cpZX8+Ywm0pxeE+J6VufNLRbXKOkQEjzjoR
l1RJ8EvWFMk5b9yMcw1DHF5kEBdE/vezOKCkpRUUAbjjiTfbr7reRi5mYwSST8qo
3KD9cGynrW3ZCHbNbcgpl6VdTrs6AL7PrZJXHmOWYtY1yv8Z/LTzQYzX0mh6cGY0
gNQY9R0JmgOH08FzfpqMaBsqIu9FtjMqb+J5NVgLrDgiQ0E3IFZEjNbRw/cJmUBT
SsgUPkmiq2nUzzECbBXu
=IMT0
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat Start script not starting from init.d or rc.local

Posted by Mathieu Larchet <ma...@univ-lorraine.fr>.
Hi,

Your variables are not visible from the su user, you should export them as you launch your command :

su tomcat -c "JAVA_HOME=... CATALINA_HOME=... $CATALINA_HOME/bin/startup.sh"

Good luck

----- Mail original -----
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
> 
> Mark,
> 
> On 10/29/14 3:44 PM, Mark Eggers wrote:
> > 
> > On 10/29/2014 10:33 AM, Anthony Bungeroth wrote:
> > 
> >> I basically need a script to run automatically when I reboot the
> >>  server. I have tried the various ways to get it to work in
> >> init.d and it's not working.  When I go into init.d and run it
> >> manually it works though.
> > 
> >> I think it has something to do with the fact that to run the
> >> script manually I am logged in as root, whereas for it to run
> >> automatically it has to run in the background.
> > 
> >> I will include the script info in this email and see if you had
> >> an idea as to where the issue is.
> > 
> >> So in /etc/init.d, there is a script called Tomcat, here is the
> >> "start" portion of the script.  Once again, when I run this
> >> manually while logged in as root it launches.
> > 
> >> #!/bin/sh # Apache Tomcat Startup Script # chkconfig 234 20 80
> > 
> >> JAVA_HOME=/opt/jdk1.6.0_45 CATALINA_HOME=/opt/tomcat
> >> TOMCAT_USER=tomcat
> > 
> >> start() { echo -n "Starting Tomcat:  " su $TOMCAT_USER
> >> $CATALINA_HOME/bin/startup.sh sleep 2 }
> > 
> >> I tried creating a new script and putting that one in "rc.local".
> >>  Here is the "rc.local" command:
> > 
> >> #!/bin/sh # # This script will be executed *after* all the other
> >>  init scripts. # You can put your own initialization stuff in
> >> here if you don't # want to do the full Sys V style init stuff.
> > 
> >> su tomcat /opt/tomcat/bin/startup.sh
> > 
> >> This is a total rookie issue I am sure....but just in case you
> >> might be able to help with an easy enough fix, I would greatly
> >> appreciate it.  I don't even know where to look for error logs to
> >>  troubleshoot this. Thanks for any assistance. Anthony
> >> ________________________________ Anthony Bungeroth Systems
> >> Engineer
> > 
> >> p: 347-762-5863 (347-76 BLUME) f: 419-831-5614 e:
> >> anthony@blumetech.com Our Blog<http://blogs.blumetech.com/>
> >> [blumetech] <http://www.blumetech.com>
> >> <http://www.blumetech.com>[blumetech]
> >> <http://www.aws-partner-directory.com/PartnerDirectory/PartnerDetail?Name=Blume+Technical+Consulting>
> >
> >> 
> > 
> > 
> > 
> > <http://www.aws-partner-directory.com/PartnerDirectory/PartnerDetail?Name=Blume+Technical+Consulting>
> >
> > 
> >> This email and any files transmitted with it are confidential and
> >>  intended solely for the use of the individual or entity to whom
> >>  they are addressed. If you have received this email in error,
> >> you are directed not to read, disclose, reproduce, distribute,
> >> disseminate or otherwise use this transmission, and we also
> >> request that you immediately delete this message and its
> >> attachments, if any. Delivery of this message to any person
> >> other than the intended recipient(s) is not intended in any way
> >> to waive privilege or confidentiality. Finally, the recipient
> >> should check this email and any attachments for the presence of
> >> viruses; Blumetech accepts no liability for any damage caused by
> >> any virus transmitted by this email.
> > 
> > 
> > Anthony,
> > 
> > My relevant line looks like this (all one line of course):
> > 
> > $SU - $TOMCAT_USER -c "${CONFIG_OPTS} ${CAT_PID}
> > ${TOMCAT_INSTANCE} start" >> $SERVICE_LOG 2>&1
> 
> 
> You may be using a different "su" than me, but here's the
> documentation for the "-" switch for mine:
> 
>        -, -l, --login
>            Provide an environment similar to what the user would
> expect had
>            the user logged in directly.
> 
>            When - is used, it must be specified as the last su option. The
>            other forms (-l and --login) do not have this restriction.
> 
> So, first, I don't think you want a "login" shell: there is no reason
> to run /etc/profile, ~/.profile, etc. is there? Second, you aren't
> supposed to use "-" except as the last option on the line. You might
> want to check the manual page for your version of su.
> 
> > $SU                - set to su for non-SELinux, runuser for
> > SELinux $TOMCAT_USER       - Tomcat user ${CONFIG_OPTS}     -
> > CATALINA_HOME, CATALINA_BASE, JRE_HOME, etc. ${CAT_PID}         -
> > PID, not used in startup ${TOMCAT_INSTANCE} - Tomcat command based
> > on CATALINA_HOME $SERVICE_LOG       - logs the start and stop of
> > the service
> 
> I would recommend using extra quotes around everything to avoid
> problems with paths that might contain spaces.
> 
> > I stuff all of the options in a file which is parsed and placed
> > into ${CONFIG_OPTS}. I could probably use setenv.sh, but this way I
> > have a root-controlled (and versioned) configuration file for my
> > service configuration.
> > 
> > I use catalina.sh directly, which is buried in the
> > ${TOMCAT_INSTANCE} variable. This is so I can do start and stop
> > with one command setup.
> 
> +1
> 
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1
> Comment: GPGTools - http://gpgtools.org
> 
> iQIcBAEBCAAGBQJUUkhcAAoJEBzwKT+lPKRYfCIP/3xwf65TwYvGW2EpptNgpESK
> /lkV/BiF4VywJCM/6mVBkNXtPsx3y/0Cn6i5klXT+WF2+PdnO3NABmD1JtsaJxtr
> ovIdMkRGvVlkJnsffsYSSsnz8qBiN+kWRwCvqePZ23Qs10ylp3F2/KgHIuZ3lEOQ
> cNM3iDk0X3go3WAtQrePmgpqXf+IEO82c6kDeQJP+gDGLEpKgWZnVIPC75U0OAgR
> SYVy7BgcOnFq07qMWM73TsutPB2vWi+6hO5e7v9+I6AuwY0V2xr9FCdlYfSJhV6o
> WVJOX5d0IjrleMrTbPnUTo/OU/3Sim5DlVym09/QRSd5Zgw9dDPqXc0ahfFejrJE
> yeo5LqJ1jUTNxscpxO7jJ5WyNfNX0joaoUa3wmE0N+kdYBSzoSm1E1YS2BpMq8/m
> NGeNggL9ReiJibVWIRCk/pFi0EsFMvhsSwKirK/rGr5YDetcnWiu+WBYaufna0kf
> 7wYGnAQwqsb6bdb0Viv4EwwKRtOeaks55iwQhZUaT6nB/22lDZwCC9V2qQxS7soP
> R5Dc2gNvhZi4ATaQEKD4QYNHSSIaZcpCq9J2yCYU8edDjpGnwWPSV1Va67AsXxxt
> x555DA3O/J7PJp4Ux+Tm5ryC9WBmZa1cgcSTg4OG+gl1w05PRcOMgY77ZrFHXOn5
> BkQ9dsenPiq2wdaXa0++
> =QSqk
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 

-- 

Mathieu LARCHET
Direction du Numérique
Sous-Direction des Infrastructures
-
24-30 rue Lionnois
54003 Nancy Cedex
-
Tel : 03 83 68 53 82
Mail : mathieu.larchet@univ-lorraine.fr
-

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat Start script not starting from init.d or rc.local

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Mark,

On 10/29/14 3:44 PM, Mark Eggers wrote:
> 
> On 10/29/2014 10:33 AM, Anthony Bungeroth wrote:
> 
>> I basically need a script to run automatically when I reboot the
>>  server. I have tried the various ways to get it to work in
>> init.d and it's not working.  When I go into init.d and run it
>> manually it works though.
> 
>> I think it has something to do with the fact that to run the
>> script manually I am logged in as root, whereas for it to run 
>> automatically it has to run in the background.
> 
>> I will include the script info in this email and see if you had
>> an idea as to where the issue is.
> 
>> So in /etc/init.d, there is a script called Tomcat, here is the 
>> "start" portion of the script.  Once again, when I run this 
>> manually while logged in as root it launches.
> 
>> #!/bin/sh # Apache Tomcat Startup Script # chkconfig 234 20 80
> 
>> JAVA_HOME=/opt/jdk1.6.0_45 CATALINA_HOME=/opt/tomcat 
>> TOMCAT_USER=tomcat
> 
>> start() { echo -n "Starting Tomcat:  " su $TOMCAT_USER 
>> $CATALINA_HOME/bin/startup.sh sleep 2 }
> 
>> I tried creating a new script and putting that one in "rc.local".
>>  Here is the "rc.local" command:
> 
>> #!/bin/sh # # This script will be executed *after* all the other
>>  init scripts. # You can put your own initialization stuff in
>> here if you don't # want to do the full Sys V style init stuff.
> 
>> su tomcat /opt/tomcat/bin/startup.sh
> 
>> This is a total rookie issue I am sure....but just in case you 
>> might be able to help with an easy enough fix, I would greatly 
>> appreciate it.  I don't even know where to look for error logs to
>>  troubleshoot this. Thanks for any assistance. Anthony 
>> ________________________________ Anthony Bungeroth Systems 
>> Engineer
> 
>> p: 347-762-5863 (347-76 BLUME) f: 419-831-5614 e: 
>> anthony@blumetech.com Our Blog<http://blogs.blumetech.com/> 
>> [blumetech] <http://www.blumetech.com> 
>> <http://www.blumetech.com>[blumetech] 
>> <http://www.aws-partner-directory.com/PartnerDirectory/PartnerDetail?Name=Blume+Technical+Consulting>
>
>> 
> 
> 
> 
> <http://www.aws-partner-directory.com/PartnerDirectory/PartnerDetail?Name=Blume+Technical+Consulting>
>
> 
>> This email and any files transmitted with it are confidential and
>>  intended solely for the use of the individual or entity to whom
>>  they are addressed. If you have received this email in error,
>> you are directed not to read, disclose, reproduce, distribute, 
>> disseminate or otherwise use this transmission, and we also 
>> request that you immediately delete this message and its 
>> attachments, if any. Delivery of this message to any person
>> other than the intended recipient(s) is not intended in any way
>> to waive privilege or confidentiality. Finally, the recipient
>> should check this email and any attachments for the presence of
>> viruses; Blumetech accepts no liability for any damage caused by
>> any virus transmitted by this email.
> 
> 
> Anthony,
> 
> My relevant line looks like this (all one line of course):
> 
> $SU - $TOMCAT_USER -c "${CONFIG_OPTS} ${CAT_PID}
> ${TOMCAT_INSTANCE} start" >> $SERVICE_LOG 2>&1


You may be using a different "su" than me, but here's the
documentation for the "-" switch for mine:

       -, -l, --login
           Provide an environment similar to what the user would
expect had
           the user logged in directly.

           When - is used, it must be specified as the last su option. The
           other forms (-l and --login) do not have this restriction.

So, first, I don't think you want a "login" shell: there is no reason
to run /etc/profile, ~/.profile, etc. is there? Second, you aren't
supposed to use "-" except as the last option on the line. You might
want to check the manual page for your version of su.

> $SU                - set to su for non-SELinux, runuser for
> SELinux $TOMCAT_USER       - Tomcat user ${CONFIG_OPTS}     -
> CATALINA_HOME, CATALINA_BASE, JRE_HOME, etc. ${CAT_PID}         -
> PID, not used in startup ${TOMCAT_INSTANCE} - Tomcat command based
> on CATALINA_HOME $SERVICE_LOG       - logs the start and stop of
> the service

I would recommend using extra quotes around everything to avoid
problems with paths that might contain spaces.

> I stuff all of the options in a file which is parsed and placed
> into ${CONFIG_OPTS}. I could probably use setenv.sh, but this way I
> have a root-controlled (and versioned) configuration file for my
> service configuration.
> 
> I use catalina.sh directly, which is buried in the
> ${TOMCAT_INSTANCE} variable. This is so I can do start and stop
> with one command setup.

+1

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJUUkhcAAoJEBzwKT+lPKRYfCIP/3xwf65TwYvGW2EpptNgpESK
/lkV/BiF4VywJCM/6mVBkNXtPsx3y/0Cn6i5klXT+WF2+PdnO3NABmD1JtsaJxtr
ovIdMkRGvVlkJnsffsYSSsnz8qBiN+kWRwCvqePZ23Qs10ylp3F2/KgHIuZ3lEOQ
cNM3iDk0X3go3WAtQrePmgpqXf+IEO82c6kDeQJP+gDGLEpKgWZnVIPC75U0OAgR
SYVy7BgcOnFq07qMWM73TsutPB2vWi+6hO5e7v9+I6AuwY0V2xr9FCdlYfSJhV6o
WVJOX5d0IjrleMrTbPnUTo/OU/3Sim5DlVym09/QRSd5Zgw9dDPqXc0ahfFejrJE
yeo5LqJ1jUTNxscpxO7jJ5WyNfNX0joaoUa3wmE0N+kdYBSzoSm1E1YS2BpMq8/m
NGeNggL9ReiJibVWIRCk/pFi0EsFMvhsSwKirK/rGr5YDetcnWiu+WBYaufna0kf
7wYGnAQwqsb6bdb0Viv4EwwKRtOeaks55iwQhZUaT6nB/22lDZwCC9V2qQxS7soP
R5Dc2gNvhZi4ATaQEKD4QYNHSSIaZcpCq9J2yCYU8edDjpGnwWPSV1Va67AsXxxt
x555DA3O/J7PJp4Ux+Tm5ryC9WBmZa1cgcSTg4OG+gl1w05PRcOMgY77ZrFHXOn5
BkQ9dsenPiq2wdaXa0++
=QSqk
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat Start script not starting from init.d or rc.local

Posted by Mark Eggers <it...@yahoo.com.INVALID>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On 10/29/2014 10:33 AM, Anthony Bungeroth wrote:
> 
> I basically need a script to run automatically when I reboot the 
> server. I have tried the various ways to get it to work in init.d 
> and it's not working.  When I go into init.d and run it manually
> it works though.
> 
> I think it has something to do with the fact that to run the script
> manually I am logged in as root, whereas for it to run 
> automatically it has to run in the background.
> 
> I will include the script info in this email and see if you had an
>  idea as to where the issue is.
> 
> So in /etc/init.d, there is a script called Tomcat, here is the 
> "start" portion of the script.  Once again, when I run this 
> manually while logged in as root it launches.
> 
> #!/bin/sh # Apache Tomcat Startup Script # chkconfig 234 20 80
> 
> JAVA_HOME=/opt/jdk1.6.0_45 CATALINA_HOME=/opt/tomcat 
> TOMCAT_USER=tomcat
> 
> start() { echo -n "Starting Tomcat:  " su $TOMCAT_USER 
> $CATALINA_HOME/bin/startup.sh sleep 2 }
> 
> I tried creating a new script and putting that one in "rc.local". 
> Here is the "rc.local" command:
> 
> #!/bin/sh # # This script will be executed *after* all the other 
> init scripts. # You can put your own initialization stuff in here 
> if you don't # want to do the full Sys V style init stuff.
> 
> su tomcat /opt/tomcat/bin/startup.sh
> 
> This is a total rookie issue I am sure....but just in case you 
> might be able to help with an easy enough fix, I would greatly 
> appreciate it.  I don't even know where to look for error logs to 
> troubleshoot this. Thanks for any assistance. Anthony 
> ________________________________ Anthony Bungeroth Systems 
> Engineer
> 
> p: 347-762-5863 (347-76 BLUME) f: 419-831-5614 e: 
> anthony@blumetech.com Our Blog<http://blogs.blumetech.com/> 
> [blumetech] <http://www.blumetech.com> 
> <http://www.blumetech.com>[blumetech] 
> <http://www.aws-partner-directory.com/PartnerDirectory/PartnerDetail?Name=Blume+Technical+Consulting>
>
>
>
> 
<http://www.aws-partner-directory.com/PartnerDirectory/PartnerDetail?Name=Blume+Technical+Consulting>
> 
> This email and any files transmitted with it are confidential and 
> intended solely for the use of the individual or entity to whom 
> they are addressed. If you have received this email in error, you 
> are directed not to read, disclose, reproduce, distribute, 
> disseminate or otherwise use this transmission, and we also
> request that you immediately delete this message and its
> attachments, if any. Delivery of this message to any person other
> than the intended recipient(s) is not intended in any way to waive
> privilege or confidentiality. Finally, the recipient should check
> this email and any attachments for the presence of viruses;
> Blumetech accepts no liability for any damage caused by any virus
> transmitted by this email.
> 

Anthony,

My relevant line looks like this (all one line of course):

$SU - $TOMCAT_USER -c "${CONFIG_OPTS} ${CAT_PID} ${TOMCAT_INSTANCE}
start" >> $SERVICE_LOG 2>&1

$SU                - set to su for non-SELinux, runuser for SELinux
$TOMCAT_USER       - Tomcat user
${CONFIG_OPTS}     - CATALINA_HOME, CATALINA_BASE, JRE_HOME, etc.
${CAT_PID}         - PID, not used in startup
${TOMCAT_INSTANCE} - Tomcat command based on CATALINA_HOME
$SERVICE_LOG       - logs the start and stop of the service

I stuff all of the options in a file which is parsed and placed into
${CONFIG_OPTS}. I could probably use setenv.sh, but this way I have a
root-controlled (and versioned) configuration file for my service
configuration.

I use catalina.sh directly, which is buried in the ${TOMCAT_INSTANCE}
variable. This is so I can do start and stop with one command setup.

Based on that and using catalina.sh, your command line should probably
look like:

start() {
    echo -n "Starting Tomcat:  "
    su - $TOMCAT_USER -c "{$CATALINA_HOME}/bin/catalina.sh start"
    sleep 2
}

Make sure your permissions in $CATALINA_HOME are correct.

And your su might need to be runuser, depending on whether or not you
use SELinux.

. . . just my two cents
/mde/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBAgAGBQJUUUOsAAoJEEFGbsYNeTwtc30H+wYMoqdkvsnnVoxo/ettJVco
UgBuWJBVnyWAuHvmDytNnh6YmtWAzaAQDTtC3lHll25Po0lv0giORXRz8GGI3wlM
OJejGeCYj2sjPSOCSMv2DpSCaYn/nR9VD7TUbjM5wx1Co31lxbT3z2QDz/2LQFoI
yt/312hiaJERKRRAjHmmYKU1Za+dlpat6kNoCZBKgu1nDqML6gj0gENV0AhScZwp
tAAu0J275KR4prMGRJxsI9Et+w52ORCfcH00NURHnEv+4v15eWm2/egzerzGFxh7
20kwIukUqBaNVCab6+rvH8xuwCyNGJqiKb3sR87GB6iTi47p7rWhod40Ou9qWvA=
=BzOH
-----END PGP SIGNATURE-----

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat Start script not starting from init.d or rc.local

Posted by Jason Ricles <jg...@alum.lehigh.edu>.
You can use upstart if you have that, with a .conf file. However unless you
source the profile.d or wherever your environment variables are held do not
use them in an init task!

On Wed, Oct 29, 2014 at 1:55 PM, Christopher Schultz <
chris@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Anthony,
>
> On 10/29/14 1:33 PM, Anthony Bungeroth wrote:
> > I basically need a script to run automatically when I reboot the
> > server.
> >
> > I have tried the various ways to get it to work in init.d and it's
> > not working.  When I go into init.d and run it manually it works
> > though.
>
> That's good.
>
> > I think it has something to do with the fact that to run the
> > script manually I am logged in as root, whereas for it to run
> > automatically it has to run in the background.
>
> /etc/init.d are not usually run "in the background". Most /etc/init.d
> scripts are processed as "root" on boot, so that shouldn't matter.
>
> > I will include the script info in this email and see if you had an
> > idea as to where the issue is.
> >
> > So in /etc/init.d, there is a script called Tomcat, here is the
> > "start" portion of the script.  Once again, when I run this
> > manually while logged in as root it launches.
> >
> > #!/bin/sh # Apache Tomcat Startup Script # chkconfig 234 20 80
> >
> > JAVA_HOME=/opt/jdk1.6.0_45 CATALINA_HOME=/opt/tomcat
> > TOMCAT_USER=tomcat
> >
> > start() { echo -n "Starting Tomcat:  " su $TOMCAT_USER
> > $CATALINA_HOME/bin/startup.sh
>
> I'm not sure that's going to work. "man su". On my system, the command
> comes first (with a "-c" switch), the username last. You might want to
> consider using "sudo" instead of "su".
>
> > sleep 2
>
> Sleep? Why?
>
> > }
> >
> > I tried creating a new script and putting that one in "rc.local".
> > Here is the "rc.local" command:
> >
> > #!/bin/sh # # This script will be executed *after* all the other
> > init scripts. # You can put your own initialization stuff in here
> > if you don't # want to do the full Sys V style init stuff.
> >
> > su tomcat /opt/tomcat/bin/startup.sh
> >
> > This is a total rookie issue I am sure....but just in case you
> > might be able to help with an easy enough fix, I would greatly
> > appreciate it.  I don't even know where to look for error logs to
> > troubleshoot this.
>
> Don't use rc.local. Use /etc/init.d/[whatever]
>
> Remember that /etc/init.d scripts aren't directly executed at boot:
> you have to "ln -s" each script into /etc/rcX.d where X is the
> runlevel number into which the machine is booting.
>
> Hope that helps,
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1
> Comment: GPGTools - http://gpgtools.org
>
> iQIcBAEBCAAGBQJUUSooAAoJEBzwKT+lPKRYjLoQAMmtQ2fm12YbKDC6893mjO0T
> Hf9oBBDxoBLxkIGu1LC/DUs3GQTGrer3IikNTdIfYzF66ULClD0qxziNbtLcEjtw
> OLAIiA1cp0zMw2J5NTg5xacyVO8EH9yvKYlgjroLQBfwqK7woo58f4hnh91TkVTZ
> uWwY1d/wt0iJ2nVeScQh9xGYonZkMeLpDFryG+ANAgXOomqzz7uRz52Tsfp46Q7f
> 9laPkMRu8paNJ86TSZtr+fQ/NQhhWh+6F8rgqxf/FYwxwbWzN7hgleX4oAev0tTv
> uM8lOz4tdWreKHMAXGGgrLY/55sCTdPtGlwf11hsMnh6OuUsjEbigzwA5y544kf+
> L/bPN1Bc2LwfoMffjjZceORTRK7/j1JrkkMNRYe1g+RjT6Vxio0kal83m6P61X7N
> 4SwGzZCwHNwbK0I3O03Y7SsBd8uvtX905IyTKr1Vqh71LKVg3y3Xm0wrAeCWq6q5
> WmiUSOAyHPDuiC7YuYRCEqva0zTi5vBrZ4sDQT0uQ/p4JRLG6orIZWeDYqD+n4jE
> OsFGnAGU7MGKoePElrxWecalxxrQg3Bd1rhp3+BbjKuSb+c43RjN6NflaExTER8S
> kV8iXAheHhm/IE8JXjwuNHnWHx6PDe4tVyURVaaW8GSgkCXbqyCAwFV1CKxlTlWn
> Vw6zW2S1K67Ffd7nsO4Z
> =K5zX
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Tomcat Start script not starting from init.d or rc.local

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Anthony,

On 10/29/14 1:33 PM, Anthony Bungeroth wrote:
> I basically need a script to run automatically when I reboot the 
> server.
> 
> I have tried the various ways to get it to work in init.d and it's 
> not working.  When I go into init.d and run it manually it works 
> though.

That's good.

> I think it has something to do with the fact that to run the
> script manually I am logged in as root, whereas for it to run
> automatically it has to run in the background.

/etc/init.d are not usually run "in the background". Most /etc/init.d
scripts are processed as "root" on boot, so that shouldn't matter.

> I will include the script info in this email and see if you had an 
> idea as to where the issue is.
> 
> So in /etc/init.d, there is a script called Tomcat, here is the 
> "start" portion of the script.  Once again, when I run this
> manually while logged in as root it launches.
> 
> #!/bin/sh # Apache Tomcat Startup Script # chkconfig 234 20 80
> 
> JAVA_HOME=/opt/jdk1.6.0_45 CATALINA_HOME=/opt/tomcat 
> TOMCAT_USER=tomcat
> 
> start() { echo -n "Starting Tomcat:  " su $TOMCAT_USER
> $CATALINA_HOME/bin/startup.sh

I'm not sure that's going to work. "man su". On my system, the command
comes first (with a "-c" switch), the username last. You might want to
consider using "sudo" instead of "su".

> sleep 2

Sleep? Why?

> }
> 
> I tried creating a new script and putting that one in "rc.local". 
> Here is the "rc.local" command:
> 
> #!/bin/sh # # This script will be executed *after* all the other
> init scripts. # You can put your own initialization stuff in here
> if you don't # want to do the full Sys V style init stuff.
> 
> su tomcat /opt/tomcat/bin/startup.sh
> 
> This is a total rookie issue I am sure....but just in case you
> might be able to help with an easy enough fix, I would greatly
> appreciate it.  I don't even know where to look for error logs to
> troubleshoot this.

Don't use rc.local. Use /etc/init.d/[whatever]

Remember that /etc/init.d scripts aren't directly executed at boot:
you have to "ln -s" each script into /etc/rcX.d where X is the
runlevel number into which the machine is booting.

Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJUUSooAAoJEBzwKT+lPKRYjLoQAMmtQ2fm12YbKDC6893mjO0T
Hf9oBBDxoBLxkIGu1LC/DUs3GQTGrer3IikNTdIfYzF66ULClD0qxziNbtLcEjtw
OLAIiA1cp0zMw2J5NTg5xacyVO8EH9yvKYlgjroLQBfwqK7woo58f4hnh91TkVTZ
uWwY1d/wt0iJ2nVeScQh9xGYonZkMeLpDFryG+ANAgXOomqzz7uRz52Tsfp46Q7f
9laPkMRu8paNJ86TSZtr+fQ/NQhhWh+6F8rgqxf/FYwxwbWzN7hgleX4oAev0tTv
uM8lOz4tdWreKHMAXGGgrLY/55sCTdPtGlwf11hsMnh6OuUsjEbigzwA5y544kf+
L/bPN1Bc2LwfoMffjjZceORTRK7/j1JrkkMNRYe1g+RjT6Vxio0kal83m6P61X7N
4SwGzZCwHNwbK0I3O03Y7SsBd8uvtX905IyTKr1Vqh71LKVg3y3Xm0wrAeCWq6q5
WmiUSOAyHPDuiC7YuYRCEqva0zTi5vBrZ4sDQT0uQ/p4JRLG6orIZWeDYqD+n4jE
OsFGnAGU7MGKoePElrxWecalxxrQg3Bd1rhp3+BbjKuSb+c43RjN6NflaExTER8S
kV8iXAheHhm/IE8JXjwuNHnWHx6PDe4tVyURVaaW8GSgkCXbqyCAwFV1CKxlTlWn
Vw6zW2S1K67Ffd7nsO4Z
=K5zX
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org