docker stop command send SIGTERM to pid1 inside the container to let a chance to stop gracefully (https://www.ctl.io/developers/blog/post/gracefully-stopping-docker-containers/)
Unfortunatly some software ignore SIGTERM and need to be stopped by their own command (hello opendj)
To do so, in the Dockerfile, in the CMD, I use a script like this :
/thecommand/tostart/thesoftware/inbackground
trap "/thecommand/tostop/thesoftware" SIGTERM
while true; do sleep 1; done
so my script is run with PID1, docker stop sends SIGTERM, my script catch (trap) the signal, and run the command to stop gracefully
à mettre dans son bashrc
showOriginal() {
packageName=$(dpkg -S $1|cut -d':' -f1)
tmpdir="/tmp/showOriginal-$packageName-$(date +%s)"
mkdir $tmpdir
cd $tmpir
apt-get download $packageName > /dev/null
dpkg -x *.deb $tmpdir
cat ${tmpdir}$1
cd - >/dev/null
rm -rf $tmpdir
}
Comment créer un script d'init pour une application java.
EDIT : ce truc n'a pas marché pour moi :
s=ps -C 'java -jar /path/to/application.jar' -o pid h
Du coup, j'ai remplacé par :
s=$(pgrep --full 'une string unique qui identifie la command line pour lancer mon jar')
#
#
#
check_status() {
s=ps -C 'java -jar /path/to/application.jar' -o pid h
if [ $s ] ; then
return $s
fi
return 0
}
start() {
check_status
pid=$?
if [ $pid -ne 0 ] ; then
echo "The application is already started"
exit 1
fi
echo -n "Starting application: "
java -jar /path/to/application.jar >> /path/to/logfile 2>&1 &
echo "OK"
}
stop() {
check_status
pid=$?
if [ $pid -eq 0 ] ; then
echo "Application is already stopped"
exit 1
fi
echo -n "Stopping application: "
kill -9 $pid &
echo "OK"
}
status() {
check_status
if [ $? -ne 0 ] ; then
echo "Application is started"
else
echo "Application is stopped"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart|reload)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
Je me garde ça au chaud, ça peut servir
Script pour backup toutes ses bases dans des fichiers séparés
Un wiki complet à lire sur quelques outils en bash
xargs sed cut awk grep find while for