Deploying Long-Running Application Services on Virtual Machines: A Practical Guide

    Deploying a long-running application on a virtual machine requires more than installing an operating system, resolving dependencies, and starting a process. This guide explains how to design a server-oriented VM for unattended operation, covering deployment goals, capacity and disk layout, secure system preparation, runtime pinning and dependency isolation, system-service management, configuration and secret handling, controlled releases, minimal network exposure, observability, backups, recovery drills, and a practical troubleshooting sequence. It is intended for engineers who need a reproducible, maintainable deployment that survives reboots and recovers predictably from failures.

    Deploying Long-Running Application Services on Virtual Machines: A Practical Guide

    Running an application service that must stay online inside a virtual machine may look like a simple sequence: install the operating system, install dependencies, and start the process. In practice, the task is about stability, maintainability, and clear failure boundaries. An environment with a graphical desktop is convenient for installation, demonstrations, and temporary operations. A service that must run continuously is better suited to a server-style VM with a focused role, remote management, and restart and recovery behavior after reboot. Desktop sessions, graphical components, and containerized workstations often share the lifecycle of the host or interactive session; sleep, resolution changes, desktop crashes, or image updates can unexpectedly interrupt a production process. Before deployment, define the target as an unattended service, not a desktop computer that someone can open at any time.

    1. Define the Deployment Goal First

    Before you start, use four questions to constrain the design and avoid changing the plan while installing.

    1. Must the service be online 24/7, and can it tolerate planned reboots?
    2. Does it need a graphical interface, or only a command line and remote management?
    3. Is data allowed to reside on the system disk, and can it be recovered from backup if lost?
    4. Is access limited to internal debugging, or will the service be exposed to a broader network?

    If the answers point to long-term operation, choose a server-style VM: fixed compute and memory, a dedicated data disk, automatic startup on boot, collectable logs, and version-controlled configuration. A graphical desktop can remain available as a temporary troubleshooting tool, but it should not be a prerequisite for the service to stay alive. General-purpose cloud servers on public clouds—for example, Baidu AI Cloud’s cloud server offering—follow the same principles: plan compute, storage, network, and identity separately, and do not treat “a desktop that can be opened” as deployment completion.

    2. Capacity and Topology Planning

    For a lightweight interpreted runtime with one persistent process, 2 virtual CPUs and 4 GB of memory are often enough as a starting point to cover installation, dependency resolution, and light concurrency. This is a starting point, not a performance guarantee. Before finalizing the specifications, observe idle memory, startup peaks, log writes, and disk growth. If memory stays above 80% for long periods or frequent swapping occurs, scale up or split components instead of continuing to stack unrelated services on the same machine.

    Use at least three logical disk areas:

    • System disk: the operating system and basic tools, making reinstallation easier.
    • Data disk: application data, configuration, and persistent state that should survive an OS reinstall.
    • Log and backup space: limit individual file size so that logs cannot fill the root partition and prevent the service from starting.

    On the network, use different ports for the management entry point and the business entry point, and allow access only from necessary network ranges. Do not share excessively broad permissions between the VM and its host. The host provides compute and storage, while a service account inside the VM should have access only to its own directories.

    3. System Preparation

    When creating the VM, select a long-term-support server edition, and set the language and time zone clearly during installation so that log timestamps do not diverge from the operations team’s time zone. Immediately after installation, do three things: update system packages, create a normal administrative account, and confirm time synchronization. Use that normal account for subsequent installation and daily operations, and elevate privileges only temporarily when modifying system configuration.

    Remote management should use key-based login by default, disable empty passwords, and restrict allowed source addresses. Do not enable direct administrator password login just for convenience. Once a management port is exposed to an untrusted network, credential-stuffing attacks and automated scanning can turn the host into an entry point. If the management port must be reachable externally, place it behind a restricted network, a bastion or jump host, or an equivalent gateway rather than opening it to the entire internet.

    Install only the basic tools you actually need: a version control client, a download tool, a text editor, and a process viewer. After installation, use the normal account to verify that you can log in, write to the planned data directory, and that system time is correct. If this step fails, do not continue installing the application.

    4. Runtime and Dependency Isolation

    A long-running application should pin the runtime major version instead of always following the “latest” release. Version drift can cause an application that starts today to fail next week after dependency resolution. Recommended practices:

    • Use an independent user-level version manager instead of polluting the system-provided runtime.
    • Record the major version in the project documentation, for example: “The runtime major version is fixed to a specific long-term-support release.”
    • Keep the dependency manifest and lock file together so another machine can reproduce the environment.
    • Install the application in the service account’s home directory or a dedicated directory, not in a temporary desktop session path.

    After installation, run a version check and a health check in a non-interactive way. The health check should at least confirm that the process can start, the configuration file can be read, required ports are available, and the data directory is writable. If the application provides a localized UI or localized configuration, pin the language pack, locale, and character encoding together to avoid garbling caused by mismatches between the remote terminal and file encoding.

    The following shows sequence only; it contains no product-specific installation address:

    1. # 1. Create a service account and enter its home directory
    2. # 2. Install and pin the runtime major version
    3. # 3. Place configuration and the dependency manifest in the data directory
    4. # 4. Run the pre-start self-check as the service account
    5. # 5. Confirm the listening address, ports, and log path

    Do not treat a script fetched from an external source and executed immediately as the only deliverable. A script can speed up initial installation, but production environments should retain an offline package or internal artifact, verify integrity, and keep the steps repeatable.

    5. Run the Process Under a System Service

    A process started manually in a terminal usually ends when the session exits, making it unsuitable for long-running service. Delegate the application to a system service manager: start it on boot, restart it according to policy after an abnormal exit, and collect standard output into logs. The service unit should at least specify:

    • The run user, with no unnecessary use of a superuser.
    • The working directory and environment variables, including the runtime path.
    • The start command and stop signal, ensuring graceful shutdown.
    • The restart interval and retry limit, preventing a crash loop from saturating the CPU.
    • Dependency ordering, such as starting only after the network is ready.

    After changing configuration, run a syntax check first, then reload the service and inspect recent logs. Consider the release complete only after the health check passes. Treating “a welcome message in the terminal” as deployment success is one of the most common causes of later failures.

    6. Configuration, Secrets, and Releases

    Configuration has three layers: default configuration shipped with the version, environment-specific configuration, and secrets and tokens. The first two layers can be placed in controlled directories with change records; secrets must not be committed to version control, pasted into chat, or captured in screenshots. Restrict permissions so that only the service account can read them. After rotating a secret, verify whether the old process has loaded the new value, and perform a rolling restart if necessary.

    Use a fixed release sequence: back up current configuration and data, deploy the new version, run the self-check, switch the service, and observe error rates and resource usage. Keep the previous runnable version available so rollback can happen within minutes. Do not overwrite files directly in a directory that is actively serving traffic without leaving a rollback path.

    7. Access Points and Minimal Exposure

    Bind business ports only to the addresses that are actually required. For local-only debugging, bind to the loopback address; when LAN access is needed, bind to the internal address and explicitly allow access in the host or virtual-network firewall. Add reverse proxying, access authentication, and transport encryption according to data sensitivity instead of exposing the management interface by default.

    If a gateway or load balancer is in front of the service, the health check path should be lightweight and must not trigger expensive computation. A failed check should distinguish between “the process is not running” and “a dependency is unavailable”; otherwise, restart policies may repeatedly disrupt healthy instances.

    8. Observability, Backups, and Drills

    Collect at least four types of signals: whether the process is alive, whether the port is connectable, whether error logs are spiking, and whether disk and memory are approaching thresholds. Rotate logs daily or by size, and document the retention period in advance. Start with a small, accurate set of alerts: service down, disk nearly full, and repeated restarts. A dashboard that nobody watches is less useful than one alert that actually reaches someone.

    Backups must cover configuration, business data, and recovery-step documentation, and a restore drill should be performed regularly. Merely having backup files does not mean recovery is possible. The system disk can be rebuilt; the data disk must have an independent copy, and the copy must not reside in the same fault domain as the VM. Before upgrading the operating system, take a snapshot or equivalent backup and confirm the rollback time.

    9. Common Failures and Troubleshooting Order

    When deployment fails, troubleshoot along the dependency chain instead of repeatedly reinstalling.

    • Cannot log in remotely: check the network, firewall, and authentication method first, then whether the account is locked.
    • Process exits immediately: check service logs, working-directory permissions, and whether the runtime version matches the documentation.
    • Port unreachable: confirm the listening address, security group or firewall rules, and whether another process is occupying the port.
    • Service disappears after reboot: check whether it is registered as a system service instead of running only in an interactive terminal.
    • Disk full: clean up oversized logs, confirm the rotation policy, and expand the data disk if necessary.
    • Abnormal behavior after upgrade: compare the dependency lock file, roll back to the previous runnable version, and then analyze the differences.

    10. Deployment Checklist

    Before completion, verify each item:

    • VM specifications and disk separation have been determined.
    • A normal user account and key-based login are in use.
    • The runtime version is pinned.
    • Configuration and secrets are separated.
    • The system service starts on boot and recovers according to policy after an abnormal exit.
    • The firewall permits only necessary ports.
    • Logs, alerts, and backups are available.
    • Rollback steps have been exercised once.

    When these conditions are met, the VM is a host for long-running services, not a desktop that is opened temporarily.