Skip to content

Instantly share code, notes, and snippets.

@dbrownidau
Last active July 8, 2019 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbrownidau/c3b2f26a0e3adf3a00474be6391a112e to your computer and use it in GitHub Desktop.
Save dbrownidau/c3b2f26a0e3adf3a00474be6391a112e to your computer and use it in GitHub Desktop.
MailHog Standalone Installation / Systemd service script
# -r, --system create a system account
# -m, --create-home create the user's home directory (by default no home created for system accounts)
# -s, --shell SHELL login shell of the new account (Do system accounts get nologin by default anyway?)
sudo useradd -r -m -s /usr/sbin/nologin mailhog
# https://github.com/mailhog/MailHog/releases
wget https://github.com/mailhog/MailHog/releases/download/v1.0.0/MailHog_linux_amd64 -O /home/mailhog/MailHog_linux_amd64
# make exec.
# I like to keep the binary non-writeable by the executing user.
chmod +x /home/mailhog/MailHog_linux_amd64
# Optional, lets this specific binary listen to privilaged ports (ie 25) while running as an un-privilaged user.
setcap CAP_NET_BIND_SERVICE=+eip /home/mailhog/MailHog_linux_amd64
# create systemd service file
echo "[Unit]
Description=MailHog Email Catcher
After=syslog.target network.target
[Service]
User=mailhog
Group=mailhog
Environment=MH_API_BIND_ADDR=0.0.0.0:80
Environment=MH_UI_BIND_ADDR=0.0.0.0:80
Environment=MH_SMTP_BIND_ADDR=0.0.0.0:25
Type=simple
ExecStart=/home/mailhog/MailHog_linux_amd64
StandardOutput=journal
Restart=on-failure
[Install]
WantedBy=multi-user.target" > /etc/systemd/system/mailhog.service
# enable and start the service
systemctl enable mailhog
systemctl start mailhog
@dbrownidau
Copy link
Author

dbrownidau commented Jul 8, 2019

yeet

root@mailhog:~# ps -auxf
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
mailhog    563  0.0  0.7  10588  7624 ?        Ssl  16:16   0:00 /home/mailhog/MailHog_linux_amd64
root@mailhog:~# ss -tulpn
Netid  State   Recv-Q  Send-Q   Local Address:Port   Peer Address:Port
tcp    LISTEN  0       128                  *:25                *:*      users:(("MailHog_linux_a",pid=682,fd=3))
tcp    LISTEN  0       128                  *:80                *:*      users:(("MailHog_linux_a",pid=682,fd=5))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment