Brad T wrote:
> Hello, I've been trying to get this to work as a service to startup when my raspberry pi boots, but so far I've had no luck.
>
> Any tips would be appreciated:
>
> I'm trying to run a bash script on startup as a systemd service, I'm doing this on a Raspberry Pi 4 with Raspbian Buster Lite.
>
> I'm able to execute the bash script if I run it manually ./hls.sh and I am able to also run the service if I do sudo service tv start but the tv.service does not appear to be able to execute the bash script hls.sh on start. I did give permissions chmod 777 for both the service and the bash file as well.
>
> Bash Script
> > #!/bin/bash
> > /usr/bin/ffmpeg -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 2 -y -nostdin \
> > -hide_banner -loglevel fatal \
> > -i
http://10.0.0.11:9981/stream/channelnumber/2 \
> > -vcodec copy -acodec copy -scodec copy -g 60 \
> > -fflags +genpts -user_agent HLS_delayer \
> > -metadata service_provider="TimeShift" \
> > -metadata service_name="TV 1" \
> > -f hls -hls_flags delete_segments \
> > -hls_time 60 \
> > -hls_list_size 480 \
> > -hls_wrap 481 \
> > -hls_segment_filename /home/pi/hls/1_%03d.ts /home/pi/hls/1_hls.m3u8
>
> Service
> > [Unit]
> > Description=Timeshift TV
> > After=tvheadend.service
> > PartOf=tvheadend.service
> > Restart=always
> >
> > [Service]
> > ExecStartPre=/bin/mkdir -p /home/pi/hls/
> > ExecStart=/home/pi/hls.sh 103 &
> > ExecStop=/bin/rm -rf /home/pi/hls
> >
> > [Install]
> > WantedBy=default.target
>
> What I get when I boot and do a systemctl status
> > ● tv.service - Timeshift TV
> > Loaded: loaded (/etc/systemd/system/tv.service; enabled; vendor preset: enabled)
> > Active: failed (Result: exit-code) since Mon 2020-05-18 05:36:40 BST; 45s ago
> > Process: 465 ExecStartPre=/bin/mkdir -p -m777 /home/pi/hls/ (code=exited, status=0/SUCCESS)
> > Process: 472 ExecStart=/home/pi/hls.sh 103 & (code=exited, status=1/FAILURE)
> > Main PID: 472 (code=exited, status=1/FAILURE)
> >
> > May 18 05:36:39 tv3 systemd[1]: Starting Timeshift TV...
> > May 18 05:36:39 tv3 systemd[1]: Started Timeshift TV.
> > May 18 05:36:40 tv3 systemd[1]: tv.service: Main process exited, code=exited, status=1/FAILURE
> > May 18 05:36:40 tv3 systemd[1]: tv.service: Failed with result 'exit-code'.
You've been made heavy change in script and due to this service script at part
ExecStart=/home/pi/hls.sh 103 &
couldn't be started - 103 is the number of channel wich we want to record but in script there is no $1 variable (as the first parameter of script)