LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-16-2013, 07:13 PM   #1
ESWBitto
LQ Newbie
 
Registered: Jan 2013
Posts: 15

Rep: Reputation: Disabled
Unhappy Getting error on bashrc


Ok so here is what I did..

Distro 6 Centos

Goal: To be able to start kippo when user logs in.

What I have done is in the .bashrc file I added this

. /home/username/kippo-0.5/start.sh

and in the .bash_profile file I added this

if [ -f /kippo-0.5/start.sh ]; then
. /kippo-0.5/start.sh
fi



when I log into the user I get this...



Starting kippo in background...Traceback (most recent call last):
File "/usr/lib64/python2.6/site-packages/Twisted-10.2.0-py2.6-linux-x86_64.egg/twisted/application/app.py", line 631, in run
runApp(config)
File "/usr/lib64/python2.6/site-packages/Twisted-10.2.0-py2.6-linux-x86_64.egg/twisted/scripts/twistd.py", line 23, in runApp
_SomeApplicationRunner(config).run()
File "/usr/lib64/python2.6/site-packages/Twisted-10.2.0-py2.6-linux-x86_64.egg/twisted/application/app.py", line 374, in run
self.application = self.createOrGetApplication()
File "/usr/lib64/python2.6/site-packages/Twisted-10.2.0-py2.6-linux-x86_64.egg/twisted/application/app.py", line 439, in createOrGetApplication
application = getApplication(self.config, passphrase)
--- <exception caught here> ---
File "/usr/lib64/python2.6/site-packages/Twisted-10.2.0-py2.6-linux-x86_64.egg/twisted/application/app.py", line 450, in getApplication
application = service.loadApplication(filename, style, passphrase)
File "/usr/lib64/python2.6/site-packages/Twisted-10.2.0-py2.6-linux-x86_64.egg/twisted/application/service.py", line 400, in loadApplication
application = sob.loadValueFromFile(filename, 'application', passphrase)
File "/usr/lib64/python2.6/site-packages/Twisted-10.2.0-py2.6-linux-x86_64.egg/twisted/persisted/sob.py", line 203, in loadValueFromFile
fileObj = open(filename, mode)
exceptions.IOError: [Errno 2] No such file or directory: 'kippo.tac'

Failed to load application: [Errno 2] No such file or directory: 'kippo.tac'


So yeah...I don't know what I did wrong...I"m wondering if each file its showing is a dependency or if there is something that is more simple.
 
Old 01-16-2013, 07:34 PM   #2
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Well, that error message clearly states that kippo.tac could not be found. That's where the Python program sob.py was told to look for that data values it needed.

I'm not clear why you're sourcing the kippo script instead of just running it. (The period before the script is the source command. Omit it if you want the script executed as a command, or replace it by the exec command if you want control transferred to the script.)

<edit>
When the bashrc script is executed, it is normally run with the working directory set to the user's home directory. If the data file is not there, you could symlink to it from your home directory, or do a cd to the correct directory before you run the start script.

I.e., something like this:
Code:
cd kippo-0.5
sh start
cd ~
might be what you need.
</edit>

Last edited by PTrenholme; 01-16-2013 at 07:47 PM.
 
Old 01-17-2013, 01:23 PM   #3
ESWBitto
LQ Newbie
 
Registered: Jan 2013
Posts: 15

Original Poster
Rep: Reputation: Disabled
Thank you for your help I got it running by doing this in bashrc

cd /home/username/kippo-0.5
/home/username/kippo-0.5/start.sh
cd ~


Now how would I go about only having it ran once....scenario...If server was rebooted and had to log user back in....do the script...then if for some reason had to be logged out...then logged back in I don't want it to execute again.
 
Old 01-17-2013, 02:15 PM   #4
ESWBitto
LQ Newbie
 
Registered: Jan 2013
Posts: 15

Original Poster
Rep: Reputation: Disabled
I think I answered my own question this is what I put...


if [ -f /home/username/kippo-0.5/kippo.pid ]; then
echo "Kippo is already running"


else


cd /home/username/kippo-0.5
/home/username/kippo-0.5/start.sh
cd ~

fi

Do you see any issues with that compared to my scenario?

I'm new to creating scripts in bash... :/
 
Old 01-17-2013, 03:55 PM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Quote:
Originally Posted by ESWBitto View Post
I think I answered my own question this is what I put...


if [ -f /home/username/kippo-0.5/kippo.pid ]; then
echo "Kippo is already running"


else


cd /home/username/kippo-0.5
/home/username/kippo-0.5/start.sh
cd ~

fi

Do you see any issues with that compared to my scenario?

I'm new to creating scripts in bash... :/
Yes, all you're checking for is the existence of a file to see if the process is running, that's not enough. Who's creating the file? What's in it? Who's making sure that if the process is no longer running the file is removed? The way you have it, if whatever creates that file abandons it by mistake, hard shutdown, etc., your script will never start up the program again.

.bashrc really isn't the place to be putting startup calls for programs that should only be run once on boot, neither is .bash_profile. /etc/rc.local is a good place (if it can be run as root), or you can use the @reboot directive in cron if your version supports it, or various other methods:
http://www.cyberciti.biz/faq/linux-e...system-reboot/
 
Old 01-17-2013, 03:58 PM   #6
ESWBitto
LQ Newbie
 
Registered: Jan 2013
Posts: 15

Original Poster
Rep: Reputation: Disabled
I think it would work in this instance...Kippo can't be run as root.

the pid file it creates puts it in the kippo-0.5 directory and when the process isn't running the pid file isn't there.


I have some other programs that I would have to automate and I think your advice can help me there.
 
Old 01-17-2013, 04:08 PM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Quote:
Originally Posted by ESWBitto View Post
the pid file it creates puts it in the kippo-0.5 directory and when the process isn't running the pid file isn't there.
Sure, the program probably removes its own pid file when it closes on its own volition, but what happens if it crashes, or if the machine experiences a lock up or hard shut down and kippo doesn't get the chance to remove its pid file?

Just checking for the existence of a pid file isn't enough. You should look inside the file, chances are it contains the actual PID of the process. In which case your startup script should pull the PID out of the file and actually check if that PID is running, and if the process running with that PID has the correct name. Only if the PID contained in that file is currently running with the correct name should you skip the startup, otherwise it could just be an abandoned PID file that's preventing your script from ever launching the code.
 
Old 01-17-2013, 04:11 PM   #8
ESWBitto
LQ Newbie
 
Registered: Jan 2013
Posts: 15

Original Poster
Rep: Reputation: Disabled
I see what your saying...ok let me ask you this. I have looked at the pid itself and the pid number changes...so what would I do from there?
 
Old 01-17-2013, 04:16 PM   #9
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
How often does it change? Have you checked ps or top to see what the process with that PID is?

Every time the process starts it's going to be given a different PID, is that what you're referring to or does the PID in that file actually change while the same instance of kippo is still running?

Last edited by suicidaleggroll; 01-17-2013 at 04:18 PM.
 
Old 01-17-2013, 04:21 PM   #10
ESWBitto
LQ Newbie
 
Registered: Jan 2013
Posts: 15

Original Poster
Rep: Reputation: Disabled
Yes that's what I'm referring to....It doesn't change when that instance of kippo is running.
 
Old 01-17-2013, 04:29 PM   #11
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Ah alright, that's normal then. That's the reason why you should check that both the PID in that file is running AND that it has the right name. The kernel just arbitrarily assigns out PIDs in numerical order as processes are started, then when it hits the limit (32768 IIRC) it resets back to 1 and starts over.

It's entirely possible for kippo to be started with a PID of say 4000, then at some point it crashes and abandons the file. Some time later (hours, days), some other process that's started could be arbitrarily given a PID of 4000. So you want to make sure that when you check if the PID in that file is running, that you verify it's actually kippo using that PID and not some other process that came along hours/days after kippo abandoned the file and was arbitrarily assigned the same identifier.

It's rare for that to happen, yes, but if you want to be thorough that's the best way.

Last edited by suicidaleggroll; 01-17-2013 at 04:31 PM.
 
Old 01-17-2013, 05:51 PM   #12
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
I'd like to second suicidaleggroll.
When I started writing permanent daemon programs I cam across exactly this issue when writing cron watchdog progs to check/restart the main daemon.
These days I never bother with pid, even if stored in a file; I always check the exact process name.
 
Old 01-17-2013, 05:54 PM   #13
ESWBitto
LQ Newbie
 
Registered: Jan 2013
Posts: 15

Original Poster
Rep: Reputation: Disabled
ok so I have another one for you...

say I have a program that I want to run on root....when I edit the rc.local file and put in the same statement it works....but what I am wanting to do is take your advice and check for the pid itself rather than a file... and then echo a response to let me know either way...like this


if [ -f /var/run/program.pid ]; then
echo "Program Already Activated"


else


cd application
executable
echo "program Has been Launched "
cd ~


fi
 
Old 01-18-2013, 10:37 PM   #14
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Code:
$ id -u
1000
$ sudo id -u
0
And here's a program I sometimes source when I need root access. (Things like testing SysV init scripts, etc.)
Code:
$ cat Scripts/bash/CheckForRootAccess 
#!/bin/bash
function CheckForRootAccess()
{
  local whoami
  #
  # Check that sudo works for the user. Bypass the check if we're running as "root."
  #
  # Are we running as "root?"
  whoami=$(id -un)
  [ "${whoami}" = "root" ] && return 0
  #
  # Not "root." Confirm that the user has sudo permission.
  #
  echo You need root access to run this script. \(I.e.: You must be in the sudoers file.\)
  echo If prompted, enter your password for "sudo" to use.
  sudo echo OK - now we have root access.
  [ 0 != $? ] && echo Aborting. && return 1
  echo
  echo Note:      Many commands used in this scrip are prceeded by a "sudo" directive.
  echo            On most Linux system a "sudo" is only "good" for a few minutes, so it is
  echo            possible that you may receive additional "Password:" prompts as this
  echo            script is run.
  return 0
}

Last edited by PTrenholme; 01-18-2013 at 10:49 PM.
 
  


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
Error in bashrc filr vignesh4vi Linux - Desktop 4 11-04-2012 07:46 AM
bashrc error, while sourcing linux_2010 Programming 3 07-13-2010 01:36 AM
Setting path: /etc/profile, /etc/bashrc or ~/.bashrc Swakoo Linux - General 1 08-07-2007 11:59 PM
error on .bashrc ashley75 Linux - General 2 09-19-2005 08:09 PM
.bashrc error upon sourcing psiakr3w Linux - General 2 08-07-2004 01:44 AM


All times are GMT -5. The time now is 06:23 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