How I should run my Golang process in background?

后端 未结 5 984
小蘑菇
小蘑菇 2021-01-30 12:19

This question is not strictly programming related, but for sure important for programmers.

I wrote a simple smtp server, when I run it from console all is fine, except i

5条回答
  •  囚心锁ツ
    2021-01-30 12:43

    As Nick mentioned Supervisord is a great option that has also worked well in my experience.

    Nick mentioned problems with forking- forking itself works fine AFAICT. The issue is not forking but dropping privileges. Due to the way the Go runtime starts the thread pool that goroutines are multiplexed over (when GOMAXPROX > 1), the setuid systemcall is not a reliable way to drop permissions.

    Instead, you should run your program as a non-privileged user and use the setcap utility to grant it the needed permissions.

    For example, to allow binding to a low port number (like 80) run will need to run setcap once on the executable: sudo setcap 'cap_net_bind_service=+ep' /opt/yourGoBinary

    You may need to install setcap: sudo aptitude install libcap2-bin

提交回复
热议问题