LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 07-24-2011, 03:11 AM   #1
zasavage
Member
 
Registered: Sep 2010
Location: Bloemfontein , South Africa
Distribution: Slackware 13.37 and Slackware 14
Posts: 201

Rep: Reputation: 6
Scripting Help Please


I have this script to start openerp-web
It works fine but when I want to restart or stop I get a error ..


cat: /var/spool/openerp/openerp-web.pid: No such file or directory
And yes the file is not there , was never created

What do I need to add to the script to make the pid ?

OPENERPWEB=/usr/bin/openerp-web
PIDFILE=/var/spool/openerp/openerp-web.pid
LOCKFILE=/var/lock/subsys/openerp-web
LOGFILE=/var/log/openerp/openerp-web.log
CONFIGFILE=/etc/openerp-web/openerp-web.cfg
# Start Openerp-Web:
openerp_start(){

if [ -f $OPENERPWEB ]; then
echo "Starting Openerp Web Server !"
if [ -e "$LOCKFILE" ]; then
echo "Openerp Web Server already running!"
echo "Please remove $LOCKFILE"
else

CMD="/usr/bin/openerp-web > /dev/null 2>&1"

su - openerp -c "$CMD" &

touch $LOCKFILE
fi
fi

}

# Stop Openerp-Web:
openerp_stop() {
echo "Stopping Openerp-Web-Server"
kill -TERM $(cat $PIDFILE) > /dev/null 2>&1
rm -f $LOCKFILE
}

# Restart Openerp-Web:
openerp_restart() {
openerp_stop
sleep 1
openerp_start
}

case "$1" in
'start')
openerp_start
;;
'stop')
openerp_stop
;;
'restart')
openerp_restart
;;
*)
echo "usage $0 start|stop|restart"


regards

Lawrence

Last edited by zasavage; 07-24-2011 at 05:38 AM.
 
Old 07-24-2011, 03:50 AM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,833
Blog Entries: 1

Rep: Reputation: 1229Reputation: 1229Reputation: 1229Reputation: 1229Reputation: 1229Reputation: 1229Reputation: 1229Reputation: 1229Reputation: 1229
Hi
Please use code tags for your code.
To create a file check the 'touch' command. This tutorial discusses pid files: http://kirk.webfinish.com/2009/10/ba...ationdeletion/

Have a look at this beginner's bash tutorial. It'll be handy
http://tldp.org/LDP/Bash-Beginners-Guide/html/

Also this bit does not make sense:
Code:
case "$1" in
'start')
openerp_start
;;
'stop')cat: /var/spool/openerp/openerp-web.pid: No such file or directory

openerp_stop
;;
'restart')
openerp_restart
;;
*)
echo "usage $0 start|stop|restart"
Have a look at the case statement examples
http://www.thegeekstuff.com/2010/07/...ase-statement/

Last edited by sycamorex; 07-24-2011 at 06:14 AM.
 
Old 07-24-2011, 05:40 AM   #3
zasavage
Member
 
Registered: Sep 2010
Location: Bloemfontein , South Africa
Distribution: Slackware 13.37 and Slackware 14
Posts: 201

Original Poster
Rep: Reputation: 6
@sycamorex

Thanks for the reply will take a look at your links

Fixed the no sense part ... I must have pasted that twice

If I can just get the script to actually make the pid file then it will work


regards

Lawrence
 
Old 07-24-2011, 10:00 AM   #4
vulcan59
Member
 
Registered: Sep 2007
Location: UK
Distribution: Slackware 14.1
Posts: 73

Rep: Reputation: 24
Sometimes the pid files can be created by the actual program. Check if there is a command line option for openerp-web to create the pid file.

If not, then something like this in the start part your script should work.
Code:
echo $(ps -ef | grep [o]penerp-web | awk '{print $2}') >$PIDFILE
 
Old 07-24-2011, 07:33 PM   #5
mRgOBLIN
Slackware Contributor
 
Registered: Jun 2002
Location: New Zealand
Distribution: Slackware
Posts: 999

Rep: Reputation: 229Reputation: 229Reputation: 229
Code:
echo $(pidof openerp-web) >$PIDFILE
 
Old 07-25-2011, 04:09 AM   #6
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,684

Rep: Reputation: 669Reputation: 669Reputation: 669Reputation: 669Reputation: 669Reputation: 669
You need root permissions to write to /var/lock/subsys are you running your script as root?
 
Old 07-25-2011, 05:36 AM   #7
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,368

Rep: Reputation: Disabled
Quote:
Originally Posted by Keith Hedger View Post
You need root permissions to write to /var/lock/subsys are you running your script as root?
Assuming this is an rc. file and gets called from rc.local on startup then yes is the answer. It looks like he need to ceate the pidfile manually as mentioned above.
 
Old 07-25-2011, 05:37 AM   #8
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,368

Rep: Reputation: Disabled
Quote:
Originally Posted by dive View Post
Assuming this is an rc. file and gets called from rc.local on startup then yes is the answer. It looks like he need to create the pidfile manually as mentioned above.
But if it isn't started as root or a user with the right permissions then that needs fixing.
 
Old 07-25-2011, 06:39 AM   #9
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196
Quote:
Originally Posted by sycamorex View Post
On line 67 better there were double quotes around $@

It might be an interesting and useful challenge to code for the race condition.
 
Old 07-25-2011, 10:22 AM   #10
roybal
LQ Newbie
 
Registered: Sep 2009
Posts: 8
Blog Entries: 8

Rep: Reputation: 0
The script should take care of the race condition by virtue of the "-o noclobber". Only one running instance of the script will succeed to create a PID file. First in wins.

BTW, that's my script :-)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Scripting the Linux desktop, Part 2: Scripting Nautilus LXer Syndicated Linux News 0 02-17-2011 04:02 AM
Firefox Scripting Add-on (Scripting HTML / Javascript inside Firefox) linuxbeatswindows Programming 1 09-18-2009 10:09 PM
Help with scripting rahilmaknojia Programming 3 08-03-2008 08:23 PM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
another help with scripting?! ice99 Programming 2 08-09-2005 08:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 09:34 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration