OutsourcedGuru / pizero-webcam-tutorial

A step-by-step tutorial for setting up a Raspberry Pi Zero W computer as a webcam
MIT License
26 stars 1 forks source link

Create a service instead of using rc.local #2

Closed StevenCregan closed 4 years ago

StevenCregan commented 4 years ago

I prefer making an easily restartable service to help with tuning resolution/framerate options My config is similar to this:

Filename: mjpg_streamer.service Location: /lib/systemd/system/

Contents:

[Unit]
Description=MJPG Streaming Service
After=network.target

[Service]
Type=simple
WorkingDirectory=/home/pi
ExecStart=/home/pi/mjpg-streamer/mjpg-streamer-experimental/mjpg_streamer -o "/usr/local/lib/mjpg-streamer/output_http.so -w /home/pi/mjpg-streamer/mjpg-streamer-experimental/www" -i "/usr/local/lib/mjpg-streamer/input_raspicam.so -x 1280 -y 720 -fps 41 -quality 40 -ex sports -ifx none -mm average"
ExecStop=/bin/kill -SIGINT $MAINPID
StandardOutput=journal
StandardError=inherit
SyslogIdentifier="mjpg_streamer"
Restart=always
RestartSec=1
User=root

[Install]
WantedBy=multi-user.target

Link by running: sudo ln -s /lib/systemd/system/mjpg_streamer.service /etc/systemd/system/mjpg_streamer.service Refresh systemd: sudo systemctl daemon-reload Enable service: sudo systemctl enable mjpg_streamer Start service for the first time: sudo systemctl start mjpg_streamer

OutsourcedGuru commented 4 years ago

I think I'm more familiar with init.d, to be honest with something like a sudo service webcamd start sort of interface. It would likely be more in tune with the original from OctoPi's image as seen here.

StevenCregan commented 4 years ago

Yeah, the webcamd service is a lot more robust, and certainly better thought out; This is just a lightweight suggestion I whipped up in the middle of the night šŸ˜… I've just been seeing more and more things on Debian systems moving towards systemd, so that's what I've been trying to familiarize myself with. Figured it'd be worth sharing, even if not necessary šŸ™‚

OutsourcedGuru commented 4 years ago

Thanks for the suggestion and it's good to know each one that's available. What I could do is close this issue and create a link to it in the README.

StevenCregan commented 4 years ago

Sounds good šŸ‘