2

I am attempting to run a program that I made on startup on my Raberry Pi 2. It is running Debian (Jessie) but it doesn't seem to work. I tried following this guide: Debian: Running Scripts on StartUp and creating a system link but nothing seems to be working. The program works when I run it not on startup. Here's the code:

#!/bin/sh
#/etc/init.d/StartGRIP.sh
#

### BEGIN INIT INFO
# Provides:            StartGRIP.sh
# Required-Start:      $local_fs $network
# Required-Stop:       $local_fs
# Default-Start:       2 3 4 5
# Default-Stop:        0 1 6
# Short-Description:   Starts GRIP Pipeline
# Description:         During startup, runs below command and starts GRIP
### END INIT INFO
# Start processing
env LD_LIBRARY_PATH=/home/pi/vision/grip:LD_LIBRARY_PATH java -jar...

The last command works so I didn't include the whole line as it is a long line.

Any help is greatly appreciated!

Community
  • 1
  • 1
Jackson Haile
  • 77
  • 1
  • 1
  • 7
  • 1
    you can use [`update-rc.d`](http://www.debianadmin.com/manpages/updatercmanpage.htm) to generate the symlinks to the appropriate run levels (this assumes Sys V init), but with Systemd the whole process is different, see this [answer](https://unix.stackexchange.com/questions/47695/how-to-write-startup-script-for-systemd) for how to write systemd start up scripts – bjhaid Feb 20 '16 at 22:53
  • I've used that command, and it still doesn't work. I even tried creating one via `ls` – Jackson Haile Feb 20 '16 at 22:54
  • how did you use the command? if you don't specify the correct run level it will not start, also if the app depends on other things to start you have to ensure the dependencies start before it – bjhaid Feb 20 '16 at 22:57
  • Link to the guide I followed: http://stackoverflow.com/questions/8837680/adding-symlink-to-scripts-into-rcnumber-d-folders-to-start-process-during-syst – Jackson Haile Feb 20 '16 at 22:57
  • I linked it to rc2.d – Jackson Haile Feb 20 '16 at 23:00
  • Surely the second LD_LIBRARY_PATH on the last line needs a dollar sign in front of it? – Mark Setchell Feb 20 '16 at 23:43
  • you should have the script in `/etc/init.d/`, so let's assume your script is `/etc/init.d/StartGRIP.sh` all you need to run is `sudo update-rc.d StartGRIP.sh defaults` – bjhaid Feb 20 '16 at 23:45
  • I have done that a lot, doesn't work :/ – Jackson Haile Feb 21 '16 at 00:51
  • To create a symlink, use the 'ln' command, not 'ls'. – jeremiah Feb 23 '16 at 15:37

2 Answers2

3

Create a desktop entry for the program and place it in ~/.config/autostart

As an example that starts Safe Eyes program placing it as ~/.config/autostart/safeeyes.desktop.

[Desktop Entry]
Encoding=UTF-8
Version=0.9.4
Type=Application
Name=Safe Eyes
Comment=Protect your eyes from eye strain
Exec=safeeyes
OnlyShowIn=XFCE;
StartupNotify=false
Terminal=false
Hidden=false
Categories=Utility;

[Optional] Set the proper permission.

  sudo chmod 644 /.config/autostart/[program-name].desktop
amrezzd
  • 1,787
  • 15
  • 38
1

Alternative way:

sudo crontab -e

And add

@reboot file_you_want_to_run &
Van Tr
  • 5,889
  • 2
  • 20
  • 44
  • Not sure why but, this is unreliable, however, works most of the time. Not sure at what runlevel this is executed. – fcm Apr 30 '16 at 13:47
  • There is no need to run the script in the background. `cron` by definition runs asynchronously. – tripleee Nov 08 '20 at 15:32