techiefive
Posts: 1
Joined: Fri Mar 23, 2018 3:06 pm

Help with creating a service at boot

Fri Mar 23, 2018 3:15 pm

I'm trying to start up raspivid for an IP camera at boot and having no luck. I've created a service (code below) and am probably missing something obvious since I'm new to Raspian (and Linux in general).

Code for picamera.service:

Code: Select all

[Unit]
Description=picamera
After=network.target

[Service]
ExecStart="/opt/vc/bin/raspivid  -t -0 -w 640 -h 480 -awb auto -fps 30 -rot 270 -b 1200000 -o - |ffmpeg -loglevel quiet -i - -vcodec copy -an -f flv -metadata streamName=myStream tcp://0.0.0.0:6666&"
Restart=always

[Install]
WantedBy=default.target
Result from systemctl status picamera.service:

Code: Select all

● picamera.service - picamera
   Loaded: loaded (/etc/systemd/system/picamera.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2018-03-23 08:02:16 PDT; 25s ago
  Process: 3959 ExecStart=/opt/vc/bin/raspivid  -t -0 -w 640 -h 480 -awb auto -fps 30 -rot 270 -b 1200000 -o - |ffmpeg -loglevel quiet -i - -vcodec copy -an -f flv -metadata streamName=myStream tcp://0.0.0.0:6666& (code=exited
 Main PID: 3959 (code=exited, status=203/EXEC)

Mar 23 08:02:16 raspberrypi systemd[1]: picamera.service: Failed with result 'exit-code'.
Mar 23 08:02:16 raspberrypi systemd[1]: picamera.service: Service hold-off time over, scheduling restart.
Mar 23 08:02:16 raspberrypi systemd[1]: Stopped picamera.
Mar 23 08:02:16 raspberrypi systemd[1]: picamera.service: Start request repeated too quickly.
Mar 23 08:02:16 raspberrypi systemd[1]: Failed to start picamera.
Mar 23 08:02:16 raspberrypi systemd[1]: picamera.service: Unit entered failed state.
Mar 23 08:02:16 raspberrypi systemd[1]: picamera.service: Failed with result 'exit-code'.
As I said, it's probably something easy that I'm simply not educated enough to spot immediately. It's also possible that raspivid can't be run as a service, I suppose; but that's why I'm here asking. Thanks in advance for any assistance.

klricks
Posts: 6609
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Help with creating a service at boot

Sat Mar 24, 2018 3:04 am

If you boot to desktop then it is easy to use autostart.

Code: Select all

/home/pi/.config/lxsession/LXDE-pi/autostart
If boot to CL then use lc.local
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

User avatar
jostle
Posts: 16
Joined: Tue Mar 06, 2018 6:26 am

Re: Help with creating a service at boot

Sat Mar 24, 2018 3:27 am

You probably need to specify the full path to 'ffmpeg'
To quote the 'service' man page
DESCRIPTION
service runs a System V init script, systemd unit, or upstart job in as predictable an environment as possible, removing most environment variables and with the current working directory set to /.
I think it removes the PATH environment variable, so you need to use '/usr/bin/ffmpeg' instead of just 'ffmpeg'
Have Fun ...

Return to “Troubleshooting”