Skip to content
streamneo.
Troubleshooting13 min read

How to Use systemd to Restart an FFmpeg Sleep Sounds Stream on a Linux VPS

Supervise a validated FFmpeg sleep sounds stream with systemd, choose a restart delay, and diagnose failures from the journal.

sn.
StreamNeoPublished 4 October 2026
Worth sharing?

If your FFmpeg sleep sounds stream exits on a Linux VPS, systemd can start the process again according to a restart policy you choose. First verify the FFmpeg command by running it in the foreground; then put that same command in a service unit and use systemd’s status and journal tools to investigate failures.

This supervises the lifetime of the FFmpeg process. It does not guarantee that a destination accepts the stream, detect every stalled output, or make every network error recoverable. FFmpeg reconnect options are protocol- and failure-specific, so do not add them without checking what the command is reading or publishing.

Verify the FFmpeg command in the foreground

A service manager cannot repair a command that has never worked. Before creating a unit, run the intended FFmpeg command interactively and confirm that it reads the intended audio and produces the intended output. Keep this stage separate from supervision: if the command fails in a terminal, systemd will usually repeat the same failure rather than solve it.

Use the actual input, codecs, output destination, and stream credentials for your setup. The title does not establish whether the audio is a local file, an HTTP source, or another input, nor does it establish the publishing protocol. There is no safe universal command line for those differences. For a local track intended to repeat, choose and test a loop strategy appropriate to that input and output; for a live feed, determine what EOF and reconnect should mean before changing options.

When the foreground run fails, read the FFmpeg message and correct the underlying cause. Common checks include whether the file exists and is readable, whether the output URL is valid, whether the stream key is current, whether required codecs and protocols are available in the installed build, and whether the VPS can reach the destination. Do not paste a live stream key into a public example or a shell transcript you plan to share.

A successful foreground run is useful evidence, but it is not a full service test. The service may use a different account, working directory, permissions, or environment. Note the absolute path to FFmpeg and the exact argument list, then test under the intended service account where practical. The FFmpeg looping guide can help if your source is a file that needs to repeat; its loop advice still needs to match your particular input.

Also verify what “working” means for your channel. FFmpeg printing progress or remaining alive does not by itself prove that the destination platform is receiving and playing the stream. Confirm the receiving side separately. For a YouTube destination, the platform’s live streaming troubleshooting guidance is a primary place to check current status and stream issues.

Create a systemd service unit

A system unit describes how systemd should launch the main process. On many distributions, a unit file is stored under /etc/systemd/system/, but follow your VPS distribution’s administration guidance. The example below is a structural template, not a ready-to-run configuration. Replace paths, account, working directory, and FFmpeg arguments with values you have already tested.

[Unit]
Description=FFmpeg sleep sounds stream
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=stream
WorkingDirectory=/srv/sleep-stream
ExecStart=/usr/bin/ffmpeg <your validated FFmpeg arguments>
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target

Type=simple is suitable for a foreground process that stays attached rather than daemonising itself. ExecStart should name the executable and arguments. systemd does not automatically interpret shell syntax such as pipes, output redirection, or $VARIABLE expansion in that field. If the command genuinely needs shell logic, put that logic in a separately reviewed executable script and invoke the script explicitly; do not casually wrap an untested command in a shell.

Use absolute paths so startup does not depend on an interactive shell’s PATH. Set WorkingDirectory if the command relies on relative paths, though absolute paths for inputs are easier to reason about. Choose a dedicated account such as the illustrative stream user where practical, and grant it only the access the job needs: read access to audio files and access to any required state or log locations. The account, directories, and credential method depend on your distribution and deployment.

Treat stream credentials as secrets. Avoid embedding a live key in a unit file that is readable by other users or publishing it in a public support request. Use a protected credential mechanism appropriate to the host, and verify what the service account can read. Do not assume environment-variable syntax works directly in ExecStart; systemd unit syntax and environment-file handling have their own rules, so consult the local documentation before choosing a method.

The example includes Wants= and After= for network-online.target because a stream often needs network connectivity at startup. These express a dependency and ordering relationship; they do not ensure every distribution waits for usable connectivity. Whether a network-online wait service is enabled and meaningful is a local configuration question. A service may need its own sensible retry behaviour if the endpoint is not ready when it starts.

A VPS is not the only way to keep a channel running, but this article assumes you already have one. If you are still choosing a host, compare the practical trade-offs in the low-cost VPS guide for 24/7 internet radio. The systemd instructions here are about process supervision, not a recommendation for a particular provider.

Set a deliberate restart policy and delay

The restart policy tells systemd what kinds of process exits should prompt another start. Restart=on-failure is a reasonable starting point when an unexpected failure should be retried but a clean, intentional exit should not necessarily cause an endless loop. The official systemd service documentation describes restart behaviour and related service settings; check the version installed on your VPS because available behaviour and defaults can differ.

RestartSec=5s in the template is only an example delay, not a universally correct value. A short pause can help when a brief interruption has ended, but repeated fast failures can create noisy logs and repeated connection attempts without addressing the cause. A longer pause may be more appropriate if the destination or source needs time to recover. Choose a delay with the behaviour of your input and endpoint in mind, then observe what actually happens.

The policy acts when the process exits under the conditions covered by that setting. If FFmpeg is still running but has stopped delivering usable audio, an exit-based restart policy may do nothing. Conversely, if FFmpeg exits cleanly because the input ended, on-failure may not restart it; whether that is correct depends on whether the command should end or should keep playing. A finite file that should run continuously needs a tested loop design as well as supervision.

Restart behaviour and service start limits are related. systemd may stop trying after repeated starts within configured limits, depending on local manager policy and unit settings. Check the host’s effective configuration and version rather than assuming failures will be retried forever. If the unit reaches a start limit, first inspect the cause and correct it; simply loosening limits can turn a broken command into an endless cycle.

There are other restart semantics, but choose them only when their consequences match the job. Restarting after every exit can be appropriate for some intentionally persistent jobs, but it can also relaunch a command that was stopped on purpose. The systemd reference explains the policy choices; select one after deciding how a clean exit, a crash, and an administrative stop should behave for your channel.

Enable and start the service

After saving a system-level unit, ask systemd to reload its unit definitions, then enable and start the service. Replace the example unit name if you used another one:

sudo systemctl daemon-reload
sudo systemctl enable --now ffmpeg-sleep-stream.service
sudo systemctl status ffmpeg-sleep-stream.service

daemon-reload makes systemd read the changed unit file. enable configures the service to start during the relevant boot target; --now also starts it immediately. These actions do not prove that the stream is healthy, so check status and logs and then confirm reception at the destination. If you edit the unit later, reload the manager before restarting the service so it uses the updated definition.

Test both normal startup and the recovery behaviour you intend to rely on. Do not simulate failure by damaging a real channel during a period when listeners depend on it. Instead, use a controlled test source or a maintenance window, and observe whether the process exits, whether systemd makes a new attempt, and whether the next run resumes the intended content. Process restarts can begin a file at the beginning rather than resume meaningfully; decide whether that outcome is acceptable for sleep sounds.

Keep the distinction between enabling and starting clear. A service can be enabled for future boots but currently stopped, or started now without being enabled for reboot. Check both when diagnosing a VPS restart. If a service should not start automatically, omit enabling it and use the start operation only when intended.

Inspect status and journal logs

Use systemctl status for a quick view of the unit’s current state, recent messages, and process result. For more context from the current boot, query the journal:

sudo systemctl status ffmpeg-sleep-stream.service
sudo journalctl -u ffmpeg-sleep-stream.service -b
sudo journalctl -u ffmpeg-sleep-stream.service -f

The -b option limits the view to the current boot, while -f follows new entries as they arrive. journalctl displays entries stored by systemd’s journal service; see the journalctl manual for filters and options. If the journal appears empty, check how output is configured for the service, whether FFmpeg writes messages to standard output or error, and the distribution’s journal retention and configuration.

When the unit is failing, look for the first meaningful error rather than focusing only on the latest restart message. An invalid argument, unsupported codec, missing input, inaccessible file, bad credentials, rejected destination, or unavailable network can all lead to a process exit. The log may also show that FFmpeg is running normally even though listeners report silence; in that case, investigate the output path and receiving platform rather than assuming a process restart will help.

Compare the service execution context with the successful foreground test. Confirm the ExecStart path and argument boundaries, run access checks as the configured user, verify the working directory, and check that credentials are available through the method you selected. A command that succeeds as root can fail as a restricted service account because it cannot read the source file or required secret.

If you change an option or file path, change one relevant thing at a time and check the resulting journal. That makes it easier to tell whether the edit fixed the original failure or introduced another one. The FFmpeg VPS monitoring guide is useful for thinking about checks beyond whether the process exists; define what a healthy stream means for your own source and destination.

Add reconnect options only for the relevant protocol

FFmpeg-level reconnect and systemd restart address different events. A supported FFmpeg input may recover from a network interruption while FFmpeg remains alive. systemd can launch a new FFmpeg process after the old one exits. Neither mechanism guarantees that the publishing endpoint accepts the stream, that audio continues without a gap, or that a finite input repeats forever.

The FFmpeg Protocols Documentation lists options such as reconnect, reconnect_at_eof, and reconnect_on_network_error for relevant protocol handling. Its description of reconnect is to reconnect after disconnection before EOF is hit. That description is about the documented option in its protocol context, not a promise that the same setting repairs every type of source or output failure.

For example, if FFmpeg is reading media over HTTP, consult the current HTTP protocol section for which retry settings apply to that input and failure. Options relating to EOF, streamed inputs, particular HTTP error codes, and retry limits each have specific meanings. They should not be copied blindly onto a command publishing via RTMP or another output protocol. Check the installed FFmpeg build’s documentation and confirm where an option belongs in the argument list.

Start by identifying the actual failing leg: is FFmpeg reading a remote source, opening a local file, or publishing to a destination? Then identify whether FFmpeg exits, remains alive with a stalled input, or remains alive while the output is rejected. Choose protocol-specific recovery only if its documented behaviour covers that leg and failure. If it does not, the right fix may be a corrected URL, credentials, input loop, network diagnosis, or a separately designed health check.

A restart can have content consequences. If the command reads a local file and begins again after process exit, the programme may jump to the start; if the source is live, a new process may join at a different point. Decide whether that discontinuity is acceptable and test it. For a YouTube channel, also verify the stream in YouTube Studio or the relevant destination view: the service’s active state only tells you about the local process. The guide to YouTube live-stream rules and common issues can help separate platform-side messages from local FFmpeg errors.

If FFmpeg stays alive while output has stalled, a restart policy alone cannot identify that condition. A watchdog or health-check approach requires an explicit definition of health, such as a meaningful signal that confirms the expected media is reaching the intended destination. Do not add a watchdog that blindly kills a working process based on a superficial check. Test it separately and make sure it cannot turn a transient observability gap into repeated unnecessary restarts.

Know what supervision cannot fix

systemd is a process supervisor, not a guarantee of an uninterrupted listener experience. It can respond to process termination according to policy, but it cannot correct a revoked key, repair an invalid command, make an unreachable endpoint available, or infer that a quiet audio segment is a fault. Restarting can also repeatedly reproduce a configuration error until a start limit intervenes.

Make recovery observable. Keep logs accessible, check the unit after configuration changes, and arrange a practical way to notice when it is failed or when the destination is no longer receiving the intended stream. If the channel matters overnight, test the service under the same permissions and startup conditions it will use after a reboot. A planned test is more useful than assuming that enabled means healthy.

A hosted service can remove the need to keep your own computer on, but it changes which system you must monitor. StreamNeo may remove the particular burden of running and restarting this FFmpeg process on your VPS: it turns an uploaded video into a YouTube live stream, while your computer can be switched off. It is YouTube-only, so check that this fits your source and destination before deciding.

Before choosing a way to run the channel, weigh how much control you need over the command against the time you can spend maintaining the VPS.

Before committing, compare the operating options on the pricing page. When the file and channel are ready, start free — 24-hour trial, no card.

FAQ

Will systemd restart FFmpeg whenever it stops?

Only when the configured restart policy and local systemd rules call for another start. With Restart=on-failure, a clean exit is not necessarily treated the same as a failure. Check the unit state, restart policy, and start limits on your VPS rather than assuming every exit will loop indefinitely.

Should I use FFmpeg reconnect options and systemd together?

They can cover different failure cases: protocol-specific FFmpeg options may handle some interruptions while the process remains alive, while systemd can relaunch a process after it exits. First establish whether the command is reading or publishing over the protocol addressed by an option, then check the current FFmpeg documentation for that case. Do not treat reconnect flags as universal.

Why does the service work in a terminal but fail after reboot?

The service may run as a different user, start in another directory, or lack the environment and permissions available in your shell. Use absolute paths, check access as the service account, and read the unit’s journal after reboot. Also confirm that any network-online ordering actually waits for connectivity on your distribution.

Does an active systemd service prove my YouTube stream is live?

No. It shows that systemd considers the process active, not that YouTube is accepting and playing the output. Check FFmpeg’s logs and verify reception in the destination platform separately.

YOU’VE REACHED THE END

Keep the ideas coming.

More guides, useful tools and a little help for your next broadcast.

Back to the journal ↗
YOUR NEXT READ

A little more to explore.

More Troubleshooting guides ↗ · All topics ↗