Fork me on GitHub
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Janus as a daemon/service

By default, Janus cannot be started as a daemon. In fact, it is currently conceived as a server application that you start normally. That said, there are several reasons why you may not want to keep Janus in the foreground, while still being interested in checking the console to see what's happening.

There are different ways to "daemonize" it and have it run as a service, though. This page tries to summarize a few ways to do so, starting from "dumb" approaches like sending to background and/or using screen/tmux, to more sophisticated approaches involving systemd, upstart and others.

Running in background

The simplest way to run Janus in the background is to just append the & character to the command line. Anyway, this will still "flood" the console with output from Janus. While there are ways to handle it (e.g., as explained here), a nice and easy way to handle this is redirecting the output to a separate file, e.g., a dedicated log:

/opt/janus/bin/janus -d 5 -6 >/path/to/mylogfile 2>&1 &

This is especially useful in case you want to keep a log of what happened when Janus was running, and can also be used as a simple and effective way to watch the console "live" using tail:

tail -f /path/to/mylogfile

Terminal multiplexers

Another easy way to run Janus in the background is using terminal multiplexers like screen or tmux. If you're not familiar with such applications, you can find a quick overview here.

The following is a simple example with screen:

screen -S janus -d -m
screen -r janus -X stuff $'/opt/janus/bin/janus -d 5 -6\n'

This will create a session called "janus" and launch Janus in it with a few command line options (in this case, just the option to enable IPv6 support and set the debug to verbose). Janus will then be running in the background: accessing the console is just a matter of attaching to the "janus" screen:

screen -r janus
[CTRL+A+D to detach again]

Terminal multiplexers usually allow for logging the output to file as well, if you want to keep an history of what happened during the Janus lifetime.

systemd

This section shows how you can add Janus as a daemon to systemd.

[Unit]
Description=Janus WebRTC gateway
After=syslog.target
After=network.target

[Service]
Type=simple
ExecStart=/opt/janus/bin/janus
Restart=on-abnormal

[Install]
WantedBy=multi-user.target
Note
systemd example provided by @saghul

upstart

This section shows how you can add Janus as a daemon to upstart, which is typically available on Ubuntu systems.

description "janus"

start on filesystem or runlevel [2345]
stop on runlevel [!2345]
limit nofile 50000 50000
limit core unlimited unlimited

respawn
respawn limit 10 5

exec /opt/janus/bin/janus
Note
upstart example provided by @ploxiln

Others

TODO.