Keeping your Linux APM scripts always running(EN)

by Kuba


Posted on Wed Aug 01 14:04:01 GMT 2018


View of Cula
Keeping your Linux APM scripts always running CULA

If you monitor your server resources you would like to be sure that your metrics are always collected. Our APM scripts are designed the way it is the easiest for our users to try it. One just needs to execute the downloaded script and results are immediately present in CULA.
However, simple execution of the script does not guarantee the infinite running (after the system reboot or crash). We decided to write this simple tutorial post in order to help our users who might be not super-familiar with system administration.

Let's start with downloading Cula APM Script. If your server happens not to have any GUI and Browser, you can do this little trick: Just login to CULA and go to your server settings. Then open your browser's developer tools (F12 for most of the modern browsers) and choose the "NETWORK" tab. After that click the "download bash script button". Then you should be able to right-click the request and copy as a bash's CURL command (see the screenshot below). Paste the command and add:

 > cula_script.sh 
(or any other name you'd like to use. Then run:
chmod +x cula_script.sh
in order to make your script executable.

The most popular way of scheduling the task is to use CRON. In order to use Cula APM Script with CRON properly, we will need to make some adjustments.
In CRON, the task is scheduled every some specified time (CRON expression). However, our default Cula APM Script is wrapped in the infinite loop. So let's get rid of it (please notice hashtags (#) which need to be put in front of 4 lines, see screenshot below).

Once it's done, you need to type in console
crontab -e
and press enter, which is going to open the default editor (likely VI). For those who don't know how to VI:
  • Hit ESC
  • Press I (you're now in the insert mode)
  • Type (or paste) */2 * * * * /path/to/script.sh (run every 2 minutes - according to Cula rate-limiting)
  • Hit ESC
  • Type: :wq and hit Enter
That's it! Now your script is going to be executed every two minutes.

Other way of ensuring your script is running after reboot or crash is using the supervisord. This small tool checks if your desired script is up and in the opposite case supervisord starts it.
In order to use supervisor you have to install it using your favourite package manager. You can find a nice tutorial here.
Once the supervisord is installed, we need to configure it to take care of our Cula APM Script. In order to do that, we need to edit supervisord.conf file, usually located somewhere nearby /etc/init.d/supervisord.conf. See the example, basic configuration on the screenshot.
WARNING! The supervisord way should use Cula APM Script WITH loop.

After editing the config file, you need to restart the service:

service supervisord restart
In case of any difficulties, questions, suggestions, do not hestitate to contact us via chat, email or in the comment section below.

Start a free account here or e-mail us at contact@cula.io

Cula, Katowice, Poland