If you’ve come across older Redis installation guides, you’ll probably notice they use SysV init (init.d) scripts located in /etc/init.d. While that worked well on older versions of Ubuntu and Debian, modern Linux distributions have adopted systemd as the standard service manager.
In this guide, we’ll replace the legacy init.d approach with a native systemd service, which provides better reliability, automatic restarts, improved logging, and easier service management.
Why Use systemd?
systemd has been the default init system on Ubuntu for many years and offers several advantages over traditional init scripts:
- Faster and more reliable service startup
- Automatic service restart on failure
- Integrated logging through
journalctl - Better dependency management
- Improved security features
- Simplified service management with
systemctl
For new Redis installations, using a native systemd service is the recommended approach.
Step 1: Create a systemd Service File
Create a new service file:
sudo nano /etc/systemd/system/redis.service
Paste the following configuration:
[Unit] Description=Redis In-Memory Data Store Documentation=https://redis.io/docs/ After=network.target [Service] Type=notify User=redis Group=redis ExecStart=/usr/local/bin/redis-server /etc/redis.conf --supervised systemd ExecStop=/usr/bin/redis-cli shutdown Restart=always RestartSec=5 RuntimeDirectory=redis RuntimeDirectoryMode=0755 LimitNOFILE=65535 # Security hardening NoNewPrivileges=true PrivateTmp=true ProtectSystem=full ProtectHome=true ReadWritePaths=/var/lib/redis /var/log/redis [Install] WantedBy=multi-user.target
Note: If you installed Redis using Ubuntu’s package manager (
apt), the Redis binaries are typically located in/usr/bin/rather than/usr/local/bin/. Update theExecStartandExecStoppaths accordingly if necessary.
Step 2: Update Redis Configuration
Edit your Redis configuration file:
sudo nano /etc/redis.conf
Ensure the following settings are present:
supervised systemd daemonize no pidfile /run/redis/redis-server.pid
These settings allow systemd to manage the Redis process directly instead of Redis running as a background daemon.
Step 3: Reload systemd
After creating the service file, reload the systemd configuration:
sudo systemctl daemon-reload
Step 4: Enable Redis at Boot
Enable the service so it starts automatically whenever the server boots:
sudo systemctl enable redis
Step 5: Start the Service
Start Redis:
sudo systemctl start redis
Verify it’s running:
sudo systemctl status redis
You should see an output indicating that the service is active (running).
Managing Redis
Start Redis
sudo systemctl start redis
Stop Redis
sudo systemctl stop redis
Restart Redis
sudo systemctl restart redis
Reload Configuration
sudo systemctl reload redis
Check Service Status
sudo systemctl status redis
Viewing Redis Logs
One of the biggest improvements with systemd is centralized logging.
To view recent Redis logs:
journalctl -u redis
To watch logs in real time:
journalctl -u redis -f
This makes troubleshooting significantly easier than searching through multiple log files.
Testing Redis
Verify that Redis is responding correctly:
redis-cli ping
Expected output:
PONG
Troubleshooting
Service fails to start
Check the service status:
sudo systemctl status redis
Then review the logs:
journalctl -xeu redis
“redis” user does not exist
If you built Redis from source, create a dedicated service account:
sudo adduser --system --group --no-create-home redis
Binary not found
Verify the Redis binary location:
which redis-server which redis-cli
Update the ExecStart and ExecStop paths in the service file if they differ from the defaults.
Conclusion
The old /etc/init.d/redis-server startup script served its purpose for earlier Ubuntu releases, but it has been superseded by systemd on modern Linux distributions.
Using a native systemd service gives you automatic startup, better logging, improved process management, automatic restarts after failures, and enhanced security. Whether you’re deploying Redis on Ubuntu 20.04, 22.04, 24.04, or newer, this is the recommended method for running Redis in production.
If you’re following an older Redis installation tutorial that references /etc/init.d, you can safely replace it with the systemd service described above for a cleaner and more reliable setup.
