Skip to main content
Version: 2.8.x(Latest)

Applications developed using GoFrame can be independently deployed on servers to run as background daemon processes. This mode is commonly used in simple API service projects.

We recommend using the *nix server series (including: Linux, MacOS, *BSD). Below, we use the Ubuntu system as an example to introduce how to deploy projects developed using the GoFrame framework.

*nix

1. nohup

We can use the simple nohup command to run the application as a background daemon process so that even if a remote SSH connection is disconnected, the program's execution will not be affected. The nohup command tool is often pre-installed in popular Linux distributions. The command is as follows:

nohup ./gf-app &

2. tmux

tmux is a terminal multiplexer tool under Linux that can open different terminal windows to run applications as background daemon processes. Even if the remote SSH connection is disconnected, the program's execution will not be affected. Install it directly on the ubuntu system using sudo apt-get install tmux. Use the following steps to run the application in the background.

  1. tmux new -s gf-app;
  2. Execute ./gf-app in the new terminal window;
  3. Use the shortcut ctrl + B & D to exit the current terminal window;
  4. Use tmux attach -t gf-app to enter the previous terminal window;

3. supervisor

supervisor is a universal process control program developed in Python, capable of transforming a normal command-line process into a background daemon and monitoring the process status, automatically restarting it if it exits abnormally. Official website: http://supervisord.org/ Common configuration is as follows:

[program:gf-app]
user = root
directory = /var/www
command = /var/www/main
stdout_logfile = /var/log/gf-app-stdout.log
stderr_logfile = /var/log/gf-app-stderr.log
autostart = true
autorestart = true

The steps are as follows:

  1. Use sudo service supervisor start to start the supervisor service;
  2. Create an application configuration file /etc/supervisor/conf.d/gf-app.conf, with the content as above;
  3. Use sudo supervisorctl to enter the supervisor management terminal;
  4. Use reload to reread the configuration file and restart all processes managed by supervisor;
  5. You can also use update to reload the configuration (default without restarting) and then use start gf-app to start the specified application;
  6. Then use the status command to view the status of the processes managed by supervisor;

Sharing pitfalls:

  1. After changing the conf configuration file, execute reload in supervisorctl to update and use the latest configuration.
  2. The directory configuration usually cannot be omitted, specifying the current working directory path, and must be configured before command.
  3. The command needs to use an absolute path; otherwise, it will not find the executable file.

4. systemctl

Systemd is a Linux system tool used to start daemon processes, and it has become the standard configuration for most distributions.

systemctl is the main command of Systemd used to manage the system. You can refer to Ruan Yifeng's interpretation of Systemd, particularly sections four and five.

In fact, most of our services are managed with systemctl, such as MySQL, Nginx, etc.

Common configuration is as follows:

[Unit]
# Unit description
Description=GF APP
# Execute this program after what service starts
After=mysql.service

[Service]
Type=simple
# Directory of program execution
WorkingDirectory=/data/server/gfapp/
# Startup script command
ExecStart=/data/server/gfapp/gfapp
# Restart conditions
Restart=always
# Seconds to restart
RestartSec=5

[Install]
WantedBy=multi-user.target

Usage:

  1. Create an application configuration file /etc/systemd/system/gfapp.service, with the content as above;
  2. Use systemctl daemon-reload to reload services;
  3. Execute systemctl start gfapp to start the service;
  4. Finally, execute systemctl status gfapp to view the service running status information;
  5. Execute systemctl enable gfapp to add the service to the boot startup items;
  6. Note: The executed gfapp uses the file name as the service name;
  7. Common commands are: start(start), stop(stop), restart(restart), status(view running status), enable(add to boot startup), disable(remove program from boot startup)

5. screen

Screen is a free software developed under the GNU project for command-line terminal switching. Users can connect to multiple local or remote command-line sessions simultaneously and switch between them freely. GNU Screen can be considered a command-line interface version of a window manager. It provides a unified interface and corresponding functionality for managing multiple sessions.

Installation:

sudo apt install -y screen ( debian series)

sudo yum install -y screen  ( centos)

Common parameters:

  1. screen -S yourname -> Create a session called yourname
  2. screen -ls -> List all current sessions
  3. screen -r yourname -> Return to yourname session
  4. screen -d yourname -> Remotely detach a session
  5. screen -d -r yourname -> End the current session and return to yourname session

Usage:

  1. Use the command screen -S gfapp to create a session;
  2. Execute ./gf-app in the new terminal window;
  3. Execute ctrl-a, ctrl-d to temporarily leave the current session;
  4. Execute screen -r gfapp to return to the command window; if not successful, the window might be occupied (Attached), try screen -Dr gfapp;
  5. Execute screen -X -S gfapp quit to end the program;

windows

1. NSSM

Small and Practical NSSM Packaging Windows Service Tool Introduction - Zhihu (zhihu.com)