Can Raspberry pi run 2 commands on startup with a delay in between them - raspberry-pi

I want to fire 2 commands on startup on my raspberry pi
The first one runs a node server starting script.
The second one should open chromium browser with a specific page.
The point is that I want to wait a couple of seconds to launch chromium so I'm sure that the webpage will be connected to the node server.
I tried so many things but I can't seem to fix a the delay.
Any suggestions?
This is what I have now in an LXDE session:
#lxpanel --profile LXDE-pi
#pcmanfm --desktop --profile LXDE-pi
#xscreensaver -no-splash
// This starts the node server
#/home/pi/autostart.sh
// This starts the browser
#/home/pi/async.sh
The async bash runs this:
#!/usr/bin/env bash
sleep 5
chromium-browser -kiosk http://localhost:3000

You start the node server and loop until the site comes online before launching the web-browser.
Replace "sleep 5" in async.sh by the following:
until $(curl --output /dev/null --silent --head --fail http://localhost:3000); do
printf '.'
sleep 1
done
source : How to create a loop in bash that is waiting for a webserver to respond?

Related

Polybar launch.sh not running when Awesome wm is restarted

I've been setting up my Linux desktop, running Arch on Kernel 5.18.14, and have run into some issues when configuring Polybar to start when Awesome wm starts
This is my polybar launch script (/home/user/.config/polybar/launch.sh):
#!/bin/bash
killall -q polybar
while pgrep -x polybar >/dev/null; do sleep 1; done
for m in $(polybar --list-monitors | cut -d":" -f1); do
MONITOR=$m polybar duat &
done
My polybar bar is named duat in the config.ini
This is where I execute the script in my Awesome wm rc.lua
awful.spawn.with_shell("/home/user/.config/polybar/launch.sh")
awful.spawn.with_shell("feh --bg-fill ~/.config/awesome/backgrounds/background.png")
awful.spawn.with_shell("wal -R")
Any help is greatly appreciated. It should be noted that once I run the script manually, awesome wm seems to have no problem running the script when reloaded, but if polybar is completely inactive, it refuses to start.

Start shrew vpn client (iked & ikec) on start-up of OSMC on Raspberry 2

I would like to connect to a VPN on start-up of OSMC.
Environment:
installed OSMC on Raspberry 2
downloaded, compiled and installed shrew soft vpn on the device
As user 'osmc' with ssh
> sudo iked starts the daemon successfully
> ikec -r "test.vpn" -a starts the client, loads the config and connects successfully
rc.local:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
sudo iked >> /home/osmc/iked.log 2>> /home/osmc/iked.error.log &
ikec -a -r "test.vpn" >> /home/osmc/ikec.log 2>> /home/osmc/ikec.error.log &
exit 0
after start of raspberry iked is as process visible with ps -e
but ikec is not running
osmc#osmc:~$ /etc/rc.local starts the script and connects to vpn successfully
Problem:
Why does the script not working correctly on start-up?
Thank you for your help!
I was also looking to do the same thing as you and ran into the same problem. I'm no linux expert, but I did figure out a workaround.
I created a script called ikec_after_reboot.sh and it looks like this...
$ cat ikec_after_reboot.sh
#!/bin/bash
echo "Starting ikec"
ikec -r test.vpn -a
I then installed cron.
sudo apt-get update
sudo apt-get install cron
Edit the cron job as root and run the ikec script 60 seconds after reboot.
sudo crontab -e
SHELL=/bin/bash
#reboot sleep 60 && /home/osmc/ikec_after_reboot.sh & >> /home/osmc/ikec.log 2>&1
Now edit your /etc/rc.local file and add the following.
sudo iked >> //home/osmc/iked.log 2>> /home/osmc/iked.error.log &
exit 0
Hopefully, this is helpful to you.

Unable to run "gearman" command line tool with gearman 1.1.6

I am trying to run the example on "http://gearman.org/getting_started" on Ubuntu in VirtualBox environment.
At first I tried to download an old version 0.16 by using apt-get install gearman-job-server, apt-get install gearman-tools and everything worked well. The server ran in the background, I was able to create 2 workers and verify that I can call them by creating a client.
I decided to download and compile the latest version, 1.1.6. Now, I am trying to do the same thing with the new version and I am having errors.
I run the server as admin:
sudo gearmand
The statement
gearadmin --getpid
seems to work - it returns me the process ID of the server. Thus, the server is running, and this answer is not relevant.
Now, I am adding a worker:
gearman -w -f wc -- wc -l
It seems to run.
Nevertheless,
gearadmin --workers
results in something that probably represents and empty list :
33 127.0.0.1 - :
.
(In version 0.16, I was able to see 2 lines, the second showing the registered function name.)
Attempting to run the client
gearman -f wc < /etc/passwd
results in
gearman: gearman_client_run_tasks : flush(GEARMAN_COULD_NOT_CONNECT) localhost:0 -> libgearman/connection.cc:671"
This might be the very same problem described in here - the port not specified, but I have no idea how to do it through the command line tool.
Any idea?
Ok, It looks like the answer in here was the key to success. Probably, the "getting started" section was not updated for a while. Indeed, one must specify a port explicitly for gearmand and gearman .
Server:
sudo gearmand -p 5000
Worker:
gearman -p 5000 -w -f wc -- wc -l
Client:
gearman -p 5000 -f wc < /etc/passwd

VLC won't start automatically at Ubuntu boot

I am trying to configure VLC to start streaming two streams automatically on boot with Upstart.
Here is my upstart script:
description "VLC streams"
start on (local-filesystems and net-device-up IFACE!=lo)
stop on runlevel [016]
exec /home/streamer/stream.sh
and stream.sh:
#!/bin/bash
cvlc -v "/home/administrator/Videos/Kastiel/kastiel.xspf" --sout '#std{access=udp{ttl=2},mux=ts,dst=239.220.220.31:9200}' --sout-keep --loop &
cvlc -v "/home/administrator/Videos/Rozpravky/rozpravky.xspf" --sout '#std{access=udp{ttl=2},mux=ts,dst=239.220.220.2:9200}' --sout-keep --random &
exit 0
However, after the computer boots, there is no stream and VLC process is not running. When I run stream.sh manually, it works with no problem.
Does anybody know what mistake am I doing?
I am using Ubuntu 12.10 and VLC 2.0.5.
Thank you in advance for any help.
Milan
Vlc doesn't support to be run as root due to security reasons.
You should use sudo -u user in script to change the user.
try as :
sudo -u username cvlc -v "/home/administrator/Videos/Kastiel/kastiel.xspf" --sout '#std{access=udp{ttl=2},mux=ts,dst=239.220.220.31:9200}' --sout-keep --loop &

Why is sleep needed after fabric call to pg_ctl restart

I'm using Fabric to initialize a postgres server. I have to add a "sleep 1" at the end of the command or the postgres server processes die without explanation or an entry in the log:
sudo('%(pgbin)s/pg_ctl -D %(pgdata)s -l /tmp/pg.log restart && sleep 1' % env, user='postgres')
That is, I see this output on the terminal:
[dbserv] Executing task 'setup_postgres'
[dbserv] run: /bin/bash -l -c "sudo -u postgres /usr/lib/postgresql/9.1/bin/pg_ctl -D /data/pg -l /tmp/pg.log restart && sleep 1"
[dbserv] out: waiting for server to shut down.... done
[dbserv] out: server stopped
[dbserv] out: server starting
Without the && sleep 1, there's nothing in /tmp/pg.log (though the file is created), and no postgres processes are running. With the sleep, everything works fine.
(And if I execute the same command directly on target machine's command line, it works fine without the sleep.)
Since it's working, it doesn't really matter, but I'm asking anyway: Does someone know what the sleep is allowing to happen and why?
You might try also using the pty option set it to false and see if it's related to how fabric handles pseudo-ttys.