Post a new topicPost a reply Page 1 of 1   [ 5 posts ]
Author Message
 Post subject: Start own program while boot up
PostPosted: Thu Feb 24, 2011 4:05 pm 

Joined: Wed Feb 09, 2011 12:07 pm
Posts: 9
Hi,

I've write an C/C++ program which read data from the Sensors and write these data in a database. This program is not integrated in the Manager System. Now my question, what must I do that this program start as a kind of background service like apache(the program must be able to run without any user login)? Must I write my own deamon or is there an easier way to start up this program?

To start the program manuell I logged in as root and input these commands:

- remountrw //To get writting access which is needed for the logfiles
- ./etc/SensorToMySQL //to start the program

Is there a way to do this both command automatically?


Top
 Profile  
 
 Post subject: Re: Start own program while boot up
PostPosted: Fri Feb 25, 2011 3:07 pm 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 10391
You can take a look at our tutorial about launching a script at startup.


Top
 OnlineProfile  
 
 Post subject: Re: Start own program while boot up
PostPosted: Mon Feb 28, 2011 2:39 pm 

Joined: Wed Feb 09, 2011 12:07 pm
Posts: 9
Thank you, this solution works, but in mycase I had problems that the phpmyadmin not works after reboot. I solved this problem by using this command:

update-rc.d myscript.sh defaults 98 02

With this command the process starts really late and stop early when I shutdown the meshlium.


Top
 Profile  
 
 Post subject: Re: Start own program while boot up
PostPosted: Mon Feb 28, 2011 3:47 pm 

Joined: Wed Feb 09, 2011 12:07 pm
Posts: 9
now I've an other question:

When I start my program like the discription on the top, is there a command how I can stop this program from the consol? I tried /etc/init.d/myprogram stop but it don't works.


Top
 Profile  
 
 Post subject: Re: Start own program while boot up
PostPosted: Mon Feb 28, 2011 6:00 pm 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 10391
In linux, the /etc/init.d folder is used to start and stop daemons. You've got to start it, but you have to add to the script some way to stop your program (normally with a kill signal):

Code:
#! /bin/sh
# /etc/init.d/scriptName
#

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting script scriptName "
    /etc/SensorToMySQL  // invocation of your script
    ;;
  stop)
    echo "Stopping script scriptName"
    killall SensorToMySQL  // send a kill signal to the program
    ;;
  *)
    echo "Usage: /etc/init.d/scriptName {start|stop}"
    exit 1
    ;;
esac

exit 0



Top
 OnlineProfile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 5 posts ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of http://www.gamexe.net


© Libelium Comunicaciones Distribuidas S.L. | Terms of use