LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-03-2008, 08:07 AM   #1
samengr
Member
 
Registered: Jan 2008
Posts: 59

Rep: Reputation: 15
how to create startup script?


Hi All

I have installed tomcat on RHEL4/5. It doesnt create start/stop scripts in /etc/rc.d/init.d/ --> /etc/init.d/.

Now i am stoping and starting tomcat by
#/opt/tomcat/bin/startup.sh
#/opt/tomcat/bin/shutdown.sh

but i want to configure this in a script in init.d/ directory.

I tired my self by writing a script after seeing the others in /etc/rc.d/init.d/

#!/bin/sh
#
# description: Jakarta Tomcat Java Servlets and JSP server
# processname: tomcat

start_tomcat=/opt/tomcat/bin/startup.sh
stop_tomcat=/opt/tomcat/bin/shutdown.sh

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

start() {
echo -n "Starting tomcat: "
su -c ${start_tomcat} - tomcat
echo "done."
}
stop() {
echo -n "Shutting down tomcat: "
# Add stop flag file
touch $CATALINA_HOME/temp/.manualStop
su -c ${stop_tomcat} - tomcat
echo "done."
}

# See how we were called
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 10
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
esac

exit 0



but i am getting error if i run this script.

[root@localhost /]/etc/init.d/tomcat stop
-bash: /etc/init.d/tomcat: /bin/sh^M: bad interpreter: No such file or directory.

/etc/init.d/tomcat start/stop/restart.


Can any body help me to see whats wrong here?
Thanks.
 
Old 04-03-2008, 08:40 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
i think you saved the file in msdos format, if you open the file in vi you'll probably see ^M's at the end of each line, which (afair) is the linefeed character which is used in dos format but not unix format.
 
Old 04-04-2008, 01:15 AM   #3
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
you can clean up those carriage returns in vim with:
Code:
:1,$s/\r//
 
Old 04-04-2008, 09:55 AM   #4
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,561

Rep: Reputation: 57
On a Debian, I have my startup scripts as :
/etc/rc2.d/S99startupscripts
chmod +rx /etc/rc2.d/S99startupscripts

and they starts with #/bin/bash
bla bla
 
Old 04-08-2008, 08:14 AM   #5
samengr
Member
 
Registered: Jan 2008
Posts: 59

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by acid_kewpie View Post
i think you saved the file in msdos format, if you open the file in vi you'll probably see ^M's at the end of each line, which (afair) is the linefeed character which is used in dos format but not unix format.
Hi ya,

I have typed it now in vi editor by removing the previous one but getting the same error. "-bash: /etc/init.d/tomcat: /bin/sh^M: bad interpreter: No such file or directory." Even i replaced /bin/bash to /bin/sh but it didnt work and the same error "bash: /etc/init.d/tomcat: /bin/bash^M: bad interpreter: No such file or directory."

Any body can see this problem?
 
Old 04-08-2008, 08:53 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
You can always use dos2unix to convert a file from msdos to unix format. For details:
Code:
man dos2unix
Regards
 
Old 04-15-2008, 07:39 AM   #7
samengr
Member
 
Registered: Jan 2008
Posts: 59

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by bathory View Post
You can always use dos2unix to convert a file from msdos to unix format. For details:
Code:
man dos2unix
Regards
Hi

I used the same command dos2unix /etc/rc.d/tomcat,
but still getting the same error "-bash: /etc/init.d/tomcat: /bin/sh^M: bad interpreter: No such file or directory." Even i replaced /bin/bash to /bin/sh but it didnt work and the same error "bash: /etc/init.d/tomcat: /bin/bash^M: bad interpreter: No such file or directory."

please help me to solve this issue.
 
Old 04-15-2008, 08:44 AM   #8
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
I cannot figure out what happens with your script. I've tested in my system and ti works. Can you try the following much simpler script to see if it works (change JAVA_HOME if needed)?
Code:
#!/bin/sh
# Tomcat Startup Script

export CATALINA_HOME=/opt/tomcat
export JAVA_HOME=/usr/java
export TOMCAT_OWNER=tomcat

start() {
        echo -n "Starting Tomcat:  "
        su $TOMCAT_OWNER -c $CATALINA_HOME/bin/startup.sh
}
stop() {
        echo -n "Stopping Tomcat: "
        su $TOMCAT_OWNER -c $CATALINA_HOME/bin/shutdown.sh
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
        start
        ;;
  *)
        echo $"Usage: tomcat {start|stop|restart}"
        exit
esac
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Create new script that runs on startup pnellesen SUSE / openSUSE 1 01-23-2007 08:29 PM
How to create a Linux Startup script?? Cypher12 Linux - Networking 1 12-18-2006 02:16 PM
How Do I Create A Startup Script? joany MEPIS 21 11-30-2006 04:43 PM
newbie - how to create a startup script gogogadgetearl Linux - Software 2 10-02-2005 08:14 PM
Trying to create a startup script for tuxnes emulator Kilahchris Linux - Software 1 10-28-2004 05:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration