Skip to content

Keep merbot running

Sahri Riza Umami edited this page Jul 16, 2016 · 8 revisions

merbot is group administration bot. It's have to stays up 24/7 to service the groups, so the wisest way to deploy merbot is to deployed it in to a reliable server. How could we keep keep merbot running even after we logout from the server?

Luckily, merbot have an upstart daemon. So, if your server is Ubuntu or Ubuntu based or whatever distro that support upstart, you can just execute ./merbot upstart.

What if upstart (for whatever reasons) is not possible to be installed in our server? This page will cover how to run merbot and keep it running after we logout of the server.

Run merbot in background

1. nohup

nohup mean no hang up. nohup allows you to run merbot in the background and keep it running by bypasses the signal hang up, making it possible to run merbot in the background even when the terminal is off.

nohup ./merbot &>/dev/null &

/dev/null part is to redirect nohup output to /dev/null, so it wont create nohup.out file.

See: Running Bash Commands in the Background the Right Way [Linux]

2. Terminal Multiplexer

From terminal multiplexer wiki:

A terminal multiplexer is a software application that can be used to multiplex several virtual consoles, allowing a user to access multiple separate login sessions inside a single terminal window, or detach and reattach sessions from a terminal. It is useful for dealing with multiple programs from a command line interface, and for separating programs from the session of the Unix shell that started the program, particularly so a remote process continues running even when the user is disconnected.

There are two major terminal multplexer in GNU/Linux; tmux and screen. The following steps is how to use tmux (partially taken from an Ask Ubuntu page).

  • ssh into the merbot server
  • start tmux by typing tmux into the shell
  • type ./merbot inside the started tmux session
  • leave/detach the tmux session by typing Ctrl+B and then D

You can now safely log off from the merbot server, merbot process will keep running inside tmux. When you come back again and want to check the status of merbot process you can use tmux attach to attach to your tmux session.

If you want to have multiple tmux sessions running side-by-side, you should name each session using Ctrl-B and $. You can get a list of the currently running sessions using tmux list-sessions.

See: Learn tmux in Y minutes

Run merbot as a daemon

upstart

If you use Ubuntu (based), which is use upstart as an event-based init daemon, you can create an upstart script to manage merbot as a daemon.

./merbot upstart

And then, now you can:

  • sudo start merbot to start merbots daemon
  • sudo stop merbot to stop merbots daemon
  • sudo restart merbot to restart merbots daemon
  • sudo status merbot to see merbots daemon status

Run upstart without a password

It's tiresome to type a password everytime we're start/stop/restart/status merbot. It is good practices to passworded sudo, but we know merbot do no harm. So, it would be better if we can issue merbots specific upstart commands without a password.
Here 's how to set passwordless merbots upstart:

  1. Type whoami to find out your username. For example: iza
  2. Type sudo visudo to edit sudoers file
  3. Append these lines at the end of sudoers file:
iza ALL= NOPASSWD: /sbin/start merbot, /sbin/stop merbot, /sbin/restart merbot, /sbin/status merbot
  1. Save the changes (by CTRL+O if nano is the editor).

Now, we can sudo start|stop|status|restart merbot withouth asked for password.