{"id":5,"date":"2025-10-18T00:00:00","date_gmt":"2025-10-17T21:00:00","guid":{"rendered":"https:\/\/cojan.ro\/blog\/configure-server-run-unattended-for-years\/"},"modified":"2025-10-18T00:00:00","modified_gmt":"2025-10-17T21:00:00","slug":"configure-server-run-unattended-for-years","status":"publish","type":"post","link":"https:\/\/www.cojan.ro\/blog\/configure-server-run-unattended-for-years\/","title":{"rendered":"How to Configure a Server to Run Unattended for Years"},"content":{"rendered":"\n<h1>The Dream: A Server That Just Works<\/h1>\n<p>You know what the best server is? The one you don&#8217;t have to think about. The one that doesn&#8217;t wake you up at 2 AM. The one that just quietly does its job, year after year, while you focus on literally anything else.<\/p>\n<p>Sound impossible? It&#8217;s not. But it requires upfront work and \u2013 here&#8217;s the part people skip \u2013 accepting that &#8220;unattended&#8221; doesn&#8217;t mean &#8220;abandoned.&#8221; Even the most automated server needs occasional check-ins. The difference is you&#8217;re checking on your terms, not when things are on fire.<\/p>\n<p>I&#8217;ve been running servers for web hosting clients for years. Some of them I barely touch. They update themselves, clean themselves up, back themselves up, and alert me only when something genuinely needs attention. Want to know how that works? Let me show you what actually matters.<\/p>\n<h2>The Foundation: Pick Boring Technology<\/h2>\n<p>First rule of long-running servers: <strong>use stable, boring Linux distributions<\/strong>. This isn&#8217;t the place to experiment with the bleeding edge.<\/p>\n<p>Debian stable, Ubuntu LTS, Rocky Linux, AlmaLinux \u2013 these are your friends. They&#8217;re maintained for years, they get security updates reliably, and they don&#8217;t surprise you with breaking changes every six months.<\/p>\n<p>I run Ubuntu LTS on most of my production servers. It&#8217;s boring. It works. It has a clear 5-year support lifecycle. That&#8217;s exactly what you want for something you&#8217;re not planning to touch constantly [web:77][web:79].<\/p>\n<p><strong>Don&#8217;t use<\/strong>: Rolling release distros, beta versions, anything marked &#8220;unstable.&#8221; Save that for your laptop where you can break things without anyone caring.<\/p>\n<h2>Automated Updates: The Foundation You Can&#8217;t Skip<\/h2>\n<p>Here&#8217;s the controversial take: <strong>automated security updates are essential<\/strong>. Yes, I know some update might theoretically break something. You know what breaks things more often? Unpatched security vulnerabilities getting exploited.<\/p>\n<p>On Debian\/Ubuntu, <code>unattended-upgrades<\/code> is your solution [web:77][web:86]:<\/p>\n<pre><code class=\"language-bash\">apt install unattended-upgrades\ndpkg-reconfigure -plow unattended-upgrades<\/code><\/pre>\n<p>Configure it to install security updates automatically. Edit <code>\/etc\/apt\/apt.conf.d\/50unattended-upgrades<\/code>:<\/p>\n<pre><code class=\"language-conf\">Unattended-Upgrade::Allowed-Origins {\n    \"${distro_id}:${distro_codename}-security\";\n    \"${distro_id}ESMApps:${distro_codename}-apps-security\";\n};\n\nUnattended-Upgrade::AutoFixInterruptedDpkg \"true\";\nUnattended-Upgrade::MinimalSteps \"true\";\nUnattended-Upgrade::Remove-Unused-Dependencies \"true\";\nUnattended-Upgrade::Automatic-Reboot \"false\";<\/code><\/pre>\n<p>Notice that last line? I don&#8217;t auto-reboot. Some people do. I prefer to schedule reboots myself during maintenance windows because I&#8217;m paranoid and I like to see my servers come back up [web:86][web:89].<\/p>\n<p><strong>For RHEL-based systems<\/strong>, use <code>dnf-automatic<\/code>:<\/p>\n<pre><code class=\"language-bash\">dnf install dnf-automatic\nsystemctl enable --now dnf-automatic.timer<\/code><\/pre>\n<p>Now your server patches itself. One less thing to worry about.<\/p>\n<h2>Log Management: Because Disks Fill Up<\/h2>\n<p>You know what kills long-running servers? Full disks. You know what fills disks on servers nobody&#8217;s watching? Logs.<\/p>\n<p>By default, <code>logrotate<\/code> should be configured, but let&#8217;s make sure it&#8217;s actually working and aggressive enough:<\/p>\n<pre><code class=\"language-bash\"># Check if logrotate is running\nsystemctl status logrotate.timer\n\n# Configure aggressive log rotation\ncat &gt; \/etc\/logrotate.d\/custom-aggressive &lt;&lt;EOF\n\/var\/log\/*.log {\n    daily\n    missingok\n    rotate 7\n    compress\n    delaycompress\n    notifempty\n    create 0640 root adm\n    sharedscripts\n}\nEOF<\/code><\/pre>\n<p>This keeps only 7 days of logs, compressed. Adjust to your needs, but don&#8217;t keep months of logs unless you actually use them [web:79][web:82].<\/p>\n<p>Also, <strong>monitor your disk usage<\/strong>. Set up a simple cron job:<\/p>\n<pre><code class=\"language-bash\">#!\/bin\/bash\n# \/usr\/local\/bin\/disk-alert.sh\n\nTHRESHOLD=80\nUSAGE=$(df \/ | grep \/ | awk '{ print $5}' | sed 's\/%\/\/g')\n\nif [ $USAGE -gt $THRESHOLD ]; then\n    echo \"WARNING: Disk usage is ${USAGE}% on $(hostname)\" | \\\n        mail -s \"Disk Space Alert on $(hostname)\" admin@example.com\nfi<\/code><\/pre>\n<p>Run it daily. When your disk hits 80%, you&#8217;ll know before it hits 100% and causes problems.<\/p>\n<h2>Monitoring: Because You Need to Know When Things Break<\/h2>\n<p>&#8220;Unattended&#8221; doesn&#8217;t mean &#8220;unmonitored.&#8221; It means you&#8217;re not manually checking everything constantly, but the system tells you when something&#8217;s wrong.<\/p>\n<p>Bare minimum monitoring you need: server is reachable, critical services are running, disk isn&#8217;t full, SSL certificates aren&#8217;t expired [web:79][web:85].<\/p>\n<p>For simple setups, I use a combination of external uptime monitoring (UptimeRobot, Pingdom, whatever) and basic local monitoring with email alerts.<\/p>\n<p>Simple service monitoring script:<\/p>\n<pre><code class=\"language-bash\">#!\/bin\/bash\n# \/usr\/local\/bin\/service-monitor.sh\n\nSERVICES=\"nginx mysql redis-server\"\n\nfor service in $SERVICES; do\n    if ! systemctl is-active --quiet $service; then\n        echo \"$service is down on $(hostname)\" | \\\n            mail -s \"Service Alert: $service down\" admin@example.com\n        systemctl start $service\n    fi\ndone<\/code><\/pre>\n<p>Add to crontab to run every 5 minutes:<\/p>\n<pre><code class=\"language-cron\">*\/5 * * * * \/usr\/local\/bin\/service-monitor.sh<\/code><\/pre>\n<p>Not sophisticated, but it works. Service goes down? You get an email and it attempts to restart automatically [web:79][web:82].<\/p>\n<h2>Backups: Because Everything Eventually Fails<\/h2>\n<p>You know what&#8217;s worse than a server failing? A server failing when you realize your backups don&#8217;t work. Or don&#8217;t exist.<\/p>\n<p><strong>Automate your backups. Test your backups. Seriously.<\/strong><\/p>\n<p>Simple backup strategy that actually works:<\/p>\n<pre><code class=\"language-bash\">#!\/bin\/bash\n# \/usr\/local\/bin\/backup.sh\n\nBACKUP_DIR=\"\/var\/backups\/daily\"\nDATE=$(date +%Y%m%d)\nRETENTION_DAYS=14\n\nmkdir -p $BACKUP_DIR\n\n# Backup databases\nmysqldump --all-databases | gzip &gt; $BACKUP_DIR\/mysql-$DATE.sql.gz\n\n# Backup important config files\ntar czf $BACKUP_DIR\/configs-$DATE.tar.gz \\\n    \/etc\/nginx \\\n    \/etc\/mysql \\\n    \/etc\/php \\\n    \/etc\/ssl\n\n# Backup web content\ntar czf $BACKUP_DIR\/www-$DATE.tar.gz \/var\/www\n\n# Copy to remote location (adjust for your setup)\nrsync -az $BACKUP_DIR\/ backup-server:\/backups\/$(hostname)\/\n\n# Delete old local backups\nfind $BACKUP_DIR -name \"*.gz\" -mtime +$RETENTION_DAYS -delete<\/code><\/pre>\n<p>Run nightly. Keep 14 days local, sync everything offsite [web:79][web:82].<\/p>\n<p><strong>Pro tip<\/strong>: Schedule a monthly cron job that tests restoring from backup to a test environment. Because untested backups are useless backups.<\/p>\n<h2>Automatic Cleanup Tasks<\/h2>\n<p>Servers accumulate junk. Old package caches, temp files, expired sessions. Clean this stuff automatically:<\/p>\n<pre><code class=\"language-bash\">#!\/bin\/bash\n# \/usr\/local\/bin\/cleanup.sh\n\n# Clean package cache\napt-get clean\napt-get autoclean\napt-get autoremove -y\n\n# Clean old temp files (older than 7 days)\nfind \/tmp -type f -atime +7 -delete\nfind \/var\/tmp -type f -atime +7 -delete\n\n# Clean PHP sessions (if older than 30 days)\nfind \/var\/lib\/php\/sessions -type f -mtime +30 -delete\n\n# Clean old log files not managed by logrotate\nfind \/var\/log -name \"*.log.*\" -mtime +30 -delete<\/code><\/pre>\n<p>Run weekly. Your disk will thank you [web:79].<\/p>\n<h2>Security: The Boring Stuff That Matters<\/h2>\n<p>An unattended server needs good security because you&#8217;re not constantly watching for intrusions.<\/p>\n<p><strong>Essentials<\/strong>: fail2ban for automatic IP banning, proper firewall configuration, SSH key authentication only, disabled root login, automatic security updates (already covered).<\/p>\n<p>Setup fail2ban:<\/p>\n<pre><code class=\"language-bash\">apt install fail2ban\nsystemctl enable fail2ban\n\n# Basic config that actually works\ncat &gt; \/etc\/fail2ban\/jail.local &lt;&lt;EOF\n[DEFAULT]\nbantime = 3600\nfindtime = 600\nmaxretry = 5\n\n[sshd]\nenabled = true\nport = ssh\nlogpath = \/var\/log\/auth.log\n\n[nginx-http-auth]\nenabled = true\nEOF\n\nsystemctl restart fail2ban<\/code><\/pre>\n<p>Now brute force attempts automatically result in temporary bans. One less thing to worry about [web:82].<\/p>\n<h2>SSL Certificate Renewal<\/h2>\n<p>If you&#8217;re running websites, you need SSL certificates. And they expire. Automate this with certbot:<\/p>\n<pre><code class=\"language-bash\">apt install certbot python3-certbot-nginx\n\n# Get certificate\ncertbot --nginx -d example.com\n\n# Auto-renewal is configured by default\nsystemctl status certbot.timer<\/code><\/pre>\n<p>Certbot automatically renews certificates 30 days before expiration. Just make sure the timer is enabled [web:79].<\/p>\n<h2>The Reboot Question<\/h2>\n<p>Should servers automatically reboot for kernel updates? This is religious territory, but here&#8217;s my take: <strong>schedule reboots monthly during maintenance windows<\/strong>, don&#8217;t fully automate them.<\/p>\n<p>Why? Because I want to be awake and available when a server reboots, just in case it doesn&#8217;t come back up cleanly. Your mileage may vary.<\/p>\n<p>If you do want automatic reboots after updates:<\/p>\n<pre><code class=\"language-bash\"># In \/etc\/apt\/apt.conf.d\/50unattended-upgrades\nUnattended-Upgrade::Automatic-Reboot \"true\";\nUnattended-Upgrade::Automatic-Reboot-Time \"03:00\";<\/code><\/pre>\n<p>This reboots at 3 AM if needed. Make sure you have console access if something goes wrong [web:86].<\/p>\n<h2>Documentation: Future You Will Thank Present You<\/h2>\n<p>Here&#8217;s something nobody does but everyone should: <strong>document your server configuration<\/strong>. When you log into a server you haven&#8217;t touched in 18 months because something weird happened, you&#8217;ll want notes.<\/p>\n<p>Keep a simple text file at <code>\/root\/README.txt<\/code>:<\/p>\n<pre><code class=\"language-text\">Server: web01.example.com\nPurpose: Production website hosting\nSetup date: 2025-10-18\n\nServices:\n- nginx on port 80\/443\n- MySQL on 3306 (local only)\n- PHP 8.2-FPM\n\nAutomated tasks:\n- Daily backups at 02:00\n- Security updates via unattended-upgrades\n- Weekly cleanup script\n- Monthly disk usage report\n\nImportant paths:\n- Website: \/var\/www\/example.com\n- Backups: \/var\/backups\/daily\n- Custom scripts: \/usr\/local\/bin\n\nContact: admin@example.com<\/code><\/pre>\n<p>Sounds simple? It is. It&#8217;s also incredibly valuable when you need it [web:82].<\/p>\n<h2>The Reality Check<\/h2>\n<p>A properly configured server can run for months or even years with minimal intervention. I have servers that I check on quarterly \u2013 they just work. But this requires: proper initial configuration, automated updates and backups, good monitoring with alerts, scheduled maintenance windows, documentation.<\/p>\n<p>&#8220;Unattended&#8221; means the server handles routine maintenance itself. It doesn&#8217;t mean you abandon it and hope for the best.<\/p>\n<p>Set it up right once, and you&#8217;ll spend your time building new things instead of firefighting old servers. That&#8217;s the whole point, isn&#8217;t it?<\/p>\n<hr \/>\n<p><em>P.S. \u2013 Test your monitoring and backups regularly. The best automated system in the world is worthless if you don&#8217;t verify it actually works. Trust, but verify.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Practical guide to setting up automated updates, monitoring, backups, and maintenance tasks so your Linux server can run reliably without constant babysitting<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_seo_schema_type":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[2],"tags":[],"class_list":["post-5","post","type-post","status-publish","format-standard","hentry","category-field-notes"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.cojan.ro\/blog\/wp-json\/wp\/v2\/posts\/5","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cojan.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cojan.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cojan.ro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cojan.ro\/blog\/wp-json\/wp\/v2\/comments?post=5"}],"version-history":[{"count":0,"href":"https:\/\/www.cojan.ro\/blog\/wp-json\/wp\/v2\/posts\/5\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.cojan.ro\/blog\/wp-json\/wp\/v2\/media?parent=5"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cojan.ro\/blog\/wp-json\/wp\/v2\/categories?post=5"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cojan.ro\/blog\/wp-json\/wp\/v2\/tags?post=5"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}