Comment créer un script init sur Ubuntu 14.04
Dans cet article nous vous montrons comment créer un script init sur votre serveur VPS avec le l'OS Ubuntu. Le principe est le même pour d'autres systèmes linux avec quelques exceptions.cd /etc/init.d
vi my_init_script
#! /bin/sh
export PIDFILE=/var/run/my_init_script.pid
##### Check if Pidfile exits ####
if [ -f ${PIDFILE} ]; then
echo "Pidfile already exits (${PIDFILE})"
echo "Please run rm -f ${PIDFILE}"
exit 0
fi
##Get the process number for our pidfile
ps aux | grep -i "/etc/init.d/my_init_script" | grep -v "grep" | head -n 1 | awk '{print $2}' > ${PIDFILE}
case "$1" in
start)
echo "votre code start ici"
;;
stop)
echo "votre code stop ici"
sleep 10
;;
restart)
echo "votre code stop ici"
sleep 20
echo "votre code start ici"
;;
*)
echo "Usage: my_init_script {start|stop|restart}" >&2
if [ -f ${PIDFILE} ]; then
rm -f ${PIDFILE}
fi
exit 3
;;
esac
#remove pidfile
if [ -f ${PIDFILE} ]; then
rm -f ${PIDFILE}
fi
chmod +x my_init_script
bash -n my_init_script
./my_init_script
update-rc.d my_init_script defaults
Laisser un commentaire
Votre adresse de messagerie et numéro de téléphone ne seront pas publiés