Reputation: 465
I have to call a perl program in start/stop script. I have my perl program in path/to/program: /home/nuthan/server. Now, my task is to create a start/stop script. i.e., need to call command daemon -d -v -r perl /home/nuthan/server -l /tmp/k on start and kill the pid on stop. I found too many scripts on net, i found this at http://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html. but I don't understand this, as I am new to Perl. Please help, where do i add the commands, or Am i wrong?
#!/bin/bash
# description: Foo server
# Get function from functions library
. /etc/init.d/functions
# Start the service FOO
start() {
initlog -c "echo -n Starting FOO server: "
/path/to/FOO &
### Create the lock file ###
touch /var/lock/subsys/FOO
success $"FOO server startup"
echo
}
# Restart the service FOO
stop() {
initlog -c "echo -n Stopping FOO server: "
killproc FOO
### Now, delete the lock file ###
rm -f /var/lock/subsys/FOO
echo
}
### main logic ###
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status FOO
;;
restart|reload|condrestart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
Upvotes: 1
Views: 11479
Reputation: 38265
This is where you'd need to put the daemon
command in the start function
.
start() {
initlog -c "echo -n Starting FOO server: "
daemon -d -v -r perl /home/nuthan/server -l /tmp/k
### Create the lock file ###
touch /var/lock/subsys/FOO
success $"FOO server startup"
echo
}
Generally init.d
scripts should record the pid and killproc
should know where to find the pid.
However there are so many ways that this could not work as expected, you'll be learning a lot about unix, perl and init.d scripts fixing it.
Upvotes: 2