LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-10-2015, 05:31 AM   #1
globaluty
LQ Newbie
 
Registered: Aug 2015
Posts: 4

Rep: Reputation: Disabled
How to start shell script with Mmonit?


Hello everybody!

I want to start and stop processes (gameservers) with shell scripts in Linux (debian) with Monit. I tried with this in config file monitrc:

check process gameserver
start program = "#!/bin/sh /home/user/start.sh"
if cpu > 80 for 2 cycles then alert
if cpu > 95% for 3 cycles then restart

but i received this syntax error:
/etc/monit/monitrc:280: Error: syntax error 'start program = "'

So, I don't know how to make it right, also for the stop program too.

I will be glad if you help me!

Thanks in advance.
 
Old 08-10-2015, 12:39 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
Welcome to linuxQuestions.

#!/bin/sh is a interpreter directive that basically tells the shell what to use to run the program. The #! is causing the error. Does your start.sh script have that is the first line?

start program = "/home/user/start.sh"

You can specify the shell i.e.
start program = "/bin/sh /home/user/start.sh"
 
Old 08-11-2015, 04:08 AM   #3
globaluty
LQ Newbie
 
Registered: Aug 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
I tried with both:

start program = "/home/user/start.sh" and start program = "/bin/sh /home/user/start.sh", but same error. I should notice that the gameserver, which I try to start with Monit, doesn't have a pid file, is this a problem for monit? And NO, in the first line of the start script there is no #!/bin/sh. It start so: ./hlds_run -game cstrike ....

Thanks
 
Old 08-11-2015, 02:56 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
Yes monit requires all programs to have a pid file. Your start.sh script will need to create a pid file. In addition you should use the full path instead of using ./hlds_run... The . is a shortcut for current working directory and only means something if there is a terminal window open. monit does run as root so it should have access to a users home directory but might be better from say putting the script in /usr/local/bin.

https://mmonit.com/wiki/Monit/FAQ
 
Old 08-13-2015, 08:06 AM   #5
globaluty
LQ Newbie
 
Registered: Aug 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
For now my script looks like:

start)
echo "Starting script blah"
echo "/bin/bash /home/dido/56/27050/start.bat"
;;
stop)
echo "Stopping script blah"
echo "kill $(ps aux | grep '[79].124.56.56 -port 27050' | awk '{print $2}')"
;;
*)
echo "Usage: /etc/init.d/blah {start|stop}"
exit 1
;;

and when I type /etc/init.d/blah start/stop, the server start and stop correctly.

In Monit i have this:

check process gameserver with pidfile /home/dido/56/27050/pid.pid
start program = "/bin/sh /home/dido/56/27050/start.bat"
stop program = "/etc/init.d/blah stop"

But when I press Start Service in Monit - nothing happens.
When the server is started and I press Stop Service in Monit - script stops the service correct.

I also tried with:

start program = "/etc/init.d/blah start", but the result is the same.

Where am i wrong? I tried update-rc.d blah defaults, but:

update-rc.d: using dependency based boot sequencing
insserv: warning: script 'blah' missing LSB tags and overrides
insserv: There is a loop between service monit and blah if stopped
insserv: loop involving service blah at depth 2
insserv: loop involving service monit at depth 1
insserv: Stopping blah depends on monit and therefore on system facility `$all' which can not be true!
insserv: exiting now without changing boot order!
update-rc.d: error: insserv rejected the script header

Last edited by globaluty; 08-13-2015 at 08:12 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
start application using shell script Skiltron Linux - Software 2 12-24-2008 12:51 PM
Start csh script in the same shell ? Vilius AIX 1 11-18-2008 09:23 AM
Timed shell script start lpn1160 Linux - General 1 01-05-2006 12:00 AM
Start programs from a shell script paraiso Linux - Newbie 4 04-29-2005 09:41 AM
Shell Script to Start NVU Dooley Linux - Software 5 07-13-2004 07:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration