Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8882291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:32:29+00:00 2026-06-14T20:32:29+00:00

I am writing to get some help regarding starting my java programs via Monit.

  • 0

I am writing to get some help regarding starting my java programs via Monit. I have written a start script program.sh. The monit code and the scipt code is given with this posting.

The issue is that I am not able the start and stop the program using the the script file executed via monit. I can monitor the process if I start it using the terminal but I can’t start/stop it with monit. The log from monit says “Failed to start”

However, I can start and stop programs like ssh easliy from monit. The monit runs under sudo and I am running the scripts from an account with administrative privileges.
It will very helpful if someone helps me figure this out
Thanks

monitrc file

#++++++++++#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#Monit settings
set daemon 10 with start delay 2            # check services at 2-minute intervals
set logfile syslog facility log_daemon                      
set logfile /var/log/monit.log
set idfile /var/lib/monit/id
set statefile /var/lib/monit/state
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Mail Server
set mailserver smtp.gmail.com port 587
    username "monit.abc123@gmail.com" password "password"
    using tlsv1 with timeout 30 seconds

set eventqueue
      basedir /var/lib/monit/events # set the base directory where events will be stored
      slots 100                     # optionally limit the queue size


set alert abc123@gmail.com                       # receive all alerts
set alert abc123@gmail.com only on { timeout }   # receive just service-
#                                                # timeout alert
#set alert foo@bar { nonexist, timeout, resource, icmp, connection }
#set alert security@bar on { checksum, permission, uid, gid }
# setup the email for the SMS thing over here.......................
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
set httpd port 2813 and
#     use address localhost  # only accept connection from localhost
     allow localhost        # allow localhost to connect to the server and
     allow 0.0.0.0/0.0.0.0
     allow admin:monit      # require user 'admin' with password 'monit'
#    allow @monit           # allow users of group 'monit' to connect (rw)
#    allow @users readonly  # allow users of group 'users' to connect readonly
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
set mail-format {
    from: monit@$HOST
    subject: Monit Alert --  $EVENT $SERVICE
    message: $EVENT Service $SERVICE
                 Date:        $DATE
                 Action:      $ACTION
                 Host:        $HOST
                 Description: $DESCRIPTION

            Your faithful employee,
            Monit
}
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#***********************************************************************************************
#Computer Resources check
check system myhost.mydomain.tld
    if loadavg (1min) > 4 for 5 cycles then alert
    if loadavg (5min) > 2 for 5 cycles then alert
    if memory usage > 75% for 3 cycles then alert
    if swap usage > 25% for 5 cycles then alert
    if cpu usage (user) > 70% for 5 cycles then alert
    if cpu usage (system) > 70% for 5 cycles then alert
    if cpu usage (wait) > 20% for 5 cycles then alert
#***********************************************************************************************


################################################################################################
#Monitoring SSH Service

check process ssh123 with pidfile /var/run/sshd.pid
start program = "/etc/init.d/ssh start"
stop program = "/etc/init.d/ssh stop"
if cpu > 50% for 5 cycles then alert
if totalmem > 200 MB for 5 cycles then alert
if children > 2 then alert
#if loadavg(5min) greater than 10 for 8 cycles then stop
#if 5 restarts within 5 cycles then timeout

################################################################################################
#Monitoring Prorgam in Java

check process javaprg with pidfile /home/user/Desktop/Binaries/javaprg.pid
start program = "/home/user/Desktop/Binaries/javaprg.sh start"
stop program = "/home/user/Desktop/Binaries/javaprg.sh stop"  
if cpu > 50% for 5 cycles then alert
if totalmem > 1500 MB for 5 cycles then alert
if children > 2 then alert
#if loadavg(5min) greater than 10 for 8 cycles then stop
#if 5 restarts within 5 cycles then timeout

Start/Stop script

#!/bin/bash
 case $1 in
    start)
       echo $$ > javaprg.pid;
       exec /usr/bin/java -jar javaprg.jar
       ;;
     stop) 
       kill $(cat javaprg.pid);
       rm javaprg.pid
       ;;
     *) 
       echo "usage: javaprg {start|stop}" ;;
 esac
 exit 0
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:32:30+00:00Added an answer on June 14, 2026 at 8:32 pm

    You should set absolute path in your start stop script.

    You can try to launch it using a rooted shell sudo -s.

    And you should concider using the /etc/monit/conf.d folder to put your conf files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an R script to get some database data and then do stuff
I need some help with a program that I am writing for my Systems
i need some help writing a for-loop please but i can't get it. i
I am writing some code in which i need to get a line from
I'd like to get into ejb3 to gain some practice in writing for it.
I'm writing a parser for some LISP files. I'm trying to get rid of
im writing a script to get services from local and remote machines. I've had
I'm writing a program where I get information from a page and put it
I need some help writing a MySQL trigger. what i want to do is
I'm writing some lines of code to get acquainted with the basics of Quartz

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.