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. |
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 </edit> |
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. |
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... :/ |
Quote:
.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/ |
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. |
Quote:
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. |
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?
|
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? |
Yes that's what I'm referring to....It doesn't change when that instance of kippo is running.
|
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. |
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. |
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 |
Code:
$ id -u Code:
$ cat Scripts/bash/CheckForRootAccess |
All times are GMT -5. The time now is 11:57 PM. |