-3

I have to run a C program using monit. so I had to demonize it. what i did was i took a daemon template made some changes and arrived at this file as below, which is a script file:

# Source function library
. /home/stallions/queue.c

# Do preliminary checks here, if any
#### START of preliminary checks #########


##### END of preliminary checks #######

# Handle manual control parameters like start, stop, status, restart, etc.

case "$1" in
  start)
    # Start daemons.

    echo -n $"Starting queue daemon: "
    echo
    daemon queue
    echo
    ;;

  stop)
    # Stop daemons.
    echo -n $"Shutting down queue: "
    killproc queue
    echo

    # Do clean-up works here like removing pid files from /var/run, etc.
    ;;
  status)
    status queue

    ;;
  restart)
    $0 stop
    $0 start
    ;;

  *)
    echo $"Usage: $0 {start|stop|status|restart}"
    exit 1
esac

exit 0

when i execute this file # ./queue i get errors

         # line 8: 'void fifoinit(int size)'
         # line 8: syntax error near unexpected token

I am not sure what should be the source function library path. I have given it the path where my original queue.c exits which i wanted to run it as a daemon. Can you ell me should there be anything else to be done to run this as a daemon and how to correct the errors?

HopelessN00b
  • 53,795
  • 33
  • 135
  • 209
  • 1
    You obviously don't have a bit of a clue what you are doing. `.c` files have to be compiled, they can't be sourced into a bash script. – Sven May 07 '12 at 14:25
  • I actually have to run them using monit...so when i asked it yesterday here all replied that i have to demonize it so that i could run it. so thats what I did....so how do i run them using monit then? – Wings of anarchy May 07 '12 at 14:27
  • You have to learn so much I don't even know where to begin with. You write a program in C, compile it and then you can use a script like the one you copied here to demonize it, or you can let the C program handle that itself and you use this script to start/stop the demon. This is all way off-topic here. – Sven May 07 '12 at 14:30
  • I am sorry if its off topic, but i really need to know i have a project deadline tomorrow. I will tell you what I did clearly. – Wings of anarchy May 07 '12 at 14:32
  • 3
    Then you are not qualified for this project and should hand it over to someone who is. I am sorry, but you are lacking so much that we just can't fix this on a site like [SF]. – Sven May 07 '12 at 14:33
  • Pastebin the code for queue.c – Tom O'Connor May 07 '12 at 14:36
  • I am sorry if its off topic, but i really need to know i have a project deadline tomorrow. I will tell you what I did clearly. 1. First I wrote a simple C program in VI and then I compiled it using gcc and got the output. 2. Next I wanted to run it using monit so I had to give a path in monit control file for this C program which i gave it as below: check process queue.c matching "queue.c" start program = "/home/stallions/queue.c" stop program = "killall queue.c" 3. Then what I did was went to the init.d location and created the file above mentioned in the question. This is where i ended up – Wings of anarchy May 07 '12 at 14:38
  • @balu, you're missing the point. C programs must be compiled before they can be run. You'd need to compile it to a binary file with gcc first, then execute the binary file with monit. use www.pastebin.com and show us the content of queue.c – Tom O'Connor May 07 '12 at 14:46
  • Yes I have pasted it in pastebin.com done it. I did compile the file using gcc and got the file a.out – Wings of anarchy May 07 '12 at 14:48
  • You should probably take a look at man monit. It's said, monit -d to demonize it. So, basically, you just have to: 1°/- Compile your C program, we will call it queue <-- BINARY AND NOT queue.c 2°/- Take a look at man monit to be able to understand how it work. 3°/- Write a bash script which will simply call monit with the correct parameters, so in your case, it should be something like: monit -d -c "/somewhere/MyControlFile" monitor all 4°/- configure your init script to launch at the correct level. – Dr I May 07 '12 at 14:54
  • Right.. You've pastebinned it, but you've failed to paste a link to the pastebin into the comments here.. You sir, are an idiot. – Tom O'Connor May 07 '12 at 14:58
  • its just with the name queue anyways: http://pastebin.com/mb2rH6tV – Wings of anarchy May 07 '12 at 15:03
  • Even if you did get it to execute through Monit, it'd more than likely fail because your application needs an interactive console. You've got `sscanf` calls for user input. You can't run a daemon with user input. – Tom O'Connor May 07 '12 at 15:22
  • What the hell was this written for? Just *why*? If I wanted a queue in my application, i'd use ZeroMQ, or RabbitMQ, or someone elses known-good working code. – Tom O'Connor May 07 '12 at 15:22
  • Actually, I'd be surprised if this even compiled, and didn't leak memory or segfault. – Tom O'Connor May 07 '12 at 15:23
  • @TomO'Connor the program queue.c is just an example program. that is not what i need....i need to run a c program in monit. Let it be just a simple hello world program.....and it did get executed with an output also. *all i need is run some processes using monit* – Wings of anarchy May 07 '12 at 15:29
  • So why complicate the issue with your inability to write C? A list of Monit configuration examples can be found here. http://mmonit.com/wiki/Monit/ConfigurationExamples – Tom O'Connor May 07 '12 at 15:31

1 Answers1

3

You need first to compile your C program. The following command can do it if your program does not depend on any library to be linked with:

$ gcc -o queue queue.c

This will produce the binary queue if it goes well. It seems your script is trying to execute this binary. You need just to make sure to set the correct path.

Don't source the C program into your shell script. Remove the line:

. /home/stallions/queue.c
Khaled
  • 36,533
  • 8
  • 72
  • 99