Start own program while boot up

How to configure Meshlium or use the Manager System
Post Reply
baumschupsa
Posts: 9
Joined: Wed Feb 09, 2011 11:07 am

Start own program while boot up

Post by baumschupsa » Thu Feb 24, 2011 3:05 pm

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?

libelium-dev
Posts: 23952
Joined: Mon Sep 28, 2009 12:06 pm

Re: Start own program while boot up

Post by libelium-dev » Fri Feb 25, 2011 2:07 pm


baumschupsa
Posts: 9
Joined: Wed Feb 09, 2011 11:07 am

Re: Start own program while boot up

Post by baumschupsa » Mon Feb 28, 2011 1:39 pm

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.

baumschupsa
Posts: 9
Joined: Wed Feb 09, 2011 11:07 am

Re: Start own program while boot up

Post by baumschupsa » Mon Feb 28, 2011 2:47 pm

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.

libelium-dev
Posts: 23952
Joined: Mon Sep 28, 2009 12:06 pm

Re: Start own program while boot up

Post by libelium-dev » Mon Feb 28, 2011 5:00 pm

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: Select all

#! /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


Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests