Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 7th, 2005, 11:50 PM   #11
thinkgeek
Newbie
 
Join Date: Jul 2005
Posts: 10
Rep Power: 0 thinkgeek is on a distinguished road
Will that file contain login information of NIS clients also?
thinkgeek is offline   Reply With Quote
Old Jul 11th, 2005, 10:14 AM   #12
Moldz
Programmer
 
Moldz's Avatar
 
Join Date: Feb 2005
Posts: 54
Rep Power: 4 Moldz is on a distinguished road
I'm not sure, what does the man page say? You could run a little test. When you know there are some NIS clients logged in, run the "who" program. It does exactly what I suggested, it reads the utmp file and prints the users.

Also, your daemon will not need to be a superuser to read this file, which will make it more secure. The last thing you want to do is open a hole in an important machine.
Moldz is offline   Reply With Quote
Old Jul 28th, 2005, 5:01 AM   #13
mchaudhary
Newbie
 
Join Date: Jul 2005
Posts: 2
Rep Power: 0 mchaudhary is on a distinguished road
Lightbulb Need help for installing .py-script as daemon process

Hello Dear

I am using CetOS4.0 and trying to create an init.d script for my python script. It is working fine if i have only one python script running as daemon.
If i run multiple daemons then the problem is "pidof" command. Which returns the pids of all Python programs.
I want to run few Python daemon on machine.
I also tried using

daemon $prog 2>&1 > /dev/null &
echo $! > $pidfile

but this return the pidof "daemon" rather than returning the PID of python script, in later case it also starts syslogger which i do not want to get executed with default setting.

Need hellp urgently.
Please provide some clue.

Manjeet Chaudhary
mchaudhary is offline   Reply With Quote
Old Jul 28th, 2005, 4:32 PM   #14
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
I'm under the assumption you're running your script by making it executable and placing the path to the Python interpreter on the top line, prefixed by a hash and an exclamation mark (e.g #!/usr/bin/python), and then calling it directly? You're not running `python myscript.py`, yes?
Cerulean is offline   Reply With Quote
Old Aug 3rd, 2005, 3:14 AM   #15
mchaudhary
Newbie
 
Join Date: Jul 2005
Posts: 2
Rep Power: 0 mchaudhary is on a distinguished road
Hello Cerulean

My init.d startup script is shell script and it is executable. Added the script in startup.
I am calling the Python script using command "python /path_to_server_script" from the init.d scrip.
In the server script i am using #!/usr/bin/env python; which i think is not required. The server script opens a port and keeps listening for req.
I am attaching the init.d script. Please check out and suggest.
Thank you.

My startup script is ...
-------------
# pidfile: /var/run/server_script.pid
# config:

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

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

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

RETVAL=0
pidfile="/var/run/server_script.pid"
lockfile="/var/lock/subsys/server_script"
name="server_script"
prog="python /opt/pkg/server_script.py"

start() {
#--------Check if server is already running
if [ -f $pidfile ]; then
pid=cat $pidfile
if [ ]ps -elf
touch $pidfile
touch $lockfile
echo -n "$name (pid `cat $pidfile`) is Running." && success
echo
exit 0
fi

echo -n $"Starting $name: "
$prog& 2>&1 > /dev/null
#--------Check for the success
if [ -z "`/sbin/pidof $prog`" ]; then
failure $"$prog startup"
RETVAL=1
else
pidofproc $prog > $pidfile && touch $lockfile && success $"$prog startup"
RETVAL=0
fi
echo
return $RETVAL
}

stop() {
echo -n $"Stopping $name: "
killproc server_script
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $lockfile && rm -f $pidfile
return $RETVAL
}


# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
;;
status)
#--------Check status
if [ -n "`/sbin/pidof $prog`" ]; then
pidofproc $prog > $pidfile
touch $lockfile
echo "$name (pid `cat $pidfile`) is Running."
else
echo "$name is not running."
RETVAL=3
fi
;;
*)
echo $"Usage: $0 {start|status|stop|restart|reload}"
exit 1
esac

exit $RETVAL
----------------
mchaudhary is offline   Reply With Quote
Old Aug 4th, 2005, 12:59 PM   #16
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Quote:
I am calling the Python script using command "python /path_to_server_script" from the init.d scrip.
Well there you go then. Don't do that. Make sure your Python script is executable (chmod a+x /path_to_server_script), and just call it directly (e.g `/path_to_server_script`).
Cerulean is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:41 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC