Deployment: launch hypnotoad on boot

346 views
Skip to first unread message

Gabor Szabo

unread,
Jul 22, 2016, 6:44:57 AM7/22/16
to Mojolicious
Hi,

I am trying to deploy a Mojolicious-based application on an Ubuntu server.
When I launch the application with hypnotoad everything is fine, but I wonder what is the recommended way to make the Hypnotoad server launch when I reboot the Linux box?

I looked at http://mojolicious.org/perldoc/Mojolicious/Guides/Cookbook#DEPLOYMENT but could not find this information.

regards
   Gabor

Luc Didry

unread,
Jul 22, 2016, 7:06:09 AM7/22/16
to mojol...@googlegroups.com, Gabor Szabo
You can find an upstart file for hypnotoad on
https://framagit.org/luc/lufi/blob/master/utilities/lufi_upstart.conf

I use Carton to manage the dependencies, just remove `carton exec` from
the command.

I put some environment variables in /etc/default/lufi (https://framagit.org/luc/lufi/blob/master/utilities/lufi.default), but you can hardcode them.

I provide initV and systemd files too: https://framagit.org/luc/lufi/tree/master/utilities
--
Luc
http://www.fiat-tux.fr/
Internet n'est pas compliqué, Internet est ce que vous en faites.

Jan Henning Thorsen

unread,
Jul 27, 2016, 8:31:37 AM7/27/16
to Mojolicious
I just use cron for starting on boot:

  $ crontab -l
  @reboot /path/to/myserver.sh 1>>/path/to/log/file.log 2>>/path/to/log/file.log

The reason why I have a shell script first is to set up %ENV and friends. If you don't need that, then you can just point directly to the application. I also sometimes add a hack to the shell script to see if a given database is started if the application require that to start up.

So... this is a rather hackish solution for the complicated, but (for me) a very simple solution for the simple cases. I would say using upstart. initv or systemd is a lot cleaner though, but it *might* require more work.

Алексей Орлов

unread,
Jul 29, 2016, 9:49:26 AM7/29/16
to Mojolicious
Hi!

Try this 

https://github.com/kraih/mojo/wiki/Integrating-hypnotoad-with-systemd-and-rsyslog

пятница, 22 июля 2016 г., 13:44:57 UTC+3 пользователь Gabor Szabo написал:

Alexander Karelas

unread,
Jul 29, 2016, 10:26:51 AM7/29/16
to mojol...@googlegroups.com

I use Ubic (you can download a .deb that sets up Ubic on any Ubuntu at: https://launchpad.net/~berekuk/+archive/ubuntu/ubic/+files/ubic_1.52-2_all.deb ) and then this: https://metacpan.org/pod/Ubic::Service::Hypnotoad

--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious...@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

sri

unread,
Jul 30, 2016, 5:15:55 PM7/30/16
to Mojolicious
Mojolicious 7.01 will have better systemd support and we'll add unit file examples to the docs.


--
sebastian

Stefan Adams

unread,
Aug 4, 2016, 7:42:24 PM8/4/16
to mojolicious
I've noticed that sometimes my hypnotoad just dies, no warning.  Is there a supported directive for systemd to allow systemd to auto-restart the service if the process hangs or disappears?

Stefan Adams

unread,
Aug 4, 2016, 7:46:45 PM8/4/16
to mojolicious

On Thu, Aug 4, 2016 at 6:42 PM, Stefan Adams <s103...@gmail.com> wrote:
I've noticed that sometimes my hypnotoad just dies, no warning.

Actually, to be more precise, it's toadfarm.  Not sure what difference that makes (i.e. toadfarm just uses or calls hypnotoad, doesn't it?)

Dan Book

unread,
Aug 4, 2016, 8:41:54 PM8/4/16
to mojol...@googlegroups.com
Systemd has an option for this, see Restart= here https://www.freedesktop.org/software/systemd/man/systemd.service.html

--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscribe@googlegroups.com.

Stefan Adams

unread,
Aug 4, 2016, 8:52:06 PM8/4/16
to mojolicious

On Thu, Aug 4, 2016 at 7:41 PM, Dan Book <gri...@gmail.com> wrote:
Systemd has an option for this, see Restart= here https://www.freedesktop.org/software/systemd/man/systemd.service.html

Thanks, Dan!  I understand that a daemon needs to be written to specifically handle the watchdog ping.

Timeouts include missing the watchdog "keep-alive ping" deadline

Do you know if this is necessary or if the other modes are generally sufficient to ensure that the service restarts when it fails?

Moreover, would building in watchdog support to hypnotoad be a good idea?

First of all, to make software watchdog-supervisable it needs to be patched to send out "I am alive" signals in regular intervals in its event loop. Patching this is relatively easy. First, a daemon needs to read the WATCHDOG_USEC= environment variable. If it is set, it will contain the watchdog interval in usec formatted as ASCII text string, as it is configured for the service. The daemon should then issuesd_notify("WATCHDOG=1") calls every half of that interval. A daemon patched this way should transparently support watchdog functionality by checking whether the environment variable is set and honouring the value it is set to.

Dan Book

unread,
Aug 4, 2016, 9:27:30 PM8/4/16
to mojol...@googlegroups.com
The Watchdog is an optional feature, but if you enable it (with WatchdogSec=), the Restart option will include that condition. Otherwise the on-failure setting is usually sufficient and will restart it when a systemd operation times out or the process exits with a non-zero exit code or is terminated by a signal (e.g. SIGKILL, SIGSEGV). As for supporting it in Hypnotoad itself, it would be difficult to support via a plugin since the manager process (which does not run the IOLoop) would need to be sending the notify. And I'm doubtful if such a systemd-specific feature would be something the team wants to implement in core.

--

Stefan Adams

unread,
Aug 4, 2016, 11:06:44 PM8/4/16
to mojolicious

On Thu, Aug 4, 2016 at 8:27 PM, Dan Book <gri...@gmail.com> wrote:
The Watchdog is an optional feature, but if you enable it (with WatchdogSec=), the Restart option will include that condition. Otherwise the on-failure setting is usually sufficient and will restart it when a systemd operation times out or the process exits with a non-zero exit code or is terminated by a signal (e.g. SIGKILL, SIGSEGV). As for supporting it in Hypnotoad itself, it would be difficult to support via a plugin since the manager process (which does not run the IOLoop) would need to be sending the notify. And I'm doubtful if such a systemd-specific feature would be something the team wants to implement in core.

Great -- thanks again for the insight!  Makes sense about supporting it in core, but just thought I'd start the conversation about it!  :D
Reply all
Reply to author
Forward
0 new messages