Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add daemon option for Linux #16

Closed
geerlingguy opened this issue Dec 16, 2014 · 17 comments
Closed

Add daemon option for Linux #16

geerlingguy opened this issue Dec 16, 2014 · 17 comments

Comments

@geerlingguy
Copy link
Contributor

It would be nice to be able to run mailhog as a daemon in Linux. I think the original MailHog had a -daemon option or something like that, but for the current version, the only way to run it in the background is to use nohup or pipe things somehow.

@ian-kent
Copy link
Member

Thanks @geerlingguy

I'm not sure this is really appropriate, but I'm happy to be disagreed with. I personally think this is outside the responsibility of the application layer, and supporting a daemonised mode complicates the application code (forking, monitoring forked processes, etc)

Is there any reason something like upstart, systemd, etc wouldn't work for you?

Or if you don't have root access, something like websysd or an alternative might be suitable?

(p.s., I'm not sure MailHog has ever had a daemon option, but M3MTA did!)

@pedromorgan
Copy link

Mines started with supervisord, daemon would definately be a init.d scripts not in MailHog

@geerlingguy
Copy link
Contributor Author

Looking into it further, I do agree that adding daemonization inside mailhog is probably not the most efficient solution. I went ahead and built an init script to daemonize mailhog for my needs, as part of an Ansible role for MailHog.

@geerlingguy
Copy link
Contributor Author

@ian-kent - Maybe, as an alternative, could you at least point out a preferred way to have people run it as a daemon? It seems like it would be a common use case if people want to use MailHog inside a development VM or something.

@ian-kent
Copy link
Member

Thanks for the init script and Ansible role @geerlingguy. I'll add a deployment guide linking to them.

I don't really have a preferred way, it depends which OS you're using and what works best for you. I think giving some examples (like your init scripts) of how it could be deployed would be better.

It can also be deployed on Elastic Beanstalk (using the example Dockerfile), and should work pretty well on the free tier EC2 instances for limited development work.

@ian-kent
Copy link
Member

There's also some overlap with #10 - that (at a quick glance) seemed fairly unobtrusive... if it can be integrated without causing issues, perhaps that could be a quick solution to daemonising it under linux/windows/mac?

@geerlingguy
Copy link
Contributor Author

Yeah, #10 seems like it would cover this well; I guess the issue title threw me off, since it was only mentioning 'Windows' :)

@ian-kent
Copy link
Member

I'm not sure how portable #10 would really be... it looks portable, but upstart etc support in linux varies a lot (e.g. compare RHEL with Ubuntu!) - at least for Windows its fairly consistent between major OS releases!

@geerlingguy
Copy link
Contributor Author

hah, and then you have systemd in CentOS 7 and Debian 8!!

@pedromorgan
Copy link

Actually thinking about it again, maybe we include an /etc/ directory
with an init.d, supervisor, nginx config et all.. to make it easier for end users..

@ian-kent
Copy link
Member

Just updated the readme and added a deployment guide, let me know if there's anything I've missed!

@ian-kent
Copy link
Member

Actually thinking about it again, maybe we include an /etc/ directory
with an init.d, supervisor, nginx config et all.. to make it easier for end users..

Good idea @pedromorgan! I'll reopen it, PRs welcome if anyone has any examples!

@ian-kent ian-kent reopened this Dec 18, 2014
@pedromorgan
Copy link

Cool, I'll stick in the supervisord config + nginx example .. weekend time as travelling atmo

@ian-kent ian-kent modified the milestone: Go-MailHog v0.09 Dec 21, 2014
@ian-kent
Copy link
Member

ian-kent commented Jan 4, 2015

I'll close this now, but any init script contributions are still welcome 👍

@ian-kent ian-kent closed this as completed Jan 4, 2015
@geerlingguy
Copy link
Contributor Author

Here's the systemd unit file I'm using for mailhog in my Ansible role (just for posterity):

[Unit]
Description=MailHog Email Catcher
After=syslog.target network.target

[Service]
Type=simple
ExecStart={{ mailhog_install_dir }}/mailhog
StandardOutput=journal
Restart=on-failure

[Install]
WantedBy=multi-user.target

See: https://github.com/geerlingguy/ansible-role-mailhog/blob/master/templates/mailhog.unit.j2

@juampynr
Copy link
Contributor

I followed this guide to set up the service in Ubuntu 16. Here are the steps:

  1. Create cat /etc/systemd/system/mailhog.service.
  2. Paste the following in it:
[Unit]
Description=MailHog service

[Service]
ExecStart=/usr/local/bin/mailhog

[Install]
WantedBy=multi-user.target
  1. Start the service: sudo systemctl start mailhog.
  2. Enable the service to run on boot: sudo systemctl enable mailhog
  3. Restart.
  4. Check that the web interface is running by opening http://localhost:8025 in a browser.
  5. Send a dummy email and verify that it shows up at the web interface with the following command:
php -r "\$from = \$to = 'your.emailaddress@gmail.com'; \$x = mail(\$to, 'subject'.time(), 'Hello World', 'From: '. \$from); var_dump(\$x);"

@macau23
Copy link

macau23 commented Mar 4, 2021

Without a daemon option, I cannot check the exit code of MailHog.

If I background it myself, I have to wait a little while then run a health check to know if it is okay.

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

No branches or pull requests

5 participants