Skip to content

πŸš€ An easier tool to automate your Ubuntu Server setup and domain forwarding.

License

Notifications You must be signed in to change notification settings

wellwelwel/svps

Repository files navigation

SVPS - Simplifying VPS

πŸš€ An easier tool to automate your Ubuntu Server setup and domain forwarding

npm GitHub Workflow Status (with event) npm License

Table of Contents


About

SVPS, initially designed to simplify tasks for non-Unix users, works as an ORM for Ubuntu Servers.

It supports command automation, files and directories upload via SFTP, automatic installations and configurations, domain forwarding, local text files and template strings into escaped quoted strings for dynamic remote file creation, among other features.

All this, using just a single one connection πŸ§™πŸ»βœ¨


Installation

  npm i svps

Usage

import { SVPS } from 'svps';

/** Prepare the connection */
const svps = new SVPS({
  access: {
    host: '127.0.0.1',
    username: 'root',
    password: 'root',
  },
});

/** For AWS */
const svps = new SVPS({
  access: {
    host: '***.amazonaws.com',
    username: 'ubuntu',
    privateKey: fs.readFileSync('./your_rsa.pem'),
  },
});

/** Available methods
 * svps.mount
 * svps.commands
 * svps.createVirtualHosts
 * svps.upload
 * svps.end
 *
 * See about each below πŸ•΅πŸ»
 */

Automatic Installations

await svps.mount({
  php: true || { version: 8.2, composer: true },
  node: true || { version: 18, packages: ['yarn'] },
  apache: true,
  docker: true,
  // ...

  /**
   * ... Users, Desktop (RDP), Firewall,  etc.
   *
   * See all available automatic installations below πŸ‘‡πŸ»
   */
});

Available auto-installation

See some practical examples.

Notes

  • The entire remote process is displayed on console in real time
  • Find all the commands behind SVPS in src/lib/tasks/steps
  • This may take a long time depending on your VPS specifications

Personal Commands (Queuing)

Create your own commands and combine with other SVPS features.

const commands = ['echo "πŸš€"'];

await svps.commands(commands);
  • You can use the escapeQuotes method to create multi-line escaped quoted strings. See an example here.

Upload Files and Directories

Transfer your local files and directories and set permissions for each upload.

await svps.upload([
  {
    local: './my-app-dist',
    remote: '/workspace',
    permissions: {
      user: 'my-user',
    },
  },
]);
  • It uses SFTP to send the content to remote server

Download Files

Download your remote files.

await svps.download([
  {
    remote: '/workspace/backup.zip',
    local: './my-local-path/backup.zip',
  },
]);
  • It uses SFTP to get the content from remote server

Virtual Hosts (Domains Forwarding)

await svps.createVirtualHosts([
  // Basic or Advanced Virtual Hosts
]);

/**
 * This will create a log with the processed domains to ensure that only new domains are processed.
 * If you delete this log, the domains will be understood as new and will be overwritten.
 */

Basic Usage (easier)

Node.js PHP MySQL

You can automatically create Node.js (LTS) and PHP (8.2) services and work on them in /var/containers/domains/your_domain.
Also, it allows to use an exclusive MySQL database for each domain.

await svps.createVirtualHosts([
  {
    domain: 'site.com',
    port: 5000,
    www: true /** creates an alias for "www.site.com" */,
    server: {
      language: 'node' | 'php',
      mysql: {
        database: 'db-name',
        password: 'db-pass',
        expose: 5001 /** expose port 5001 locally */,
        isPublic: true /** expose port 5001 outside the VPS */,
      },
    },
  },
]);
  • For PHP, you can flag the server option buildFromScratch as true to create the Virtual Host image from scratch, otherwise it will pull the images from my Docker Hub πŸ™‹πŸ»β€β™‚οΈ

To create flexible Basic Virtual Hosts, SVPS uses Docker containers and Apache2 to proxy their ports to your domains.

Apache2, Docker and Docker Compose required.

See some practical examples here.


Advanced Usage (manual)

Everything

By using the Virtual Hosts solely to proxy your services, you can create services in any language you choose, by simply defining the port your service is on.

await svps.createVirtualHosts([
  {
    domain: 'site.com',
    port: 5000,
    www: true /** creates an alias for "www.site.com" */,
  },
]);

// It will proxy your service at port 5000 to "site.com" and "www.site.com"

Apache2 required.


Turning VPS Server into Desktop Server (RDP)

await svps.mount({
  desktop: true,
});

/** That's it πŸ€ΉπŸ»β€β™€οΈ */
  • It will install Xubuntu Desktop and RDP Remote in port 3389
  • The desktop installation can take longer and take up more disk space (about 1GB to 3GB)
  • If you are using a container, remember to expose the port 3389
  • To access, use your credentials in a Remote Desktop Software

See a practical example using a Docker container.


Testing using a Docker Container

  • Create the container:

    docker run -d --privileged -p 22:22 --restart always wellwelwel/vps:latest
  • Then, set the default access:

    const svps = new SVPS({
      access: {
        host: '127.0.0.1',
        username: 'root',
        password: 'root',
        port: 22,
      },
    });

Close the Connection

await svps.end();

Important

  • This package is designed for pre-built VPS, KVM and Ubuntu Server >=18.04
  • The SSH user needs to be the root or a super user
  • Avoid running this tool on a server that is already in production, unless you know what you're doing πŸ§™πŸ»

Known Issues


Compatibility

macOS Linux Windows node npm


Community

I'm continuously working to improve SVPS. If you've got something interesting to share, feel free to submit a Pull Request. If you notice something wrong, I'd appreciate if you'd open an Issue.


Contributing

Please check the CONTRIBUTING.md for instructions πŸš€