DEV Community

Masui Masanori
Masui Masanori

Posted on

1

[Xubuntu] Automatic start-up Go applications and Nginx

Intro

This time, I will try automatic starting-up my Go application and Nginx.

I built my Go application by "go build .".

To start-up automatically, I will add systemd service files.

Go applications

I add a service file into "/etc/systemd/system/".

webappsample.service

[Service]
Type=simple
User=root
ExecStart=/home/example/go/src/sample/webappsample/webappsample
WorkingDirectory=/home/example/go/src/sample/webappsample
Restart=always
RestartSec=30

[Install]
WantedBy = multi-user.target
Enter fullscreen mode Exit fullscreen mode

After adding the file, I register it with systemd.

sudo systemctl enable webappsample.service
Enter fullscreen mode Exit fullscreen mode

Nginx

Nginx service files are almost identical to Go application.

nginx.service

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs