Skip to content

create

How to Create a Well-Behaved Unix/Linux Daemon in Ruby with Double-Fork: A Complete Guide

Introduction

In the world of Unix and Linux systems, daemons are the unsung heroes of background processing. These long-running processes operate independently of any user session, handling tasks like scheduling jobs, monitoring services, or processing data in the background. From web servers like Nginx to system services like cron, daemons keep our systems running smoothly without direct user interaction.

While Ruby is often associated with web development, it’s equally capable of building robust system daemons. However, creating a "well-behaved" daemon—one that detaches cleanly from the terminal, handles signals gracefully, and avoids resource leaks—requires careful attention to Unix process management.

In this guide, we’ll demystify daemonization in Ruby, focusing on the double-fork technique—a time-tested method to ensure your daemon adheres to Unix best practices. By the end, you’ll have a fully functional, production-ready Ruby daemon and the knowledge to customize it for your needs.

Note: Ruby provides a built-in Process.daemon method (since Ruby 1.9) that handles the double-fork, setsid, and FD cleanup internally. If you just need a quick daemon and don’t need fine-grained control, Process.daemon is a simpler alternative. This guide focuses on the manual approach so you understand each step. Additionally, modern init systems like systemd can manage daemonization for you—consider running your Ruby process in the foreground with a systemd unit file using Type=simple or Type=notify.

How to Create Dedicated Folders for Each Zip File and Extract Them Using Shell Script: Fixing Unzip's Direct Extraction Issue

Introduction

If you’ve ever worked with multiple zip files, you’ve likely encountered this frustration: extracting a zip file only to have its contents spill directly into your current directory, cluttering it with loose files (e.g., document.pdf, image.jpg, data.csv). This happens when the zip archive lacks a root folder—a common oversight when zipping files without first organizing them into a directory.

Manually creating a folder for each zip and extracting into it is tedious, especially with dozens of files. The solution? A simple shell script that automates this process: it creates a dedicated folder for every zip file (named after the zip itself) and extracts the contents into that folder.

In this blog, we’ll walk through building this script step-by-step, explaining how it works, how to test it, and how to customize it for your needs. By the end, you’ll have a tool to keep your directories organized effortlessly.

Introduction

In the Unix-like operating systems, files are managed through a combination of file handles (or file descriptors) and hard links, two fundamental abstractions that power everything from basic file operations to complex system design. File handles allow processes to interact with open files, while hard links provide a way to reference the same underlying data through multiple directory entries. But a common question arises: Can you create a hard link directly from a file handle?

This blog dives into the technicalities of file handles, hard links, and the Unix kernel’s design to answer that question. We’ll explore why direct hard link creation from a file handle is generally unsupported, workarounds for safe file writing, and why atomic moves remain the gold standard for reliable file updates. Whether you’re a system administrator, developer, or curious Unix enthusiast, this guide will clarify these concepts and their practical implications.

How to Create a Java Executable (JAR) with Eclipse on Ubuntu: Compile and Run from Command Line – Beginner's Guide

Introduction

Java is a versatile, cross-platform programming language, and one of its most powerful features is the ability to package applications into JAR (Java Archive) files. JAR files bundle all your Java classes, resources, and metadata into a single, portable file, making it easy to distribute and run applications across different operating systems.

If you’re new to Java development on Ubuntu, this guide will walk you through creating a simple Java project using Eclipse (a popular IDE), exporting it as an executable JAR, and even compiling/running it manually from the command line. By the end, you’ll be able to package and run your Java apps like a pro!

How to Create an Empty File in Linux Command Line with Same Permissions and Ownership (Without Copying Contents)

Introduction

In Linux, file permissions and ownership are critical for security and access control. There are scenarios where you might need to create a new empty file that mirrors the permissions and ownership of an existing file—without copying its contents. For example: - Creating a new log file that inherits the security settings of an existing log. - Generating a blank configuration file with the same access rules as a template. - Setting up a placeholder file for an application that expects specific ownership/permissions.

Manually replicating permissions and ownership can be error-prone. This guide will walk you through three reliable methods to achieve this efficiently, using built-in Linux commands. We’ll avoid copying file contents entirely, focusing only on replicating metadata (permissions and ownership).

How to Create a Folder Using Java Code on Windows and Linux Machines

Introduction

In Java, creating folders (directories) programmatically is a common task in applications that handle file management, such as log generators, data exporters, or file organizers. Whether you’re developing for Windows, Linux, or cross-platform systems, Java provides robust APIs to create directories seamlessly. This blog will guide you through the process of creating folders using Java, covering both legacy (java.io.File) and modern (java.nio.file) APIs, with a focus on cross-platform compatibility between Windows and Linux. By the end, you’ll understand how to handle path differences, permissions, and common pitfalls.

How to Create an SFTP User with Restricted Access to a Single Directory: A Guide Using Chroot and sshd_config

Introduction

Secure File Transfer Protocol (SFTP) is a widely used method for securely transferring files between systems over an encrypted SSH connection. However, by default, SFTP users may gain access to more of your server’s filesystem than intended—posing security risks. Restricting an SFTP user to a single directory (a "chroot jail") ensures they can only interact with files in that specific location, enhancing security and limiting potential damage from accidental or malicious actions.

In this guide, we’ll walk through the process of creating an SFTP user with restricted access using Chroot (a Unix system call that isolates a process to a specific directory tree) and configuring sshd_config (the main configuration file for the SSH daemon). By the end, you’ll have a locked-down SFTP environment where users can upload/download files without accessing the rest of your server.

How to Create an IAM User with Restricted Access to a Specific S3 Bucket: Prevent Listing Other Buckets & Grant List/Write Permissions

Introduction

Amazon S3 (Simple Storage Service) is a cornerstone of AWS, used for storing and retrieving data globally. However, with great flexibility comes the need for robust security. A common scenario is granting an IAM (Identity and Access Management) user access to a specific S3 bucket while restricting them from listing other buckets in your AWS account. This ensures compliance with the principle of least privilege, minimizing the risk of accidental data exposure or modification.

In this blog, we’ll walk through a step-by-step guide to creating an IAM user with: - No access to list other S3 buckets in the account. - List permissions for the specific target bucket. - Write permissions (e.g., upload objects) to the target bucket.

We’ll cover policy creation, user setup, testing, troubleshooting, and best practices to ensure your configuration is secure and effective.

How to Create a Single Tar File from Multiple Directories Excluding Parent Folders in Bash

Introduction

Tar (Tape Archive) is a powerful command-line tool in Unix and Linux systems for creating and manipulating archive files. A common task is to bundle multiple directories into a single tar file, but often you’ll want to exclude their parent folders—meaning the archived directories should sit directly at the root of the tar file, not nested inside their original parent directory. This is useful for sharing specific subdirectories, creating clean backups, or distributing content without extra folder hierarchy.

In this guide, we’ll break down how to achieve this using Bash, with step-by-step examples, advanced scenarios, and common pitfalls to avoid. By the end, you’ll master the art of creating tar archives with precise control over directory structure.

How to Create a Static Haskell Linux Executable: Fixing Compatibility Issues on CentOS 5.3 (64-bit)

Introduction

Static executables are a powerful solution for distributing software across diverse Linux environments, as they bundle all dependencies directly into the binary. This eliminates "missing library" errors, making deployment seamless—especially on older systems with outdated libraries.

CentOS 5.3 (64-bit), released in 2009, is a classic example of such an environment. It runs on the 2.6.18 kernel and uses glibc 2.5, which is far older than the libraries found on modern Linux distributions. Compiling Haskell code for CentOS 5.3 often results in compatibility issues like GLIBC_2.XX not found because newer compilers and dynamic executables rely on newer system libraries.

In this guide, we’ll walk through creating a statically linked Haskell executable specifically tailored for CentOS 5.3 (64-bit). We’ll cover setting up a build environment, configuring static linking, handling dependencies, and troubleshooting common pitfalls. We’ll also discuss the modern recommended approach using musl libc and Alpine Linux.

Note: CentOS 5 reached End of Life on March 31, 2017, and CentOS Linux as a whole has been discontinued. This guide remains useful for maintaining legacy systems or understanding static linking concepts, but for new deployments, consider using a supported distribution such as Rocky Linux, AlmaLinux, or Alpine Linux.