S
S
seys2016-08-26 13:53:51
go
seys, 2016-08-26 13:53:51

How to inject golang/beego into autoload (systemd, upstart, supervisor) vps linux?

Hello everyone, tell me who knows. I installed golang, everything works fine and the beego application starts up, I tried to add it to autoload according to various tutorials, including in Japanese, I wrote the following
upstart

description "A stupid golang http listener"

start on filesystem or runlevel [2345]
stop on runlevel [!2345]

setuid www-data
setgid www-data

respawn
respawn limit 5 2

exec /root/home/src/hello/hello

I also tried this
exec ~/home/src/hello/hello
exec go run /root/home/src/hello/main.go
does not start in any way, although just from the console, everything works
in systemd I tried this
[Unit]
Description=Webhook
[Service]
User=deployer
Group=www-data
Restart=on-failure
ExecStart=/root/home/src/hello/hello

[Install]
WantedBy=multi-user.target

in the first and second cases, everything is added well as a service, but errors are written at startup, failure and codes are very memorable, like 207
was not added to the supervisor at all, I wrote like this
[program:yourapp]
command=/root/home/src/hello/hello # the location of your app
autostart=true
autorestart=true
startretries=10
user=yourappuser # the user your app should run as (i.e. *not* root!)
directory=/ root/home/src/hello/ # where your application runs from
environment=APP_SETTINGS="/srv/www/yourapp.com/prod.toml" # environmental variables
redirect_stderr=true
stdout_logfile=/var/log/supervisor/yourapp.log # the name of the log file.
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=10

All the time I thought that it was a matter of memory, although on my openvz 384mb, and beego eats about 20mb, strange somehow, who knows what could be the problem?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
X
xotkot, 2016-08-26
@seys

for systemd
unit:

$ systemctl --user cat test.service

# /home/admin/.config/systemd/user/test.service
[Unit]
After=local-fs.target network.target

[Service]
Type=simple
ExecStart=/home/admin/code/go/bin/test
Restart=on-failure
RestartSec=60
TimeoutSec=60

[Install]
WantedBy=default.target

After - after which services or their groups to run the unit. In this case, start no earlier than the local file system is mounted and the network is available.
RestartSec - how many seconds to wait between unit service restarts (default 100ms).
TimeoutSec - how many seconds to wait for the processing of a start/stop request, after which the process is considered to have ended with an error (the program did not have time to start/stop within the allotted time).
autoload and run:
$ systemctl --user enable test.service
$ systemctl --user start test.service

status:
reloading systemd to look for new or changed units:
done after changing the description of units in the course of their work, this will also be displayed in a message (at the end) when describing the status of the changed service.
restarting the web server (after recompilation):
here test.service (unit service) and test (go webserver) are owned by user admin ( /home/admin/.config/systemd/user/test.service ). In general, who owns and who can work with a unit service , I already wrote in one of the posts .
ps
if the user is on the server, then most likely you will still need to transfer his status to linger, то есть чтобы он всегда подымался при старте системы(как и root):
# loginctl enable-linger <username>

I
i39, 2016-08-28
@i39

Совсем недавно сделал так:
https://elithrar.github.io/article/running-go-appl...

S
seys, 2016-08-27
@seys Автор вопроса

did everything as you wrote, in your case, I got the following message
Failed to get D-Bus connection: Connection refused
I also tried this tutorial
in this case, the console writes the following

[email protected]:/opt# service listener status
● listener.service - Webhook
   Loaded: loaded (/etc/systemd/system/listener.service; enabled)
   Active: failed (Result: start-limit) since Fri 2016-08-26 20:46:12 EDT; 6s ago
  Process: 4536 ExecStart=/opt/listen (code=exited, status=217/USER)
 Main PID: 4536 (code=exited, status=217/USER)

Aug 26 20:46:12 free systemd[1]: Unit listener.service entered failed state.
Aug 26 20:46:12 free systemd[1]: listener.service holdoff time over, sche...t.
Aug 26 20:46:12 free systemd[1]: Stopping Webhook...
Aug 26 20:46:12 free systemd[1]: Starting Webhook...
Aug 26 20:46:12 free systemd[1]: listener.service start request repeated ...t.
Aug 26 20:46:12 free systemd[1]: Failed to start Webhook.
Aug 26 20:46:12 free systemd[1]: Unit listener.service entered failed state.
Hint: Some lines were ellipsized, use -l to show in full.

PS I apparently slept little, but your version works. I pulled out a command from this tutorial that helped me
entered
it and your version loaded. I still have jambs according to the template that has gone, but these are trifles and I will fix everything. Thank you for your help!!! If it weren’t for you, today I would write under node.js
, it’s strange that the second option, which from the example above does not work, writes the same thing,
I still don’t understand what the problem was and how I fixed it, if you can, explain the essence, so that it dawned on me, I don’t want to somehow stupidly copy the code so that it just works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question