October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
24/7 streaming

How to Create a systemd Service for a 24/7 YouTube Radio Stream

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

To keep a YouTube radio stream running from Linux, run your encoder in the foreground under a system-level systemd service, set a deliberate restart policy, and monitor the video YouTube actually receives. systemd can restart a failed process; it cannot create the broadcast, verify the stream key, or detect every stalled output. Test the encoder command and confirm the preview in YouTube Live Control Room before enabling the service at boot.

What you need before creating the service

  • A Linux host that stays powered on and connected. A desktop works only while it is running; a VPS can keep the process online when your home computer is off, but you must account for provider limits, sustained upload bandwidth, storage, and data-transfer costs.
  • An input that can supply the intended continuous audio and, if required, video. The example below loops an MP4 file; adapt the input and codecs to your actual media.
  • FFmpeg installed at a known absolute path, such as /usr/bin/ffmpeg. Confirm that your build supports the required input and RTMPS output.
  • YouTube live streaming enabled for the account. YouTube says first-time live streaming enablement may take up to 24 hours. YouTube’s encoder setup guide covers creating a stream in Live Control Room.
  • A stream URL and matching stream key from the stream’s settings. Treat the key as a credential: do not publish it in scripts, screenshots, repositories, or logs.

Set up and test the YouTube encoder command first

Get the correct ingest details

Create or schedule the stream in YouTube Live Control Room, then copy the URL and stream key from that stream’s settings. Prefer the RTMPS endpoint when supported. YouTube’s RTMPS instructions explain how to reveal that endpoint; the ordinary RTMP address may be shown by default. RTMPS is RTMP over TLS/SSL, and YouTube notes that port 443 may be relevant when troubleshooting connection issues. Read YouTube’s RTMPS guidance.

Prove the media and command work interactively

Before involving systemd, run the encoder in a terminal as the account that will own the service. Keep it in the foreground. Confirm that the selected file, loop behavior, codecs, container, output URL, and network path are appropriate, and inspect the incoming preview in Live Control Room. The following is only an illustrative command shape, not a universal or tested FFmpeg invocation:

/usr/bin/ffmpeg -re -stream_loop -1 -i /srv/yt-radio/radio.mp4 -c:v copy -c:a aac -f flv "$YOUTUBE_RTMPS_URL/$YOUTUBE_STREAM_KEY"

Here -re reads the file at its natural rate, -stream_loop -1 repeats the input indefinitely, -i selects the input, and the codec and FLV muxer options describe one possible output setup. Copying video while encoding audio as AAC is suitable only if the source video and YouTube ingest requirements are compatible. A radio stream may instead use a still-image or other video source; choose an input and encode settings that match it. Do not assume this example’s options suit every file or FFmpeg build.

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.

Keep the stream key out of command history and process listings where possible. A destination URL containing the key can be exposed by command-line inspection or diagnostic logs. Prefer a protected configuration mechanism or carefully controlled wrapper, and ensure errors do not print the full destination URL.

Create a protected configuration and systemd unit

Use a dedicated, unprivileged account

Create a service account such as ytstream and give it only the access it needs to read the media and run the encoder. Choose a stable working directory, for example /srv/yt-radio. Keep secrets in a file with restrictive ownership and permissions, or use a systemd credential facility only after confirming that the installed systemd version supports the method you choose.

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.

Build the unit around the real command

Save a unit at /etc/systemd/system/yt-radio.service. This teaching skeleton illustrates the service structure, not a paste-ready configuration:

[Unit]
Description=YouTube radio stream
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=ytstream
Group=ytstream
WorkingDirectory=/srv/yt-radio
EnvironmentFile=/etc/yt-radio/stream.env
ExecStart=/usr/bin/ffmpeg -re -stream_loop -1 -i /srv/yt-radio/radio.mp4 -c:v copy -c:a aac -f flv $YOUTUBE_OUTPUT
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

Type=simple makes systemd track the foreground process. User and Group avoid running the encoder as root. WorkingDirectory gives the process a predictable location. Wants and After request network-online startup ordering, but do not guarantee that the remote endpoint is reachable. EnvironmentFile points to configuration, while Restart and RestartSec set the recovery policy and delay.

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.

Do not assume systemd interprets ExecStart= like a shell: it does not perform arbitrary shell expansion or concatenation. In particular, a construction such as ${YOUTUBE_RTMPS_URL}/${YOUTUBE_STREAM_KEY} is not a general way to combine environment values there. For a simple setup, store the complete output destination in one protected environment value and pass it as a single argument where the installed systemd version supports that expansion. For stronger control over secret handling, use a carefully quoted wrapper script or a compatible systemd credential mechanism, and verify the exact behavior on the target distribution. A wrapper should not log the destination URL. Check unit syntax with systemd-analyze verify /etc/systemd/system/yt-radio.service before starting it.

Choose restart behavior intentionally

Restart=on-failure restarts after an unexpected nonzero exit, signal, or configured timeout condition. Restart=always also restarts after a clean exit, which can be useful if the encoder is expected never to finish. A deliberate systemctl stop does not trigger a restart. A restart policy responds to process termination; it does not prove that audio and video are flowing correctly.

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

Load, start, and verify the service

  1. After saving the unit and protected configuration, reload systemd’s unit definitions: sudo systemctl daemon-reload.
  2. Enable the unit at boot and start it now: sudo systemctl enable --now yt-radio.service.
  3. Check its process state and recent errors: sudo systemctl status yt-radio.service.
  4. Follow the service log while it runs: sudo journalctl -u yt-radio.service -f. Review output for connection failures, missing files, invalid options, and permission errors; redact any secret if a destination is exposed.
  5. Open Live Control Room and wait for YouTube’s preview. Click Go live where required. A running local process is not proof that YouTube is receiving a usable broadcast.
  6. Test recovery before relying on the setup: deliberately stop or interrupt the encoder in a controlled test, observe whether it returns under the selected policy, and verify that the received stream resumes. Reboot-test the host if you need confidence that the service starts at boot.

Monitor the received stream, not just the process

systemd may show the unit as active while the output is stalled, silent, or missing video. Check the Live Control Room preview and use monitoring or out-of-band alerts that reflect the received stream, not only the service state. A continuous service also does not mean a single YouTube archive lasts indefinitely: YouTube says streams under 12 hours are automatically archived, so do not assume the same automatic archive behavior for longer continuous runs. See YouTube’s live-stream guidance.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common failures

The service is active, but YouTube shows no stream

  • Check journalctl -u yt-radio.service -f for encoder and connection errors.
  • Verify the stream key and ingest URL belong to the same stream, the input file exists and is readable by the service account, and the selected output options suit the media.
  • Check the Live Control Room preview and confirm outbound network access to the ingest endpoint. The local systemd state alone cannot establish that the broadcast is healthy.

RTMPS reports an SSL error or connection timeout

  • Confirm that the destination uses the RTMPS endpoint, not an RTMP URL, and that the installed FFmpeg build supports RTMPS.
  • For an SSL or connection problem, follow YouTube’s guidance on the endpoint and try port 443 where relevant. YouTube RTMPS troubleshooting.

The unit repeatedly restarts

Inspect the first encoder error in the journal before increasing RestartSec. Check the input path, permissions, command options, configuration file, and endpoint. A longer delay can reduce rapid retries, but it cannot fix a bad key or invalid command.

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.

The service fails to start or cannot read its secret

Check the unit with systemd-analyze verify, confirm the environment file’s path and permissions, and verify that the service account can read required media and configuration. Environment expansion and credential directives depend on systemd version and configuration; do not copy a secret-handling directive without checking compatibility.

The expected archive is missing

YouTube’s stated automatic archive behavior covers streams under 12 hours. For a longer continuous transmission, do not rely on an archive being created automatically.

DIY service or cloud-managed looping?

A self-managed systemd service gives you direct control over the Linux host, encoder, media, and recovery behavior. It also leaves you responsible for machine availability, updates, bandwidth, secret protection, stream monitoring, and fixing failures. A VPS is one way to keep a Linux process running while your desktop is off, but compare providers on sustained upstream capacity, storage, data-transfer charges, and operating limits rather than assuming any host is suitable.

Or let it run in the cloud

StreamNeo is an alternative for uploaded-video YouTube streams: upload a recording or build a playlist, add your YouTube stream key once, and go live. Its cloud service loops uploaded videos, so no computer or home connection has to stay on. Each slot streams the upload as made, up to 4K 60fps, at one flat price per slot; it automatically recovers if YouTube drops the stream. The first day is free with no card. Monthly pricing is $9.99 per month. It is for uploaded videos, not a live camera feed, and streams to YouTube only. Visit StreamNeo for details, or start the free first day.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

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.

Read next

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

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.