name: Deployment with Systemctl

sort: 2

Systemctl

Systemctl command is a command used to manage and control services. It allows you to enable, disable, view, start, stop, or restart system services.

Install beego application as a service

  1. Pack your application using bee pack command. Copy the resultant .tar.gz file to target server.

  2. Unpack

    1. mkdir -p /usr/local/beepkg && cd "$_"
    2. tar -xvzf *.tar.gz
    3. rm -rf *.tar.gz
  3. Configure service parameters

    1. cat <<'EOF' > /etc/systemd/system/beepkg.service
    2. [Unit]
    3. Description=beepkg
    4. AssertPathExists=/usr/local/beepkg
    5. [Service]
    6. WorkingDirectory=/usr/local/beepkg
    7. ExecStart=/usr/local/beepkg/beepkg
    8. ExecReload=/bin/kill -HUP $MAINPID
    9. LimitNOFILE=65536
    10. Restart=always
    11. RestartSec=5
    12. [Install]
    13. WantedBy=multi-user.target
    14. EOF
  4. Install service

    1. chmod +x beepkg
    2. chmod 644 /etc/systemd/system/beepkg.service
    3. systemctl daemon-reload
    4. systemctl enable beepkg
    5. systemctl start beepkg
    6. systemctl status beepkg