Home > other >  Auto boot MailHog on Ubuntu 20.04
Auto boot MailHog on Ubuntu 20.04

Time:12-27

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.

CodePudding user response:

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

CodePudding user response:

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
  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/
  • Related