How do I get my Golang web server to run in the background?

前端 未结 5 977
我在风中等你
我在风中等你 2020-12-22 22:29

I have recently completed the Wiki web development tutorial (http://golang.org/doc/articles/wiki/). I had tons of fun and I would like to experiment more with the n

5条回答
  •  臣服心动
    2020-12-22 23:07

    This will configure your service using systemd, not a comprehensive tutorial but rather a quick jump-start of how this can be set up.

    Content of your app.service file

    [Unit]  
    Description=deploy-webhook service
    After=network.target
    
    [Service]      
    ExecStart=/usr/bin/go webhook.go    
    WorkingDirectory=/etc/deploy-webhook
    
    User=app-svc      
    Group=app-svc
    
    Restart=always    
    RestartSec=10    
    KillSignal=SIGINT
    
    SyslogIdentifier=deploy-webhook-service      
    PrivateTmp=true  
    
    Environment=APP_PARAM_1=ParamA
    Environment=APP_PARAM_2=ParamB
    
    [Install]      
    WantedBy=multi-user.target  
    

    Starting the Service

    sudo systemctl start deploy-webhook.service
    

    Service Status

    sudo systemctl status deploy-webhook.service
    

    Logs

    journalctl -u deploy-webhook -e
    

提交回复
热议问题