3

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.

Luciano
  • 2,052
  • 1
  • 16
  • 26

2 Answers2

15

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/
lepsch
  • 8,927
  • 5
  • 24
  • 44
Luciano
  • 2,052
  • 1
  • 16
  • 26
  • did all the steps, all good, mailhog runs, however, visiting :8025 does not work, never loading – Vladd Jan 23 '23 at 08:02
0

You don't need a supervisor, you can use Linux systemd to create a startup application.

systemd is the standard system and service manager in modern Linux. It is responsible for executing and managing programs during Linux startup

before that add mailhog to your system path variable to call it only by name

export PATH=$PATH:/home/YOUR-USERNAME/go/bin/MailHog

sudo systemctl enable mailhog

or if you are using any desktop environment , you can follow this https://askubuntu.com/questions/48321/how-do-i-start-applications-automatically-on-login

Tipu Sultan Eiko
  • 677
  • 4
  • 10
  • sudo systemctl enable mailhog Failed to enable unit: Unit file mailhog.service does not exist. – Vladd Jan 23 '23 at 07:57