1

I am using Mongooseim 3.2.0 from the source code on the ubuntu server. Below are concern:

  1. What is the best way to run mongooseim as a service so that it automatically restarts if mongooseim crashes or system restarts?
  2. How to interact via terminal with already running mongooseim instance on the ubuntu server like "mongooseimctl live". My guess is running "mongooseimctl live" will try to create another instance. I just want to see the live logs and interaction and don't want to keep scrolling the long log files for this purpose.

I apologize if the answer to above is obvious but just want to follow the best guidance.

Shubham1164
  • 357
  • 6
  • 16
  • When I try to use "mongooseimctl live" or "mongooseimctl foreground" in the already running mongooseim instance (in sepaarte terminal on same system), I get the following error: Protocol 'inet_tcp': the name mongooseim@localhost seems to be in use by another Erlang node – Shubham1164 Jan 28 '19 at 18:28
  • 1
    BTW, you probably should not use `mongooseim@localhost` for a production deployment. Instead, figure out a domain name for you service, get a DNS, and configure the server to `mongooseim@your.domain.net`. – erszcz Jan 29 '19 at 11:34
  • 3
    "Protocol 'inet_tcp': the name mongooseim@localhost seems to be in use by another Erlang node", while a bit obscure, says it all. The server is already running in the background - it can't be started the second time in parallel. – erszcz Jan 29 '19 at 11:35

1 Answers1

2

mongooseimctl live or mongooseimctl foreground is mostly useful for development or smoke testing a deployment (unless you're running inside a container). For real world use cases you should start the server in the background with mongooseimctl start.

Back to the container - the best approach for containerised applications is to run them in the foreground, therefore in a container startup script use mongooseimctl foreground.

Once the server is running (no matter how it was started) attaching a shell to troubleshoot issues can be done with mongooseimctl debug. This is the command to use when you get the Protocol 'inet_tcp': the name mongooseim@localhost seems to be in use by another Erlang node error. Be careful if it's a production environment - you can easily take the server down with access to this shell.

If you're just interested in watching logs, with no interactive access to the server internals that the shell offers, a simple tail -f /your-configured-mongooseim-log-dir/* should be enough.


Ubuntu nowadays uses systemd for managing its services' lifetimes. A systemd .service file can be found at https://github.com/esl/MongooseIM/blob/master/tools/pkg/platforms/debian_stretch/files/build/mongooseim.service - we use it for packaging into Debian/Ubuntu .deb packages.

erszcz
  • 1,630
  • 10
  • 16
  • Thats all make sense to me. Thanks erszscz, like always :) – Shubham1164 Jan 29 '19 at 11:40
  • I will add "mongooseimctl start" in the bashrc file in ubuntu so that it will start automatically if my server restart for any reason and since currently I am doing development so I will use "mongooseimctl debug" to interact with the logs. – Shubham1164 Jan 29 '19 at 11:43
  • Adding 'mongooseimctl start' to .bashrc or .bash_profile is not the way to go to deploy a production server - for example, it won't be restarted automatically if it crashes. That's what the operating system's init/service/daemon infrastructure is for. Ubuntu used to use Upstart for service management, but AFAIK has switched to Systemd as most other distributions. Look for materials on creating a new systemd service - maybe this one will be useful: https://medium.com/@benmorel/creating-a-linux-service-with-systemd-611b5c8b91d6 – erszcz Jan 30 '19 at 12:27
  • Actually, we build Debian packages of MongooseIM so we have a script to start it as a systemd service. I'll edit the original answer accordingly. Here's the systemd .service file: https://github.com/esl/MongooseIM/blob/master/tools/pkg/platforms/debian_stretch/files/build/mongooseim.service – erszcz Jan 30 '19 at 12:31
  • Ok. I will consider them before deploying to prod. Much appreciated – Shubham1164 Jan 30 '19 at 13:35
  • Hi @erszcz, I am considering your mongooseim.service for PROD but how to copy the mongooseimctl from /home/MyUsername/workspace/MongooseIM/_build/prod/rel/mongooseim/bin/mongooseimctl to /usr/bin/mongooseimctl for ExecStart as shown in https://github.com/esl/MongooseIM/blob/master/tools/pkg/platforms/debian_stretch/files/build/mongooseim.service – Shubham1164 Jul 13 '19 at 14:54
  • Hi @Shubham1164, to install MongooseIM system-wide you should either use a .deb, an .rpm, or deploy a container. To generate a .deb/.rpm please follow https://github.com/esl/MongooseIM/blob/master/tools/pkg/README.md To build a container with your customised system, please use https://github.com/esl/mongooseim-docker While you can run a release build directly from your project directory, it's not as convenient to deploy on multiple target production machines, and it's not really the advised approach. – erszcz Jul 15 '19 at 10:16
  • U r really Awesome – Shubham1164 Jul 15 '19 at 11:14