Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
sh start
cd ~
might be what you need.
</edit>
Last edited by PTrenholme; 01-16-2013 at 06:47 PM.
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... :/
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/
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.
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 03:18 PM.
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 03:31 PM.
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.
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 ~
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 09:49 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.