Member Avatar for iamthwee

Hi guys,

I've come to a road block so i need some help.

1)I have an exe which i need to run at start up.

So I put the following bash file in the inid.d directory:

#!/bin/bash
#
#

. /etc/rc.d/init.d/functions

EXE_DIR="/root/monkey-0.9.2/bin/"
EXE_NAME="monkey"


#############################################################
#################### Functions ##############################
#############################################################

function start {
    RUNNING=`ps -ef | grep -c ./${EXE_NAME}\$`
    if [ $RUNNING -ge 1 ]; then
        echo "${EXE_NAME} is already running"
        echo_failure
	echo ""
    else
	if [ ! -x "${EXE_DIR}${EXE_NAME}" ]; then
		echo ""
		echo  "[error] ${EXE_NAME} doesn't exist"
		echo_failure
		echo ""
	else
                cd "${EXE_DIR}"                
                sleep 1
		./${EXE_NAME} > output &
	        disown
                echo  "Restarting ${EXE_NAME}"
		echo_ok
		echo ""
	fi
    fi
}

function stop {
    echo ""
    echo "Stopping ${EXE_NAME}"
    RUNNING=`ps -ef | grep -c ./${EXE_NAME}\$`
    if [ $RUNNING -ge 1 ]; then
	ID=`ps -ef | grep ${EXE_NAME} | grep -v grep | awk '{print $2}'`
	echo "PID= $ID"
	kill -9 $ID
	echo_ok
	echo ""
    else
        echo  "${EXE_NAME} is not running"
        echo_failure
        echo ""
    fi


    return 0;
}

function restart {
	stop
	start
	return 1;
}

function status {
    RUNNING=`ps -ef | grep -c ./${EXE_NAME}\$`
    if [ $RUNNING -ge 1 ]; then
	echo  "${EXE_NAME} Running"
        echo_ok
        echo ""
	tail -f "${EXE_DIR}output"
    else
        echo "${EXE_NAME} Not Running"
        echo_failure
        echo ""
    fi
}

#############################################################
###################### MAIN #################################
#############################################################


case "$1" in
	start)
		start
	;;

	stop)
		stop
	;;

	restart)
		restart
	;;

	details|status)
		status
	;;
	
	*)

	exit 1
esac

exit 0

The funny thing is the pid says it is running on boot. But it only works when I log on and restart the program manually?!

Any ideas?

Recommended Answers

All 24 Replies

What do you mean "The funny thing is the pid says it is running on boot"? Scripts in init.d must be referenced from their run levels. Depending on your distro you should have a command for update-rc.d to specify the run levels to execute the scripts.

Also the symlink naming convention for executing a process in the rc?.d directories is important. For example if monkey logs to syslog but starts before syslog is running then you may have a problem. HTTPDs are typically one of the last processes to start.

[edit]
One more thing .. usually scripts use pidfiles in /var/run . There are a lot of situations where ps may not return what you expect. ie a user has a process start up with your exe's name which will cause your script to think it is already running, regardless of its current state.
[/edit]

commented: Thanks for the help +11
Member Avatar for iamthwee

>What do you mean "The funny thing is the pid says it is running on boot"?

Well the program (c++) is actually running on start up. You see it is mini light-weight webserver.

http://www.monkey-project.com/

However, when I go to the web page it comes up with the 404 page not found error. But when I restart the program manually from the terminal, it works fine.

>Depending on your distro you should have a command for update-rc.d to specify the run levels to execute the scripts.

At the moment I'm running it off a itx board that was compiled from scratch. I didn't do it so I'm kinda clueless. But if I can get this working in ubuntu for example it would be a start.

Thanx in advance.

Post the output for this sk:/etc# ls -al rc?.d/ Your directory structure appears to be a little different in /etc so you may need to find where the rc?.d's are located: sk:/etc# find ./ -iname rc\*\.d

Member Avatar for iamthwee

Here is my output:

root@localhost:/etc# ls -al rc.d/
total 44
drwxr-xr-x 11 root root 4096 Oct  6  2008 .
drwxr-xr-x 13 root root 4096 Jan  1 00:00 ..
drwxr-xr-x  2 root root 4096 Aug 14  2009 init.d
drwxr-xr-x  2 root root 4096 Aug 10  2009 rc0.d
drwxr-xr-x  2 root root 4096 Oct  6  2008 rc1.d
drwxr-xr-x  2 root root 4096 Nov 24  2008 rc2.d
drwxr-xr-x  2 root root 4096 Aug 14  2009 rc3.d
drwxr-xr-x  2 root root 4096 Oct  6  2008 rc4.d
drwxr-xr-x  2 root root 4096 Oct  6  2008 rc5.d
drwxr-xr-x  2 root root 4096 Oct  6  2008 rc6.d
drwxr-xr-x  2 root root 4096 Oct  6  2008 rcsysinit.d
root@localhost:/etc# drwxr-xr-x 11 root root 4096 Oct  6  2008 .
-bash: drwxr-xr-x: command not found
root@localhost:/etc# drwxr-xr-x 13 root root 4096 Jan  1 00:00 ..
-bash: drwxr-xr-x: command not found
drwxr-xr-x  2 root root 4096 Aug 10  2009 rc0.d
drwxr-xr-x  2 root root 4096 Oct  6  2008 rc1.d
root@localhost:/etc# drwxr-xr-x  2 root root 4096 Aug 14  2009 init.d
drwxr-xr-x  2 root root 4096 Oct  6  2008 rc4.d
drwxr-xr-x  2 root root 4096 Oct  6  2008 rc5.d
-bash: drwxr-xr-x: command not found
drwxr-xr-x  2 root root 4096 Oct  6  2008 rc6.d
drwxr-xr-x  2 root root 4096 Oct  6  2008 rcsysinit.d
root@localhost:/etc# drwxr-xr-x  2 root root 4096 Aug 10  2009 rc0.d
-bash: drwxr-xr-x: command not found
root@localhost:/etc# drwxr-xr-x  2 root root 4096 Oct  6  2008 rc1.d
-bash: drwxr-xr-x: command not found
root@localhost:/etc# drwxr-xr-x  2 root root 4096 Nov 24  2008 rc2.d
-bash: drwxr-xr-x: command not found
root@localhost:/etc# drwxr-xr-x  2 root root 4096 Aug 14  2009 rc3.d
-bash: drwxr-xr-x: command not found
root@localhost:/etc# drwxr-xr-x  2 root root 4096 Oct  6  2008 rc4.d
-bash: drwxr-xr-x: command not found
root@localhost:/etc# drwxr-xr-x  2 root root 4096 Oct  6  2008 rc5.d
-bash: drwxr-xr-x: command not found
root@localhost:/etc# drwxr-xr-x  2 root root 4096 Oct  6  2008 rc6.d
-bash: drwxr-xr-x: command not found
root@localhost:/etc# drwxr-xr-x  2 root root 4096 Oct  6  2008 rcsysinit.d
-bash: drwxr-xr-x: command not found
root@localhost:/etc#

eh that wasn't the command I posted. ls -al rc?.d/ the ? expands for rc0.d/ rc1.d/ to list the directory contents, such as:

sk:/etc# ls -al rc?.d | less
rc0.d:
total 16
drwxr-xr-x   2 root root 4096 Mar 31  2007 .
drwxr-x--x 129 root root 8192 Aug 17 18:30 ..
lrwxrwxrwx   1 root root   17 Feb 12  2007 K09apache2 -> ../init.d/apache2
lrwxrwxrwx   1 root root   14 Oct 15  2004 K11cron -> ../init.d/cron
lrwxrwxrwx   1 root root   19 Oct 15  2004 K19setserial -> ../init.d/setserial
lrwxrwxrwx   1 root root   14 Feb  8  2005 K20acct -> ../init.d/acct
lrwxrwxrwx   1 root root   20 Dec  1  2005 K20bittorrent -> ../init.d/bittorrent
lrwxrwxrwx   1 root root   17 Dec 19  2004 K20caudium -> ../init.d/caudium
lrwxrwxrwx   1 root root   28 Oct 19  2004 K20courier-authdaemon -> ../init.d/courier-authdaemon
lrwxrwxrwx   1 root root   22 Oct 19  2004 K20courier-imap -> ../init.d/courier-imap
lrwxrwxrwx   1 root root   26 Oct 19  2004 K20courier-imap-ssl -> ../init.d/courier-imap-ssl
lrwxrwxrwx   1 root root   21 Nov 23  2004 K20courier-pop -> ../init.d/courier-pop
lrwxrwxrwx   1 root root   25 Nov 23  2004 K20courier-pop-ssl -> ../init.d/courier-pop-ssl
lrwxrwxrwx   1 root root   16 Feb 25  2005 K20distcc -> ../init.d/distcc
lrwxrwxrwx   1 root root   13 Mar  7  2007 K20gpm -> ../init.d/gpm
lrwxrwxrwx   1 root root   17 Nov 24  2004 K20mailman -> ../init.d/mailman
lrwxrwxrwx   1 root root   17 Oct 15  2004 K20makedev -> ../init.d/makedev
lrwxrwxrwx   1 root root   15 Jul 14  2005 K20mbmon -> ../init.d/mbmon
lrwxrwxrwx   1 root root   17 Oct 15  2004 K20oidentd -> ../init.d/oidentd
lrwxrwxrwx   1 root root   23 Feb 26  2007 K20openbsd-inetd -> ../init.d/openbsd-inetd
lrwxrwxrwx   1 root root   19 Feb 21  2005 K20pure-ftpd -> ../init.d/pure-ftpd
lrwxrwxrwx   1 root root   15 Oct 18  2004 K20qmail -> ../init.d/qmail
lrwxrwxrwx   1 root root   16 Nov 22  2004 K20quagga -> ../init.d/quagga
lrwxrwxrwx   1 root root   15 Mar 18  2006 K20rsync -> ../init.d/rsync
lrwxrwxrwx   1 root root   15 Oct 23  2004 K20snmpd -> ../init.d/snmpd
lrwxrwxrwx   1 root root   13 Oct 15  2004 K20ssh -> ../init.d/ssh
lrwxrwxrwx   1 root root   17 Mar 12  2007 K20sysstat -> ../init.d/sysstat
lrwxrwxrwx   1 root root   16 Oct 23  2004 K20webmin -> ../init.d/webmin
lrwxrwxrwx   1 root root   22 Nov 23  2004 K21spamassassin -> ../init.d/spamassassin
lrwxrwxrwx   1 root root   13 Feb  1  2007 K23ntp -> ../init.d/ntp
lrwxrwxrwx   1 root root   20 Feb 22  2007 K25hwclock.sh -> ../init.d/hwclock.sh
lrwxrwxrwx   1 root root   23 Oct 15  2004 K30etc-setserial -> ../init.d/etc-setserial
lrwxrwxrwx   1 root root   18 Jun 20  2005 K40arpwatch -> ../init.d/arpwatch
lrwxrwxrwx   1 root root   16 Nov 22  2004 K75hdparm -> ../init.d/hdparm
lrwxrwxrwx   1 root root   18 Jan 25  2005 K79quotarpc -> ../init.d/quotarpc
lrwxrwxrwx   1 root root   15 Oct 16  2004 K85bind9 -> ../init.d/bind9
lrwxrwxrwx   1 root root   15 Jan 25  2005 K85quota -> ../init.d/quota
lrwxrwxrwx   1 root root   13 Nov 27  2004 K89atd -> ../init.d/atd
lrwxrwxrwx   1 root root   15 Oct 15  2004 K89klogd -> ../init.d/klogd
lrwxrwxrwx   1 root root   18 Oct 15  2004 K90sysklogd -> ../init.d/sysklogd
lrwxrwxrwx   1 root root   16 Oct 23  2004 K91apache -> ../init.d/apache
lrwxrwxrwx   1 root root   20 Feb 27  2005 K91apache-ssl -> ../init.d/apache-ssl
lrwxrwxrwx   1 root root   12 Oct 23  2004 K99ud -> ../init.d/ud
-rw-r--r--   1 root root  355 Jan  7  2006 README
lrwxrwxrwx   1 root root   18 Feb  1  2007 S20sendsigs -> ../init.d/sendsigs
lrwxrwxrwx   1 root root   17 Oct 15  2004 S30urandom -> ../init.d/urandom
lrwxrwxrwx   1 root root   22 Oct 15  2004 S31umountnfs.sh -> ../init.d/umountnfs.sh
lrwxrwxrwx   1 root root   20 Oct 15  2004 S35networking -> ../init.d/networking
lrwxrwxrwx   1 root root   18 Oct 15  2004 S40umountfs -> ../init.d/umountfs
lrwxrwxrwx   1 root root   20 Sep 12  2005 S60umountroot -> ../init.d/umountroot
lrwxrwxrwx   1 root root   14 Oct 15  2004 S90halt -> ../init.d/halt

rc1.d:
total 16
drwxr-xr-x   2 root root 4096 Mar 31  2007 .
drwxr-x--x 129 root root 8192 Aug 17 18:30 ..
lrwxrwxrwx   1 root root   17 Feb 12  2007 K09apache2 -> ../init.d/apache2
lrwxrwxrwx   1 root root   14 Oct 15  2004 K11cron -> ../init.d/cron
lrwxrwxrwx   1 root root   14 Feb  8  2005 K20acct -> ../init.d/acct
lrwxrwxrwx   1 root root   17 Dec 19  2004 K20caudium -> ../init.d/caudium
lrwxrwxrwx   1 root root   28 Oct 19  2004 K20courier-authdaemon -> ../init.d/courier-authdaemon
Member Avatar for iamthwee

I am also going to attach the web-server files as their hosting seems to be down.

Member Avatar for iamthwee

Oh right not sure, I'm completely lost when it comes to shell scripting and linux

root@localhost:/etc# find ./ -iname rc\*\.d
./rc.d
./rc.d/rc6.d
./rc.d/rc2.d
./rc.d/rc0.d
./rc.d/rcsysinit.d
./rc.d/rc1.d
./rc.d/rc5.d
./rc.d/rc3.d
./rc.d/rc4.d
root@localhost:/etc#

Ok -- now try this: ls -alR /etc/rc.d/rc?.d It will be a lot of output so you have two options
1) Write it to a file: ls -alR /etc/rc.d/rc?.d >> /tmp/outfile 2) Use a pager: ls -alR /etc/rc.d/rc?.d | less or ls -alR /etc/rc.d/rc?.d | more . Your system may not have one of the pagers installer. In my opinion less > more, but either will work.

I have looked at the source and I have a question. In your init script you have ./${EXE_NAME} > output & where the & is apparently how you're trying to make it a background process.
From the INSTALL file:

 Running Monkey
 ==============

        bin/monkey

        or

        bin/monkey -D (to run monkey in background mode)

Shouldn't you be using -D to put it in Daemon/background mode instead of using &? Also your redirect only handles stdout but not stderr, and if something isn't initializing properly it will probably write to stderr. It should look like: ./${EXE_NAME} >> output 2>&1 &. Using ">" overwrites the file if it exists, or creates a new file where ">>" appends or creates a new file so your log will keep growing.

Member Avatar for iamthwee

Ok I'm not sure what this is telling you but

root@localhost:/etc# ls -alR /etc/rc.d/rc?.d
/etc/rc.d/rc0.d:
total 8
drwxr-xr-x  2 root root 4096 Aug 10  2009 .
drwxr-xr-x 11 root root 4096 Oct  6  2008 ..
lrwxrwxrwx  1 root root   14 Apr 16  2009 K30sshd -> ../init.d/sshd
lrwxrwxrwx  1 root root   20 Aug 10  2009 K31estar -> ../init.d/init_estar
lrwxrwxrwx  1 root root   21 Aug 10  2009 K32monkey -> ../init.d/init_monkey
lrwxrwxrwx  1 root root   14 Apr 16  2009 K35alsa -> ../init.d/alsa
lrwxrwxrwx  1 root root   16 Apr 16  2009 K45random -> ../init.d/random
lrwxrwxrwx  1 root root   13 Apr 16  2009 K46ntp -> ../init.d/ntp
lrwxrwxrwx  1 root root   20 Apr 16  2009 K48nfs-server -> ../init.d/nfs-server
lrwxrwxrwx  1 root root   17 Apr 16  2009 K49portmap -> ../init.d/portmap
lrwxrwxrwx  1 root root   17 Apr 16  2009 K80network -> ../init.d/network
lrwxrwxrwx  1 root root   18 Apr 16  2009 K90sysklogd -> ../init.d/sysklogd
lrwxrwxrwx  1 root root   21 Apr 16  2009 S60sendsignals -> ../init.d/sendsignals
lrwxrwxrwx  1 root root   17 Apr 16  2009 S70mountfs -> ../init.d/mountfs
lrwxrwxrwx  1 root root   14 Apr 16  2009 S80swap -> ../init.d/swap
lrwxrwxrwx  1 root root   18 Apr 16  2009 S90localnet -> ../init.d/localnet
lrwxrwxrwx  1 root root   14 Apr 16  2009 S99halt -> ../init.d/halt

/etc/rc.d/rc1.d:
total 8
drwxr-xr-x  2 root root 4096 Oct  6  2008 .
drwxr-xr-x 11 root root 4096 Oct  6  2008 ..
lrwxrwxrwx  1 root root   14 Apr 16  2009 K30sshd -> ../init.d/sshd
lrwxrwxrwx  1 root root   14 Apr 16  2009 K35alsa -> ../init.d/alsa
lrwxrwxrwx  1 root root   13 Apr 16  2009 K46ntp -> ../init.d/ntp
lrwxrwxrwx  1 root root   20 Apr 16  2009 K48nfs-server -> ../init.d/nfs-server
lrwxrwxrwx  1 root root   17 Apr 16  2009 K49portmap -> ../init.d/portmap
lrwxrwxrwx  1 root root   17 Apr 16  2009 K80network -> ../init.d/network
lrwxrwxrwx  1 root root   18 Apr 16  2009 K90sysklogd -> ../init.d/sysklogd
lrwxrwxrwx  1 root root   16 Apr 16  2009 S25random -> ../init.d/random

/etc/rc.d/rc2.d:
total 8
drwxr-xr-x  2 root root 4096 Nov 24  2008 .
drwxr-xr-x 11 root root 4096 Oct  6  2008 ..
lrwxrwxrwx  1 root root   14 Apr 16  2009 K30sshd -> ../init.d/sshd
lrwxrwxrwx  1 root root   13 Apr 16  2009 K46ntp -> ../init.d/ntp
lrwxrwxrwx  1 root root   20 Apr 16  2009 K48nfs-server -> ../init.d/nfs-server
lrwxrwxrwx  1 root root   17 Apr 16  2009 K49portmap -> ../init.d/portmap
lrwxrwxrwx  1 root root   17 Apr 16  2009 K80network -> ../init.d/network
lrwxrwxrwx  1 root root   18 Apr 16  2009 K90sysklogd -> ../init.d/sysklogd
lrwxrwxrwx  1 root root   16 Apr 16  2009 S25random -> ../init.d/random

/etc/rc.d/rc3.d:
total 8
drwxr-xr-x  2 root root 4096 Aug 14  2009 .
drwxr-xr-x 11 root root 4096 Oct  6  2008 ..
lrwxrwxrwx  1 root root   18 Apr 16  2009 S10sysklogd -> ../init.d/sysklogd
lrwxrwxrwx  1 root root   17 Apr 16  2009 S20network -> ../init.d/network
lrwxrwxrwx  1 root root   17 Apr 16  2009 S22portmap -> ../init.d/portmap
lrwxrwxrwx  1 root root   16 Apr 16  2009 S25random -> ../init.d/random
lrwxrwxrwx  1 root root   14 Apr 16  2009 S30sshd -> ../init.d/sshd
lrwxrwxrwx  1 root root   20 Aug 10  2009 S40estar -> ../init.d/init_estar
lrwxrwxrwx  1 root root   21 Aug 14  2009 S45monkey -> ../init.d/init_monkey

/etc/rc.d/rc4.d:
total 8
drwxr-xr-x  2 root root 4096 Oct  6  2008 .
drwxr-xr-x 11 root root 4096 Oct  6  2008 ..
lrwxrwxrwx  1 root root   18 Apr 16  2009 S10sysklogd -> ../init.d/sysklogd
lrwxrwxrwx  1 root root   17 Apr 16  2009 S20network -> ../init.d/network
lrwxrwxrwx  1 root root   17 Apr 16  2009 S22portmap -> ../init.d/portmap
lrwxrwxrwx  1 root root   20 Apr 16  2009 S24nfs-server -> ../init.d/nfs-server
lrwxrwxrwx  1 root root   16 Apr 16  2009 S25random -> ../init.d/random
lrwxrwxrwx  1 root root   13 Apr 16  2009 S26ntp -> ../init.d/ntp
lrwxrwxrwx  1 root root   14 Apr 16  2009 S30sshd -> ../init.d/sshd

/etc/rc.d/rc5.d:
total 8
drwxr-xr-x  2 root root 4096 Oct  6  2008 .
drwxr-xr-x 11 root root 4096 Oct  6  2008 ..
lrwxrwxrwx  1 root root   18 Apr 16  2009 S10sysklogd -> ../init.d/sysklogd
lrwxrwxrwx  1 root root   17 Apr 16  2009 S20network -> ../init.d/network
lrwxrwxrwx  1 root root   17 Apr 16  2009 S22portmap -> ../init.d/portmap
lrwxrwxrwx  1 root root   20 Apr 16  2009 S24nfs-server -> ../init.d/nfs-server
lrwxrwxrwx  1 root root   16 Apr 16  2009 S25random -> ../init.d/random
lrwxrwxrwx  1 root root   13 Apr 16  2009 S26ntp -> ../init.d/ntp
lrwxrwxrwx  1 root root   14 Apr 16  2009 S30sshd -> ../init.d/sshd

/etc/rc.d/rc6.d:
total 8
drwxr-xr-x  2 root root 4096 Oct  6  2008 .
drwxr-xr-x 11 root root 4096 Oct  6  2008 ..
lrwxrwxrwx  1 root root   14 Apr 16  2009 K30sshd -> ../init.d/sshd
lrwxrwxrwx  1 root root   14 Apr 16  2009 K35alsa -> ../init.d/alsa
lrwxrwxrwx  1 root root   16 Apr 16  2009 K45random -> ../init.d/random
lrwxrwxrwx  1 root root   13 Apr 16  2009 K46ntp -> ../init.d/ntp
lrwxrwxrwx  1 root root   20 Apr 16  2009 K48nfs-server -> ../init.d/nfs-server
lrwxrwxrwx  1 root root   17 Apr 16  2009 K49portmap -> ../init.d/portmap
lrwxrwxrwx  1 root root   17 Apr 16  2009 K80network -> ../init.d/network
lrwxrwxrwx  1 root root   18 Apr 16  2009 K90sysklogd -> ../init.d/sysklogd
lrwxrwxrwx  1 root root   21 Apr 16  2009 S60sendsignals -> ../init.d/sendsignals
lrwxrwxrwx  1 root root   17 Apr 16  2009 S70mountfs -> ../init.d/mountfs
lrwxrwxrwx  1 root root   14 Apr 16  2009 S80swap -> ../init.d/swap
lrwxrwxrwx  1 root root   18 Apr 16  2009 S90localnet -> ../init.d/localnet
lrwxrwxrwx  1 root root   16 Apr 16  2009 S99reboot -> ../init.d/reboot
root@localhost:/etc#

Btw the script I gave in post #1 works fine to start up a c++ exe I've written myself if it means I don't have to use the SKELETON one you suggested.

Member Avatar for iamthwee

I have looked at the source and I have a question. In your init script you have ./${EXE_NAME} > output & where the & is apparently how you're trying to make it a background process.
From the INSTALL file:


Shouldn't you be using -D to put it in Daemon/background mode instead of using &? Also your redirect only handles stdout but not stderr, and if something isn't initializing properly it will probably write to stderr. It should look like: ./${EXE_NAME} >> output 2>&1 & . Using ">" overwrites the file if it exists, or creates a new file where ">>" appends or creates a new file so your log will keep growing.

No idea, I didn't write the script. Can you update the script with what you think it should be and I'll try it with that.

Thanx for you help so far!

That output tells me that your init script is referenced in runlevels 0 (halt) and 3 (depends on distro). What distro is that machine running?

"Standard": 3 Multi-User Mode with Networking Starts the system normally
Debian: 2-5 are same
Redhat: Multi-User mode, console logins only
SuSE: 3 Multi-User mode, console logins only
Slackware: 3 Multi-User mode without display manager

So depending on what distro you're using that may be the wrong runlevel. One way of finding the distro:

sk:/etc# find /etc -maxdepth 1 -iname \*rel\* ; find /etc -maxdepth 1 -iname \*ver\*
/etc/squirrelmail
/etc/debian_version

I think redhat creates /etc/redhat-release .. but most all distros have a file named "release" or "version" in /etc.

Member Avatar for iamthwee

Erm I vaguely remember the guy saying something about using linux from scratch? Does that matter?

I mean if that makes things a bit more easier.


I'll forget that for the time being and just try to get this working at start up for ubuntu as a vmware image?

But I really need this to work on start up.

Ok.. try this. kill the httpd, backup your file, replace it with this, and see if it starts. If it starts OK then try rebooting the machine.

#!/bin/bash
#
#

. /etc/rc.d/init.d/functions

EXE_DIR="/root/monkey-0.9.2/bin/"
EXE_NAME="monkey"


#############################################################
#################### Functions ##############################
#############################################################

function start {
    RUNNING=`ps -ef | grep -c ./${EXE_NAME}\$`
    if [ $RUNNING -ge 1 ]; then
        echo "${EXE_NAME} is already running"
        echo_failure
	echo ""
    else
	if [ ! -x "${EXE_DIR}${EXE_NAME}" ]; then
		echo ""
		echo  "[error] ${EXE_NAME} doesn't exist"
		echo_failure
		echo ""
	else
                # cd "${EXE_DIR}"                
                # sleep 1
		# ./${EXE_NAME} > output &
	        # disown
                ${EXE_DIR}${EXE_NAME} -D >> ${EXE_DIR}output 2>&1
                echo  "Restarting ${EXE_NAME}"
		echo_ok
		echo ""
	fi
    fi
}

function stop {
    echo ""
    echo "Stopping ${EXE_NAME}"
    RUNNING=`ps -ef | grep -c ./${EXE_NAME}\$`
    if [ $RUNNING -ge 1 ]; then
	ID=`ps -ef | grep ${EXE_NAME} | grep -v grep | awk '{print $2}'`
	echo "PID= $ID"
	kill -9 $ID
	echo_ok
	echo ""
    else
        echo  "${EXE_NAME} is not running"
        echo_failure
        echo ""
    fi


    return 0;
}

function restart {
	stop
	start
	return 1;
}

function status {
    RUNNING=`ps -ef | grep -c ./${EXE_NAME}\$`
    if [ $RUNNING -ge 1 ]; then
	echo  "${EXE_NAME} Running"
        echo_ok
        echo ""
	tail -f "${EXE_DIR}output"
    else
        echo "${EXE_NAME} Not Running"
        echo_failure
        echo ""
    fi
}

#############################################################
###################### MAIN #################################
#############################################################


case "$1" in
	start)
		start
	;;

	stop)
		stop
	;;

	restart)
		restart
	;;

	details|status)
		status
	;;
	
	*)

	exit 1
esac

exit 0

After the machine reboots examing the contents of the log file and see if it even tried to execute. If it didn't execute then we'll add it to the other standard startup runlevels.

Member Avatar for iamthwee

Ok I just tried that new script, but it didn't work.

The webpage still failed to load.


[edit]
Out of interest does it work on your machine.

To see it working you should be able to open your webbrowser, type in: localhost:2001

And it should server out the web page.

in order to start the exe manually, you go to

> cd monkey-0.9.2
> cd bin
> ./banana restart

This is of course after you've ran the config and make file.

There could be a million things going wrong with the distro being LFS. Up for doing a gotomeeting or logmein and I can take a look at it? That would be the easiest way :)

With the new script is the daemon running? What does the contents of /root/monkey-0.9.2/bin/output have? Take a look at it: tail -50 /root/monkey-0.9.2/bin/output

wait a minute.... you're running ./banana but the script you posted earlier references a different file:

EXE_DIR="/root/monkey-0.9.2/bin/"
EXE_NAME="monkey"

Those are running two different files in the bin directory .. unless they're symlinked to eachother?

[edit]
I don't know if it will work on my machines. It requires a ton of libs that I don't have installed.
[/edit]

Member Avatar for iamthwee

The output is:

root@localhost:~/monkey-0.9.2/bin# more output
Monkey HTTP Daemon 0.9.2
Built : Aug  9 2009 22:38:40
Home  : http://monkeyd.sourceforge.net

Which is probably useless no doubt.

Again, have you tried getting it to work for your linux distro.

If you can get it to run at start up that would be encouraging.

Not sure how to do the logmein. Is it something you gotta pay for?

Thanx again.

Member Avatar for iamthwee

>I don't know if it will work on my machines. It requires a ton of libs that I don't have installed.

No not at all, the reason why we chose it because it is a stand-alone web server much lighter than apache.

At least you probably need g++/gcc

You should just be able to run the make and config files. If you could test it, that would be better cos then we'd both be on the same page so to speak. :)


[edit]
banana is just a script which EXECUTES the monkey exe.

Eh yeah actually it has the required libs installed it just for some reason is failing in the configure. That httpd hasn't really been updated since ~2004. I use "lighttpd" in cases where I need a standalone webserver. Let me try to get this app compiled.

[edit]
I also sent you a PM if you want to try that route. It will probably be quicker
[/edit]

Don't forget to mark it as solved ;)

Take care

Member Avatar for iamthwee

Thanks you're the man!

Member Avatar for iamthwee

If anyone else has the same problem it was a permission problem...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.