I have one CentOS based Amazon Linux AMI and I was trying to setup custom service, in which a small bash script (which creates a dummy file in a particular location) will be called on boot.
I followed this tutorial https://unix.stackexchange.com/a/20361 and created a custom service script myscript
like below, and copied it into /etc/init.d folder
with 777 permission and root
as the owner;
#!/bin/bash
# chkconfig: 2345 20 80
# description: Description comes here....
Source function library.
. /etc/init.d/functions
start() {
echo -n "Starting myscript... "
su user
touch /data/startfile
return 0
}
stop() {
echo -n "Stopping myscript... "
su user
touch /data/stopfile
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
esac
exit 0
After rebooting the machine, when I checked /data/
directory, I can see two files startfile
as well as stopfile
. If the service is starting automatically, startfile
is expectable, but I wonder about stopfile
. Can somebody please explain why this is happening?
Thanks