Tell me more ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

I'm new when coming to services/daemons. I found this: http://stackoverflow.com/questions/1221110/windows-like-services-development-in-linux-using-mono/1234761#1234761

I'm trying to start my test program as a daemon, but I can't get it to work.

I did as follow:

sudo nano /etc/init.d/MyMonoApp2

CODE:

#/etc/init.d/MyMonoApp
#

APP_NAME="MyMonoApp2"
APP_PATH="/home/pi/daemon"

APP_USER=pi

case "$1" in
start)


    echo "Starting $APP_NAME"

    start-stop-daemon --start \
                      --background \
                      --make-pidfile \
                      --pidfile /var/run/$APP_NAME.pid \
                      --chuid $APP_USER \
                      --exec "$APP_PATH/$APP_NAME"
;;
stop)

    echo "Stopping $APP_NAME"
            start-stop-daemon -o  --stop \
            --pidfile /var/run/$APP_NAME.pid

;;
*)
echo "Usage: /etc/init.d/$APP_NAME {start|stop}"
exit 1
;;
esac

exit 0

$ sudo chmod +x /etc/init.d/MyMonoApp2

$ sudo update-rc.d MyMonoApp2 defaults

at my home dir:

$ sudo mkdir daemon

$ sudo wget http://gruffman.se/rpi/net/RPi.Time.Net.exe

$ sudo MyMonoApp2

CODE:

#!/bin/sh
#!/home/pi/MyMonoApp2

APP_NAME=`basename $0`
APP_DIR=`dirname $0`
HOSTNAME=`hostname`

cd $APP_DIR

tail --lines=300 output.log  | mail -s "MyMonoApp $HOSTNAME:$APP_NAME STARTED" "me@email.com"

exitcode=0
until [ $exitcode -eq 9 ]
do
    startdate="$(date +%s)"
    /usr/local/bin/mono RPi.Time.Net.exe $HOSTNAME:$APP_NAME > output.log
    exitcode=$?
    enddate="$(date +%s)"

    echo "EXIT CODE = $exitcode" >> output.log

    cp -f output.log output.log.1
    elapsed_seconds="$(expr $enddate - $startdate)"
    echo "Elapsed seconds $elapsed_seconds"


    subject="EXIT CODE: $exitcode"
    echo "BASH: Exit Code = $exitcode"

    if [ $exitcode -eq 6 ] #Restart
    then
      subject="RESTART"
    elif [ $exitcode -eq 7 ] #Previous version
    then
      subject="PREVIOUS VERSION"
      cp -fv MyMonoApp.exe_previous RPi.Time.Net.exe
    elif [ $exitcode -eq 8 ] #Update
    then
      subject="SOFTWARE UPDATE"
      cp -fv RPi.Time.Net.exe MyMonoApp.exe_previous
      mv -fv MyMonoApp.exe_new RPi.Time.Net.exe
    elif [ $exitcode -eq 9 ] #Shutdown
    then
      subject="SHUTDOWN"
    fi


    if [ $elapsed_seconds -ge 10 ]  #been running for longer than 10 seconds
    then
            tail --lines=300 output.log  | mail -s "MyMonoApp $HOSTNAME:$APP_NAME $subject" "me@email.com"
            sleep 1  # tiny delay to let things settle
    else
            sleep 5  # delay to protect against eating the CPU resourses
    fi

done

THen: $ sudo service MyMonoApp2 start $sudo chkconfig ..... just to see that it's off :(

The output file only gives me Exit code 127.

Cheers!

share|improve this question
Could it be that I have missed include some System lib in my program? – Christian Feb 28 at 11:59

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.