Raspimina
Posts: 58
Joined: Thu Feb 27, 2014 4:51 pm

startup/boot list with conditions [updated]

Thu Feb 27, 2014 5:17 pm

Hi to all the community :)
How can i full mange the startup list o rasbian distribution?

I know the manage with: init.d and update-rc
Are there other ways?

On the BOOT situation raspberry must upload some files over ftp connection on running "/opt/upload/upload" script.
On the HALT situation raspberry must delete some files on running "/opt/delete/delete" script.

This raspberry boot with auto connect on sakis3g and need to run the "/opt/upload/upload" script.
I want to start upload script only when sakis3g connection is established, haw can i manage this?
Last edited by Raspimina on Fri Feb 28, 2014 11:32 pm, edited 4 times in total.

Raspimina
Posts: 58
Joined: Thu Feb 27, 2014 4:51 pm

Re: advance manage of startup list

Thu Feb 27, 2014 7:49 pm

how can i be sure that my upload script will be execute at last command? (when the raspberry is full "UP" and 3G connected with sakis3g)
I ask for the simplest (easy to manage) solution :)



the full situation is:
1-raspberry POWER ON
2-auto mount USB drive on specific folder
3-auto connect via sakis3g on 3G network
4-auto connect with hamachi
5-(LAST STEP I WANT) run "upload" script that will upload on FTP connection the USB mount folder (on point 2)


thanks

Raspimina
Posts: 58
Joined: Thu Feb 27, 2014 4:51 pm

Re: advance manage of startup list

Fri Feb 28, 2014 2:33 am

i found a solution that works.

the script now has a longer sleep (90s) so im sure it runs when sakis3g is connected.
its so composed:

sudo nano /etc/init.d/upload

Code: Select all

#*********************************************************
#! /bin/sh
# /etc/init.d/upload

### BEGIN INIT INFO
# Provides:          upload
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Simple script to start a program at boot
# Description:       A simple script which will start / stop a program a boot / shutdown.
### END INIT INFO


case "$1" in
  start)
    sleep 90
    echo "Upload to FTP"
    # run application you want to start
    sudo /opt/upload/upload
    ;;
  stop)
    echo "Terminate process, also not necessary"
    # kill application you want to stop
    
    ;;
  *)
    echo "Usage: /etc/init.d/upload {start|stop}"
    exit 1
    ;;
esac

exit 0
#*********************************************************
sudo chmod 755 /etc/init.d/upload
sudo /etc/init.d/upload start
sudo /etc/init.d/upload stop
sudo update-rc.d upload defaults


this script runs one other script:
-> sudo /opt/upload/upload

Code: Select all

sudo mount -t vfat -o uid=pi,gid=pi /dev/sda1 /data
find /data -type f -exec curl -u ftpuser:ftppasswrd --ftp-create-dirs -T {} ftp://ftpurl/{} \;
rm -r /data/* -f -v
it works, but i want to add more "intelligence".
how can manage the last part of the script: rm -r /data/* -f -v
i want do execute it only if the ftp upload process it's all fine. How can i set conditions?

thanks

Raspimina
Posts: 58
Joined: Thu Feb 27, 2014 4:51 pm

Re: startup/boot list with conditions [updated]

Fri Feb 28, 2014 11:33 pm

Any suggestion? :(

User avatar
DougieLawson
Posts: 39300
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: startup/boot list with conditions [updated]

Fri Feb 28, 2014 11:56 pm

You can set dependencies in the LSB headers.

Code: Select all

# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “General discussion”