By default Monika will run in the foreground. Like other Node.js applications, there are several ways to run Monika in the background on Unix, Linux, and macOS.
Refer to the Run in Docker documentation page.
npm install -g pm2to install PM2
pm2 start monika -- -c <your_full_path_to_the_monika.yml>to start Monika using PM2
If you want to add more Monika parameters such as
--prometheus, add it after the double dashes. But if you want to add more PM2 parameters such as
-i max, add it before the double dashes.
Refer to the PM2 Official Documentation for all available PM2 parameters.
On your terminal, run
nohup monika &
You'll get an output similar to the following.
 93457appending output to nohup.out
In the above example, 93457 is the process ID (pid). And the output of Monika is written to
To stop Monika, run
kill -9 <pid>.
On Debian/Ubuntu, you can install it by running
sudo apt install screen.
monika -c monika.yaml
Press Ctrl+a then D. This will cause Monika to run on a different screen in the background.
To go back to the screen, run
screen -ls to list the running screens. You will get an output similar to the following.
There is a screen on:9049.pts-0.the-server (03/23/21 08:34:38) (Detached)1 Socket in /run/screen/S-server.
9049.pts-0.the-server is the name of the screen.
screen -r <name_of_the_screen>.
To stop Monika, hit CTRL+C and then CTRL+D to exit/terminate Screen.
To use the systemd service unit, you need to locate the Monika binary. For example, if you installed Monika using NPM, run which monika to know where is your Monika located. e.g
/home/hyperjump/.nvm/versions/node/v14.17.6/bin/monikais the full path to Monika binary file
/home/hyperjump/.nvm/versions/node/v14.17.6/bin/is the full path to Monika binary directory
Create a new file and copy the contents below into the file:
[Unit]Description=Monika[Service]ExecStart=/bin/sh -c '<full_path_to_your_monika_binary_file> -c <full_path_to_your_monika.yml>'Restart=on-failureUser=<your_user>Group=<your_group>WorkingDirectory=<full_path_to_your_monika_binary_directory>[Install]WantedBy=multi-user.target
Replace the values to the correct values and save the file as
Adjust the service file permissions to 644 by running
sudo chmod 644 monika.service
monika.service file to
/etc/systemd/system/ folder by running
sudo cp monika.service /etc/systemd/system/monika.service
Reload the daemon server by running
sudo systemctl daemon-reload
Start Monika service by running
sudo systemctl restart monika.service
To confirm that Monika is working flawlessly, run
sudo systemctl status monika.service in your terminal.
PT Artha Rajamas Mandiri (Hyperjump) is an open-source-first company providing engineering excellence service. We aim to build and commercialize open-source tools to help companies streamline, simplify, and secure the most important aspects of its modern DevOps practices.
Copyright © 2023 Hyperjump Tech. All Rights Reserved.