DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
DocumentaryTube
Admit one · Blog

How to Configure a systemd Service to Restart an Always-On YouTube Stream

A practical systemd unit for restarting FFmpeg, with restart-policy choices, boot commands, YouTube stream checks and troubleshooting.
Opened Runtime5 min Written byDocumentaryTube Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run FFmpeg in the foreground as a systemd service, then choose a restart policy that matches what a clean exit means for your stream. Use Restart=on-failure if a successful exit should leave the stream stopped, or Restart=always if systemd should launch FFmpeg again even after it exits cleanly. A restart policy can relaunch an exited process; it cannot by itself guarantee a healthy YouTube stream.

Configure FFmpeg as a systemd service

This illustrative unit assumes a Linux host with systemd and FFmpeg installed, a local video file, and a stream URL and key obtained from YouTube Live Control Room. Replace the user, paths, input and destination for your setup. It has not been tested against a specific distribution, systemd release, FFmpeg build or YouTube account.

# /etc/systemd/system/youtube-stream.service
[Unit]
Description=YouTube live stream encoder
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=streamer
WorkingDirectory=/srv/stream
ExecStart=/usr/bin/ffmpeg -re -stream_loop -1 -i /srv/stream/loop.mp4 -c:v libx264 -preset veryfast -b:v 4500k -maxrate 4500k -bufsize 9000k -c:a aac -b:a 128k -f flv rtmps://YOUR_INGEST_URL/YOUR_STREAM_KEY
Restart=on-failure
RestartSec=10s

[Install]
WantedBy=multi-user.target

Type=simple makes the foreground FFmpeg process the service’s main process, so systemd can supervise its lifetime. Do not background the encoder with & or wrap it in a script that exits while FFmpeg continues; otherwise systemd may supervise the wrong process.

The FFmpeg command is a shape example, not a recommended universal encoding profile. It loops one local file, uses illustrative encoding values, and sends output to an RTMPS destination. The actual endpoint and key must come from your Live Control Room, and the values must suit your media, installed encoder and available upload bandwidth. YouTube’s H.264 guidance lists 5 Mbps for 1080p at 30 fps and 14 Mbps for 4K at 30 fps; these are platform recommendations, not evidence that your connection can sustain those rates. See StreamNeo only for its separate cloud option described below; for YouTube encoder settings, consult YouTube’s current guidance in Live Control Room.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Load and start the unit

  1. Save the file as /etc/systemd/system/youtube-stream.service. Protect the unit and any configuration holding the stream key from access by other users.

  2. Reload systemd’s unit definitions and enable the service at boot while starting it now:

    Rank #2
    Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
    • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
    • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
    • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
    • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
    • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
    sudo systemctl daemon-reload
    sudo systemctl enable --now youtube-stream.service
  3. Check the service state and follow its logs:

    sudo systemctl status youtube-stream.service
    sudo journalctl -u youtube-stream.service -f
  4. Separately inspect the preview and stream health in YouTube Live Control Room. An active systemd unit only shows that the service process is running; it does not prove that YouTube is receiving a healthy feed.

After editing the unit, run daemon-reload before restarting it. enable configures startup with the unit’s target, while --now also starts it immediately. Command behavior and available systemd directives can vary by distribution and release; consult the local systemctl, systemd.service and systemd.unit manuals.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Choose the restart policy deliberately

Setting What it does Use it when
Restart=on-failure Restarts after a failure, but not after a clean exit. A clean FFmpeg exit should leave the stream stopped.
Restart=always Restarts after clean exits as well as failures, signals and timeouts. Any FFmpeg exit should start another encoder process.

A manager-requested stop, such as systemctl stop youtube-stream.service, is intentional and is not automatically undone by these restart policies. Set a delay with RestartSec= to avoid immediate retry loops. The example’s 10s is a chosen delay, not a universal recommendation or guarantee; a different destination or recovery pattern may call for a different interval.

Account for start-rate limiting

Systemd can limit repeated starts. If FFmpeg exits quickly over and over, the service may stop being restarted until the rate-limit window allows another attempt or an operator intervenes. The systemd project documents manager defaults of 10 seconds and 5 attempts, but these settings are configurable, and per-unit settings or the installed version may differ. Check the host’s local systemd configuration and manuals rather than assuming those defaults apply.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2Ă— USB C male to USB A female adapters and 2Ă— USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check the parts systemd cannot repair

  • Stream key and endpoint: Use the current URL and key displayed in YouTube Live Control Room. YouTube treats stream keys as credentials; keep them private, and reset a key if it is exposed, then update the service configuration. Prefer the RTMPS endpoint when available.

  • Network capacity: YouTube recommends 20% upload headroom. Account for the stream’s bitrate and any simultaneous backup stream, where applicable; a network disruption can still break delivery even if FFmpeg later restarts.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    Best Value
    Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
    • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
    • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
    • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
    • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
    • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
  • Input and encoder: Confirm that the file exists and is readable by the service user, that the installed FFmpeg supports the selected codecs, and that the chosen resolution, frame rate and bitrate match the source and connection.

  • Rights and channel policies: Use media you have permission to stream and check YouTube’s current copyright and reused-content rules for your channel and material. Restarting an encoder does not change whether content is permitted or eligible under YouTube’s policies.

  • Process health: systemd reacts to process exits and service results; it does not necessarily detect an FFmpeg process that remains alive but is stuck or no longer sending usable video. Detecting that condition requires an appropriate health check or monitoring beyond a basic restart policy.

Troubleshoot common restart failures

Symptom Likely cause What to check or do
The service fails immediately and does not stream. Invalid unit syntax, missing executable or input, inaccessible file, or invalid destination/key. Read systemctl status and journalctl -u youtube-stream.service; verify the FFmpeg path, service user’s file permissions, input path and current YouTube endpoint/key.
FFmpeg exits, but systemd does not restart it. A clean exit with Restart=on-failure, an intentional stop, or start-rate limiting. Choose Restart=always only if clean exits should relaunch; check whether an operator or dependency stopped the service and review the journal for rate-limit messages.
The unit is active, but YouTube shows no healthy stream. The process exists but cannot deliver valid media because of a bad key, endpoint, input, encoder setting or network path. Use the journal for FFmpeg errors and verify the preview and health in Live Control Room. Do not treat systemctl is-active as proof of viewer playback.
It starts at boot but not reliably after a network outage. network-online.target ordering is not a guarantee that every remote route or service is reachable, and systemd cannot fix a continuing network failure. Inspect boot and service logs, confirm the host’s network-online mechanism is configured, and ensure retries are not exhausting the start limit while connectivity is down.
The service never exits despite a frozen or stale stream. The encoder process may remain alive without delivering a usable feed. Use a separate health-monitoring approach capable of detecting stale output; a restart policy alone has no failure signal to act on.

Or let it run in the cloud

If maintaining an always-on host, its network and FFmpeg service is more than you want to manage, StreamNeo is a YouTube-only cloud service for looping uploaded videos. Upload a recording or build a playlist, add your YouTube stream key, and go live. Nothing has to stay on at home; uploads stream as made, up to 4K 60fps, at one price per slot, with automatic recovery if YouTube drops the stream. The first day is free with no card. Monthly is $9.99 per month.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start your free StreamNeo day.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Screening Room

  1. How to Migrate a 24/7 YouTube Stream to a New VPSAdmit one · BlogHow to Migrate a 24/7 YouTube Stream to a New VPSOpened04 OCT 2026Runtime6 min
  2. How to Run a YouTube Playlist on a Headless Linux Server—and Broadcast It LiveAdmit one · BlogHow to Run a YouTube Playlist on a Headless Linux Server-and Broadcast It LiveOpened04 OCT 2026Runtime6 min
  3. How to Make a 24/7 Indian Music YouTube Stream Restart After a Server RebootAdmit one · BlogHow to Make a 24/7 Indian Music YouTube Stream Restart After a Server RebootOpened04 OCT 2026Runtime6 min
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.