Entry
How can I make Linux programs stop, start & restart from a Perl script?
Sep 4th, 2003 22:31
Colin Thomsen, Don Bledsoe,
If the program you want to stop/start/restart is a daemon which is
correctly installed in /etc/init.d, this is a simple process. For the
example of the Apache web server, there would be a file in /etc/init.d
called httpd.
In your Perl script, you could enter:
`/etc/init.d/httpd stop`
or
`/etc/init.d/httpd restart`
or
`/etc/init.d/httpd start`
Alternatively, most Linux distribs provide a command called 'service'
which makes it even easier:
`service httpd start`
Note the special 'backtics' in the lines above, which tell Perl to
execute the command. You can also execute commands using the 'system'
keyword.
If you want to stop an arbitrary Linux program, you will need to use
some special techniques, like:
- run ps and grep it to find the process id of the program you wish to
stop
- run kill with the process ID.
If you just want to start an arbitrary Linux program, you just need
the path to the program and you run it as follows:
`/usr/bin/ls`
The above example runs ls.