TheWaterbug
Posts: 67
Joined: Fri Feb 05, 2016 12:35 am
Location: Los Angeles, CA, USA, Earth

Startup script fails with (code=exited, status=203/EXEC)

Tue Jan 23, 2018 6:41 am

Top Edit^2: Please mind. It's failing again. It worked once, on a reboot, but on a second reboot I got the original failure again.

Top Edit: Never mind. I fixed this by putting #!/bin/bash at the top of my script. :roll:

/////////////////
I want to run a script at startup, so that ffmpeg pulls video from my BeeCam and pushes it to my YouTube streaming channel.

Per this guide I did:

Code: Select all

 sudo nano /etc/init.d/StreamToYouTube.sh
 	<pasted in known, working script>
 sudo chmod 755 /etc/init.d/StreamToYouTube.sh
 sudo update-rc.d StreamToYouTube.sh defaults
 
That last command resulted in:

Code: Select all

insserv: warning: script 'K01StreamToYouTube.sh' missing LSB tags and overrides
insserv: warning: script 'StreamToYouTube.sh' missing LSB tags and overrides
but I'm not sure what that means.

When I boot I get an error in the message stream:

Code: Select all

[FAILED] Failed to start (null)
see 'systemctl status StreamToYouTube.service' for details
So I ran systemctl and it says:

Code: Select all

raspberrypi:~ $ systemctl status StreamToYouTube.service
● StreamToYouTube.service - (null)
   Loaded: loaded (/etc/init.d/StreamToYouTube.sh)
   Active: failed (Result: exit-code) since Wed 1969-12-31 16:00:18 PST; 48 years 0 months ago
  Process: 568 ExecStart=/etc/init.d/StreamToYouTube.sh start (code=exited, status=203/EXEC)
If I cd /etc/init.d and type ./StreamToYouTube.sh, it works, and my stream goes live. So the script is correct and executable, but I can't figure out how to get it to run automatically at boot.

Thanks!

User avatar
RaTTuS
Posts: 9707
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Startup script fails with (code=exited, status=203/EXEC)

Tue Jan 23, 2018 8:12 am

that is well out of date,
you need to use the systemd style startuo
i.e. [from memory so not guaranteed to work]

sudo nano /lib/systemd/system/StreamToYouTube.service

Code: Select all

[Unit]
Description=Streamer
After=network-online.target
Requires=network-online.target

[Service]
ExecStart=/full/path/to/script
Restart=always

[Install]
WantedBy=multi-user.target

then enable it like

Code: Select all

sudo systemctl enable StreamToYouTube 
then start it

Code: Select all

sudo systemctl start StreamToYouTube 
and check

Code: Select all

sudo systemctl status StreamToYouTube 

[edited for sanity and a few additions in the systemd.service stuff
Last edited by RaTTuS on Wed Jan 24, 2018 8:22 am, edited 2 times in total.
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

User avatar
allfox
Posts: 403
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Startup script fails with (code=exited, status=203/EXEC)

Tue Jan 23, 2018 9:09 am

Not sure if this is the problem, but it worth a note.

Did your script check if the network connection is working before it access YouTube?

According to https://www.freedesktop.org/wiki/Softwa ... orkTarget/
Normally, such a script could be scheduled with a systemd service file to make sure network is ready before it goes:

Code: Select all

[Unit]
Description=abcdef
After=network-online.target
Requires=network-online.target

[Service]
ExecStart=/bin/abcdef
SyslogIdentifier=abcdef

[Install]
WantedBy=multi-user.target

However, Raspbian is not Debian. This part does not work as standard, sometimes it fails. I'm not sure if it is because Raspbian is switched to dhcpcd. You would need check the network connection manually in the script.

I just delay everything 60 seconds on boot.

Try this method:
Add this line to /etc/crontab: @reboot pi /bin/sleep 60;/full/path/to/StreamToYouTube.sh




And another common pitfall for boot script is the $PATH variable. It would be different on booting environment. So,in the script, use full path, not relative path.

TheWaterbug
Posts: 67
Joined: Fri Feb 05, 2016 12:35 am
Location: Los Angeles, CA, USA, Earth

Re: Startup script fails with (code=exited, status=203/EXEC)

Tue Jan 23, 2018 8:33 pm

Thanks for all the suggestions!

When I sudo reboot the Pi the script runs successfully about half the time, so it's entirely possible that it's trying to start before the network is fully up.

But what I don't understand is why the loop doesn't try again. Here's the full contents of StreamToYouTube.sh:

Code: Select all

#!/bin/bash
cd /usr/local/bin/
while true
do
./ffmpeg -re -thread_queue_size 512 -rtsp_transport tcp -i "rtsp://user:password@192.168.1.11:554" -i SomeMusic.mp3 -vcodec copy -acodec copy -t 01:00:00 -f flv "rtmp://a.rtmp.youtube.com/live2/my-youtube-streaming-key"
sleep 10s
done
Based on a previous user's experience, it's not uncommon for things to crap out occasionally, so this is supposed to restart it every hour. And sometimes it does. If I ssh in and kill ffmpeg, it starts up again after 10 seconds. But if I leave it running all the time, sometimes ffmpeg will just die and not restart itself. I don't know why.

I may also be having SD card/filesystem issues, as suggested in my other thread. That 4 GB card is the original included with my first Pi2 kit, about 2 years ago. I have a new SD card on order from amazon.

User avatar
RaTTuS
Posts: 9707
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Startup script fails with (code=exited, status=203/EXEC)

Wed Jan 24, 2018 8:23 am

having a
Restart=always
in teh .service file will help if it bails out.

[i've edited my previous post to add a couple of useful stuff]
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

TheWaterbug
Posts: 67
Joined: Fri Feb 05, 2016 12:35 am
Location: Los Angeles, CA, USA, Earth

Re: Startup script fails with (code=exited, status=203/EXEC)

Thu Jan 25, 2018 7:24 am

RaTTuS wrote:
Tue Jan 23, 2018 8:12 am
that is well out of date,
you need to use the systemd style startuo
i.e. [from memory so not guaranteed to work]
<snip>
Thanks!

I think the root of my problem (and my previous problem) was a flakey SD card. Every time I rebooted the Pi, fsck ended up fixing a bunch of problems. Then, finally, things stopped being fixable, and some files disappeared :roll:

But by then, my new SD card had arrived, so I put a new OS on it and compiled ffmpeg.

I created the service as you suggested, and it's working! I like the ability to send start/stop/status and control it that way.

I've rebooted it a few times, and it's always come up successfully.

Thanks!

Now I need to figure out how to crop the video . . .

Return to “General discussion”

Who is online

Users browsing this forum: dshaw619, nihilisticG and 42 guests