Lost_ego has asked for the wisdom of the Perl Monks concerning the following question:

I need to write a program that can be called like a process. The program is going to automate some other perl scripts. I need to incorporate a Start, Stop, and Status. Therefore when you execute "perl program_name start" it starts and returns the command prompt. Likewise "perl program_name stop" stops the program and "perl program_name status" returns the state of the program. I have thought about using touch files but it just seems very .... Uneducated. Any ideas or questions?

Replies are listed 'Best First'.
Re: Parent Program
by Mr_Person (Hermit) on Jun 10, 2003 at 20:36 UTC

    For control, I'd use a shell script seperate from the Perl program, probably one that uses the standard start-stop-daemon command. You can look at how the other processes on your computer are started and copy off of them, or most distributions have a "skeleton" init script to build new init scripts from. In Debian, that's located at /etc/init.d/skeleton.

    After that, you still need a way to have the Perl program become a daemon (detach from the console) and write a PID file so start-stop-daemon can check to see if it's already running before starting it. There are many CPAN modules for this, one that does both is Net::Server::Daemonize, or you could use a combination of Proc::Daemon and Proc::PID::File or similar.

Re: Parent Program
by Jenda (Abbot) on Jun 10, 2003 at 23:05 UTC

    <murmuring>Why do people always forget to specify the operating system?</murmuring>

    Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature

      Sorry about dropping off the OS's. I will run this script on AIX5, HP11, and Sun. just be happy I was able to drop DEC off of the list.