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
Related
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!
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
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
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 &
I have made a bash init script in file at /etc/init.d/redis-snapshot:
#!/bin/bash
### BEGIN INIT INFO
# Provides: redis-snapshot
# Required-Start: $local_fs $syslog Stime redis-server
# Required-Stop: $local_fs $syslog $time redis-server
# Default-Start: 0 6
# Default-Stop: 2 3 4 5
# Short-Description: Backup redis data on system exit
# Description: redis-snapshot is a simple bash script to dump redis data
# to disk whenever the system shuts down or reboots.
### END INIT INFO
# path to script log file
ACTIVITYLOG='/home/noman/Desktop/redis-snapshot.log'
# create/touch log file
touch $ACTIVITYLOG
# invoke the save command on redis-cli
# this will dump all in-memory data to disk
OUTPUT="$(redis-cli SAVE)"
echo -e "$(date +'%Y-%m-%d %H:%M:%S %Z')\tSnapshoting Redis Data To Disk" >> $ACTIVITYLOG
echo -e "$(date +'%Y-%m-%d %H:%M:%S %Z')\tRedis says $OUTPUT" >> $ACTIVITYLOG
# end - nothing to do
I am using the following command to make it run on system reboot and shutdown:
sudo update-rc.d redis-snapshot start 99 0 6 .
It does not work for some reason and I am clueless what to try next.
Any bright ideas?
What is your underlying distro and release?
Try
chkconfig --add redis-snapshot
If you wish to specifically find out whether your script is run, you may try skipping output redirection to file, so you'd see it during boot-up or checking /var/log/boot.log after boot.
If the output is missing, then your script was not added to /etc/rc#.d.
An alternative method of running a script on startup (which I prefer) is via /etc/rc.local. E.g.:
bash /root/script.sh
exit 0