How to run a program on startup in Debian - linux

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!

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

Alternative way:
sudo crontab -e
And add
#reboot file_you_want_to_run &

Related

Starting vnc-server with command every startup in linux

I run a headless Kali Linux raspberry pi.
I got the ssh to work properly and start at boot.
I got the vnc working but only when I start it manually from terminal.
Problem:
I need to start the vnc-server every time the raspberry boots.
And I have tried like a 100 different things from google but this seems to be the "most" successful for me.
I have created a .sh file with this content:
File path: /root/Documents/startavnc.sh
x11vnc -gui -display :0 -usepw -rfbport 5900 -bg
This code works when I run it directly in terminal.
I have then created this file:
/etc/init.d/startavnc
With the following contents:
#!/bin/sh
### BEGIN INIT INFO
# Provides: startavnc
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $network $time
# Should-Stop: $network $time
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stops the vnc-server
# Description: Controls the automatic start of vnc-server at reboot
### END INIT INFO
/root/Documents/startavnc.sh
I took these LBG-stuff from another file and I'm not sure if I need all. But I got some errors when they where not included so I added them.
I then ran:
chmod ugo+x /etc/init.d/startavnc
update-rc.d startavnc defaults
When it didn't work I googled some more and ran:
ln -s /etc/init.d/startavnc /etc/rc.d
And it still aren't executing when I boot up the pi.
Can you see some obvious fault in this?
I'm, as you probably already figured, a Linux newbie...
Thanks!

how to check whether Linux is going down for halt or reboot

I need to execute some command when system is going down for halt/poweroff.
I need to know this inside my script /etc/init.d/myScript which is called when system is going down.
I used to do it by checking $runlevel variable and if it is set to 0, then system was going down for halt, it was working for instance in Raspbian a few years ago.
However, in my Linux cubieboard2 4.9.12-sunxi Armbian this variable is not set, and when I execute "runlevel" command inside "STOP" case in myScript it says it is in N 5 runlevel which is not true because I have executed poweroff
All tips are welcome.
Handling runlevel in script will not be needed if you are adhering to LSB standard.
As per LSB spec, you might like to header to your script. Following is a example
header.
### BEGIN INIT INFO
# Provides: scriptname
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
More details at chapter 20 of LSB standard
Additionally, you can control runlevel at which your script will invoked.It can also be controlled by chkconfig command

Won't boot because of rc.local start up script

Environment :
Virtualization software : VMware Workstation 12 Player
Guest Machine : Red Hat 6.4
Host Machine : Windows 7 Professional Service Pack 1
Question :
I'm trying to execute automatically a svn update at the boot of my virtual machine. I edited the rc.local file like this :
#!/bin/sh -e
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
sleep 10
svn update path/to/repository
exit 0
But with this the virtual machine won't boot, it keeps loading (If I remove the svn command line, there is no problem). And if I try to shutdown or restart the guest, we can see this :
So it means that svn command was executed but it didn't work. I already tried writing "svn update --username user --password xxx" but same result. How do I get the svn command to run?
What if you create the file in /etc/init.d/svnserve
#!/bin/bash
### BEGIN INIT INFO
# Provides: svnserve
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: true
# Short-Description: Start/stop svnserve
### END INIT INFO
svnserve -d -r /PATH/TO/YOUR/REPOSITORY
Make it Executable:
chmod u+x /etc/init.d/svnserve
Create links from runlevels to the script:
update-rc.d svnserve
Then check if the links were created correctly
find /etc/ -name '*svnserve*'
Best regards
Xsi

Starting node app at startup on raspberry pi

EDIT: As per Jim Rush's advice I'm now using rc.local instead of init.d direclty to run forever start on boot up.
I'm wracking my head on this one.
I'm wanting to start a node app on the raspberry pi startup and reboot. I'm using forever to actually call the app and using init.d for the debian style start instructions.
I've created the kuuyi file within the /etc/init.d directory, given it a permission of 755 and, after editing the file, ran update-rc.d kuuyi defaults to hopefully trigger Raspbian to start it on restart/boot.
Here's my init.d file:
#!/bin/sh
#/etc/init.d/kuuyi
### BEGIN INIT INFO
# Provides: kuuyi
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Kuuyi
### END INIT INFO
case "$1" in
start)
/usr/local/bin/forever --sourceDir=/home/pi/kuuyi_device -p /root/.forever run.js
;;
stop)
/usr/local/bin/forever stop --sourceDir=/home/pi/kuuyi_device run.js
;;
*)
echo "Usage: /etc/init.d/kuuyi {start|stop}"
exit 1
;;
esac
exit 0
Any ideas as to why this isn't working? I'm running Raspbian on a Raspberry Pi B+. I've run /etc/init.d kuuyi start and forever kicks and begins the app just fine. Its just not happening after booting up the machine.
Any help on this is so appreciated, I'm about as wrung out as an old cheese cloth after dairy day on this one.
I run node (actually nodemon) from /etc/rc.local. Just the command line with & at the end. I also redirect stderr and stdout to log files to troubleshoot startup and crash problems. Getting the permissions right, on any directory that was written to, was one of my early problems.
Example:
PATH=$PATH:/opt/node/bin
cd /var/node/RoadsterNode
/opt/node/bin/nodemon /var/node/RoadsterNode/app.js < /dev/null >/var/tmp/startup.log 2>/var/tmp/startup.err &

Why is a deluge startup script necessary?

I'm currently working on making a spare Raspberry Pi into a headless BitTorrent box, using Deluge.
Most guides on setting up Deluge on Linux include a custom startup script that will be run at boot. However, when you're SSH'd into the Pi, you can start the deluged daemon by simply typing in "deluged".
However, when I wrote a basic bash script which ran this command, put it in /etc/init.d/ and added it using update-rc.d, it didn't work.
nano /etc/init.d/startdeluged.sh
chmod 755 /etc/init.d/startdeluged.sh
update-rc.d startdeluged.sh defaults
The bash script contained this:
#!/bin/sh
deluged
exit
I'm new to setting up startup scripts on Linux, and I'm just wondering why a special script is necessary when simply running a command in the Terminal has the same effect. Does it have anything to do with the user who is entering the command?
You must add the begin init infos after #!/bin/sh. It looks like that :
### BEGIN INIT INFO
# Provides: scriptname
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
More infos there : https://wiki.debian.org/LSBInitScripts
The script at this page may interest you : http://dev.deluge-torrent.org/wiki/UserGuide/Service/DebianUbuntuInitd

Resources