Apostol is a framework for developing server applications (system services) on the Linux OS.
Apostol is developed in the C++ programming language using an asynchronous programming model based on the epoll API with direct access to the PostgreSQL (via the libpq
library) specifically for high-load systems.
The key element of the platform is the built-in HTTP server with direct access to the PostgreSQL DBMS.
The uniqueness of the solution lies in the fact that both the HTTP server and PostgreSQL sockets are within a single event processing loop, which allows data to be transmitted instantly from the HTTP server to the database. In other words, there are no intermediaries, typically represented by scripting languages, between the HTTP server and the database. This, in turn, allows database queries to be executed with maximum efficiency and minimal latency.
- The main advantages:
- Autonomy: After building, you get a fully ready-to-use binary file in the form of a system service (daemon) under Linux OS;
- Speed: Queries to the HTTP server and the database are executed as fast as the operating system and DBMS allow;
- Connection pool: Apostol has its own customizable connection pool with PostgreSQL.
The framework has a modular design, built-in HTTP server, and PostgreSQL client.
-
WebServer (Web server);
- Provides the Swagger UI which will be available at http://localhost:8080 in your browser after launching Apostol.
-
PGFetch (Postgres Fetch);
- Enables receiving and sending
HTTP requests
in thePL/pgSQL
programming language.
- Enables receiving and sending
- AuthServer (Authorization server OAuth 2.0);
- AppServer (Application server);
- MessageServer (Message server: SMTP/FCM/API);
- FileServer (File server);
- Replication (Database replication);
- StreamServer (Streaming data server).
Apostol has built-in WebSocket support: WebSocket API.
Combining all the above, you can create an information system CRM System, Central system for charging points or Telegram bot on PL/pgSQL why not ;-).
With Apostol your possibilities are only limited by your imagination.
Projects implemented at Apostol:
- CopyFrog (AI-powered platform for creating unique images, Ad Copy, video creatives, marketing descriptions for products and services)
- OCPP CSS (Central System as Service for Charging Points)
- BitDeals (Bitcoin payment processing service)
- Ship Safety ERP (ERP system for organization of production activities of the shipping company)
- PlugMe (CRM system for charging stations and owners of electric vehicles)
- DEBT Master (A system for automating debt collection)
You can build an image yourself or get a ready-made one from Docker Hub:
docker build -t apostol .
docker pull apostoldevel/apostol
If you built it yourself:
docker run -d -p 8080:8080 -p 8081:8081 -p 5433:5432 --rm --name apostol apostol
If you got a ready-made image:
docker run -d -p 8080:8080 -p 8081:8081 -p 5433:5432 --rm --name apostol apostoldevel/apostol
Swagger UI will be available at http://localhost:8080 or http://host-ip:8080 in your browser.
Pgweb is a web-based database explorer for PostgreSQL will be available at http://localhost:8081 or http://host-ip:8081 in your browser.
Instead of pgweb, you can use any other tool for working with databases. PostgreSQL from the container will be available on port 5433.
auto/ contains scripts files
cmake-modules/ contains CMake modules files
conf/ contains configuration files
src/ contains source code files
├─app/ contains source code files: Apostol
├─core/ contains source code files: Apostol Core
├─lib/ contains source code files for libraries
| └─delphi/ contains source code files for the library*: Delphi classes for C++
└─modules/ contains source code files for add-ons (modules)
www/ contains files for the website
To install Apostol, you will need:
- C++ compiler;
- CMake or an Integrated Development Environment (IDE) with CMake support;
- libpq-dev library (libraries and headers for C language frontend development);
- postgresql-server-dev-all library (libraries and headers for C language backend development).
To install the C++ compiler and necessary libraries on Ubuntu, run:
sudo apt-get install build-essential libssl-dev libcurl4-openssl-dev make cmake gcc g++
A detailed description of how to install C++, CMake, IDE, and other components required for the project build is not included in this guide.
To install PostgreSQL, use the instructions at this link.
To install the database, you need to perform the following steps:
- Specify the name of the database in the db/sql/sets.conf file (by default: web)
- Specify the passwords for the DBMS users libpq-pgpass:
$ sudo -iu postgres -H vim .pgpass
*:*:*:http:http
- Specify in the configuration file /etc/postgresql/{version}/main/pg_hba.conf:
# TYPE DATABASE USER ADDRESS METHOD local web http md5
- Apply the settings:
$ sudo pg_ctlcluster <version> main reload
- Execute:
$ cd db/ $ ./install.sh --make
The --make parameter is required to install the database for the first time. After that, the installation script can be run without parameters or with the --install parameter.
To install Apostol (without Git), you need to:
- Download Apostol;
- Unpack it;
- Configure CMakeLists.txt (if necessary);
- Build and compile (see below).
To install Apostol using Git, execute:
git clone https://github.com/apostoldevel/apostol.git
cd apostol
./configure
cd cmake-build-release
make
sudo make install
By default, the apostol binary will be installed in:
/usr/sbin
The configuration file and files required for operation, depending on the installation option, will be located in:
/etc/apostol
or
~/apostol
apostol
is a Linux system service (daemon).
To manage apostol
, use standard service management commands.
To launch apostol
, execute:
sudo systemctl start apostol
To check the status, execute:
sudo systemctl status apostol
The result should be something like this:
● apostol.service - Apostol
Loaded: loaded (/etc/systemd/system/apostol.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2019-04-06 00:00:00 MSK; 3y ago
Process: 461158 ExecStartPre=/usr/bin/rm -f /run/apostol.pid (code=exited, status=0/SUCCESS)
Process: 461160 ExecStartPre=/usr/sbin/apostol -t (code=exited, status=0/SUCCESS)
Process: 461162 ExecStart=/usr/sbin/apostol (code=exited, status=0/SUCCESS)
Main PID: 461163 (apostol)
Tasks: 2 (limit: 77011)
Memory: 2.6M
CPU: 44ms
CGroup: /system.slice/apostol.service
├─461163 apostol: master process /usr/sbin/apostol
└─461164 apostol: worker process ("pq fetch", "web server")
apostol
can be managed using signals.
The main process number is written by default to the /run/apostol.pid
file.
You can change the name of this file during the build configuration or in the apostol.conf
[daemon]
section with the pid
key.
The main process supports the following signals:
Signal | Action |
---|---|
TERM, INT | fast shutdown |
QUIT | graceful shutdown |
HUP | configuration change, launching new worker processes with new configuration, graceful shutdown of old worker processes |
WINCH | graceful shutdown of worker processes |
There is no need to manage worker processes individually. Nevertheless, they also support some signals:
Signal | Action |
---|---|
TERM, INT | fast shutdown |
QUIT | graceful shutdown |