Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Using Fedora
FedoraForum Search

Forgot Password? Join Us!

Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 17th June 2011, 05:03 AM
lovetide Offline
Registered User
 
Join Date: Mar 2006
Location: ShenZhen,China;深圳
Age: 34
Posts: 18
windows_xp_2003ie
Wink F15 A init.d service script works with `service X start` but not `systemctl start X`

I wrote a service script, and want to start tomcat6 when reboot. but it not work:
  • the script file is /etc/init.d/tomcat6 (see the following)
  • i've already chkconfig --add tomcat6, and no error occur, chkconfig --list can list tomcat6 service
  • service tomcat6 start/stop can work properly
  • but after reboot or systemctl start/stop tomcat6.service does not start tomcat6: the script was executed, and a file was created by the script
  • SELinux is in Enforcing mode, but setenforce 0 does not help.
  • Fedora 15, kernel 2.6.38.8-32.fc15.x86_64

There're no related log in /var/log/message, /var/log/audit/audit.log logged the following:
Code:
type=USER_CMD msg=audit(1308242653.204:369): user pid=3002 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='cwd="/" cmd="/usr/tomcat6/bin/startup.sh" terminal=? res=failed'
type=SERVICE_START msg=audit(1308242653.228:370): user pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg=': comm="tomcat6" exe="/bin/systemd" hostname=? addr=? terminal=? res=success'
There's failed at the end of the first line, but I can't get more detail information from it.


/etc/init.d/tomcat6
Code:
#!/bin/bash
#
# Startup script for Tomcat
#
# chkconfig: 35 80 20
# description: Tomcat service script
### BEGIN INIT INFO
# Provides: tomcat6
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start: 3 5
# Default-Stop: 0 1 2 4 6
# Short-Description: Start and stop tomcat6
# Description: Tomcat 6, servlet 2.5, JSP 2.1
### END INIT INFO

ret=0

NAME="$(basename $0)"
LOCK_FILE="/var/lock/subsys/$NAME"
TOMCAT_HOME=/usr/tomcat6

start ()
{
        if [ -f "$LOCK_FILE" ]
        then
                echo "$LOCK_FILE exists, this assuming Tomcat is running ! If it's not, delete $LOCK_FILE and start again."
                exit 2
        fi

        echo "Starting $NAME ..."
        sudo -u tomcat "$TOMCAT_HOME/bin/startup.sh"
        touch "$LOCK_FILE"
}
stop ()
{
        echo "Stopping $NAME ..."
        sudo -u tomcat "$TOMCAT_HOME/bin/shutdown.sh"
        rm -f "$LOCK_FILE"
}
restart ()
{
        stop
        start
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                restart
                ;;
        *)
                echo "$1 is not supported."
                echo "Usage: $0 {start|stop|restart}"
                exit 3
esac


exit $ret
am i missed something or something wrong in the script?

---------- Post added at 12:03 PM ---------- Previous post was at 12:50 AM ----------

I don't know how to debug/verbose the output `systemctl start XX`, so I redirect some output in the script to a log file. finally, it's `sudo` failed with

Code:
sudo: sorry, you must have a tty to run sudo
it seems the internal mechanism between `service` and `systemctl` are different.

I take a look at the official tomcat6 init.d script, the offcial one use `/bin/su` or `/sbin/runuser`, not `sudo`. after I changed from `sudo` to `su`, the script works now.

Code:
#!/bin/bash
#
# Startup script for Tomcat
#
# chkconfig: 35 80 20
# description: Tomcat service script
### BEGIN INIT INFO
# Provides: tomcat6
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start: 3 5
# Default-Stop: 0 1 2 4 6
# Short-Description: Start and stop tomcat6
# Description: Tomcat 6, servlet 2.5, JSP 2.1
### END INIT INFO

ret=0

NAME="$(basename $0)"
LOCK_FILE="/var/lock/subsys/$NAME"
#LOG_FILE=/var/log/tomcat6-service-log.txt
#chown ${TOMCAT_USER}:${TOMCAT_USER} "$LOG_FILE"
#whoami >> "$LOG_FILE"

TOMCAT_HOME=/usr/tomcat6
TOMCAT_USER="${TOMCAT_USER:-tomcat}"
TOMCAT_LOG="$TOMCAT_HOME/logs/catalina.out"

SU_COMMAND="/bin/su"
if [ -x "/sbin/runuser" ]; then
        # For SELinux we need to use 'runuser' not 'su'
        SU_COMMAND="/sbin/runuser"      # /sbin/runuser -s /bin/sh
fi

start ()
{
        if [ -f "$LOCK_FILE" ]
        then
                echo "$LOCK_FILE exists, this assuming Tomcat is running ! If it's not, delete $LOCK_FILE and start again."
                exit 2
        fi

        echo "Starting 正在启动 $NAME ..."
        # 如果用 systemctl start tomcat6.service 来启动,则 sudo 失败:sudo: sorry, you must have a tty to run sudo
        #sudo -u tomcat "$TOMCAT_HOME/bin/startup.sh" >> "$LOG_FILE" 2>&1
        #consoletype >> "$LOG_FILE" 2>&1
        $SU_COMMAND $TOMCAT_USER -c "$TOMCAT_HOME/bin/startup.sh" >> "$TOMCAT_LOG" 2>&1
        touch "$LOCK_FILE"
}
stop ()
{
        echo "Stopping 正在停止 $NAME ..."
        #sudo -u tomcat "$TOMCAT_HOME/bin/shutdown.sh" >> "$LOG_FILE" 2>&1
        $SU_COMMAND $TOMCAT_USER -c "$TOMCAT_HOME/bin/shutdown.sh" >> "$TOMCAT_LOG" 2>&1
        rm -f "$LOCK_FILE"
}
restart ()
{
        stop
        start
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                restart
                ;;
        *)
                echo "$1 is not supported. 尚不不支持 $1 操作"
                echo "Usage 用法: $0 {start|stop|restart}"
                exit 3
esac

exit $ret
__________________
linux newbie/菜鸟 :eek:
http://maclife.net

Last edited by lovetide; 17th June 2011 at 05:09 AM. Reason: solved
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
DNS service won`t start dronale Using Fedora 0 14th June 2011 11:17 AM
difference between service and systemctl roger F15 Development 1 23rd April 2011 02:05 AM
Can't start nmb service in F9 OralDeckard Servers & Networking 2 27th May 2008 05:19 PM
chkconfig wokrs but service start says unknow service gkk Servers & Networking 4 10th December 2007 02:45 AM
how to start service linoob Servers & Networking 7 23rd May 2006 07:15 PM


Current GMT-time: 08:29 (Friday, 24-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat