1

Guys, please don't scream at me :D

i need a tool to be installed on ubuntu that check if a specific process is running or not, if not then it starts it automatically

Comments
  • 9
    Systemd.

    in the background:
  • 4
    That's a good need for you to have
  • 0
  • 0
    What about something like ps | grep?
  • 1
    @dIREsTRAITS supervisor is also option. But systemd is fine too
  • 2
    Create a Shell Script:
    For example, you can create a script named check_process.sh with the following content:
    #!/bin/bash
    process_name="your_process_name"

    if ! pgrep -x "$process_name" > /dev/null; then
    echo "$process_name is not running. Starting it now..."
    # Start your process here, for example:
    # /path/to/your/process &
    else
    echo "$process_name is already running."
    fi
    Make the Script Executable:
    chmod +x check_process.sh

    Create a systemd Service Unit:
    Create a file, e.g., check_process.service, in the /etc/systemd/system/ directory:
    [Unit]
    Description=Check and start your process if not running

    [Service]
    ExecStart=/path/to/your/check_process.sh
    Restart=always

    [Install]
    WantedBy=multi-user.target

    Reload systemd

    sudo systemctl daemon-reload

    Start and Enable the Service
    sudo systemctl start check_process
    sudo systemctl enable check_process

    Check the Status:
    sudo systemctl status check_process
  • 0
    Haha, 15 years ago we had this too in my previous company. I think it was called check.sh and did exactly that. :'-D
  • 4
    Here is the site I use to figure out how to do things like this: www.google.com
  • 1
    @helloworld I love when people give real answers instead of forwarding to Google.

    @netikras I called you a nerd but you were really cool
  • 1
  • 2
    @retoor I don't in fact know how to do it at this moment. But a few google searches and I will. Both googling and digesting google information are skills. Better to acquire those skills when people are available than when they are not. If someone posts a "this is what I tried" instead. I will help them with what they posted. But they must make an effort.
  • 3
    @retoor This is a classic example where chatgpt can provide an accurate and well explained solution. Quicker than google and better than stack. That’s all I did. Chatgpt is another tool in your toolbox, you’re a fool if you dismiss it.
  • 1
  • 0
  • 2
    The hate against systemD is IMHO unjustified.
  • 0
    We use Monit (https://mmonit.com/monit/) to restart logstash whenever it goes down
  • 1
    @Demolishun I already searched for this on Google however the reason I'm asking is just to get what other are using and get their approach, to make it simple you have a problem and you asked your friend what should I do? He tells you ask google... you know what google is and you already got your solution but you are just asking to confirm that the solution you got is the best one
  • 0
    @helloworld right, i did that too, chatgpt suggested to use systemd and supervisor
  • 0
    @dIREsTRAITS what did you try?
  • 1
    @Demolishun I already solved it. Thanks for nothing
  • 0
    @dIREsTRAITS that was the intended outcome. Good job.
Add Comment