laravelsupervisordubuntu-20.04mailhog

Auto boot MailHog on Ubuntu 20.04


I installed MailHog in my staging environment by following these steps:

  1. sudo apt-get -y install golang-go
  2. go get github.com/mailhog/MailHog

In order to manually start the service I do:

  1. cd ~/go/bin
  2. ./MailHog

Since I'm using Laravel I already have supervisor running for workers. I'm wondering if there is a way to add a new .conf file in order to start MailHog.

I tried to follow how Laravel workers are started, but so far no luck

[program:mailhog]
process_name=%(program_name)s_%(process_num)02d
command=~/go/bin/MailHog
user=ubuntu
stdout_logfile=/var/www/api/storage/logs/mailhog.log

I get mailhog:mailhog_00: ERROR (no such file) when I try to start supervisor.

I need a way to auto boot MailHog, no matter if I need supervisor or via services.

I'll really appreciate it if you can provide the "recipe" for starting MailHog from the supervisor or by using a service.


Solution

  • I figure out how the complete installation/setup should be:

    1. Downloading & installation
    sudo apt-get -y install golang-go
    go get github.com/mailhog/MailHog
    
    1. Copy Mailhog to bin directory
    sudo cp ~/go/bin/MailHog /usr/local/bin/MailHog
    
    1. Create MailHog service
    sudo tee /etc/systemd/system/mailhog.service <<EOL
    [Unit]
    Description=MailHog
    After=network.target
    [Service]
    User=ubuntu 
    ExecStart=/usr/bin/env /usr/local/bin/MailHog > /dev/null 2>&1 &
    [Install]
    WantedBy=multi-user.target
    EOL
    

    Note: Change the User=ubuntu to your username.

    1. Check status service is loaded successfully.
    sudo systemctl status mailhog
    

    Output

    mailhog.service - MailHog
         Loaded: loaded (/etc/systemd/system/mailhog.service; disabled; vendor preset: enabled)
         Active: inactive (dead)
    
    1. Start service
    sudo systemctl enable mailhog
    
    1. Reboot system and visit http://yourdomain.com:8025/