I'm using CentOS 7 what my aim is to create a cron for every five seconds but as I researched we can use cron only for a minute so what I am doing now is I have created a shell file.
hit.sh
while sleep 5; do curl http://localhost/test.php; done
but I have hit it manually through right clicking it.
What I want is to create a service for that file so that i can start and stop it automatically.
I found the script to create a service
#!/bin/bash
# chkconfig: 2345 20 80
# description: Description comes here....
# Source function library.
. /etc/init.d/functions
start() {
# code to start app comes here
# example: daemon program_name &
}
stop() {
# code to stop app comes here
# example: killproc program_name
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
# code to check status of app comes here
# example: status program_name
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
esac
exit 0
But I don't know what to write in start or stop methods I tried placing the same content of hit.sh in start(){}
but it gave error for }
in stop method.
systemd
script, thus no suffix is needed. You should be able to run old scripts withsystemd
just fine though. Have you triedsystemctl enable hitservice
? – Dmitry Grigoryev May 05 '17 at 07:35hit.sh > /var/log/hit.log 2>&1 &
? – E.S. Jun 05 '20 at 00:22/etc/systemd/system
and not/etc/init.d/
– MoDzeus Nov 27 '21 at 18:17.service
extension and cannot be started withsystemctl
. – Dmitry Grigoryev Nov 29 '21 at 10:14