Revision [13259]
This is an old revision of DaemonEinrichtenDebian made by ToBo on 2012-03-17 21:17:59.
Daemon einrichten
Einen neuen Daemon unter Debian einzurichten ist nicht mit einer Zeile getan.
Die erste Voraussetzung ist, es existiert bereits ein Skript wie in dem nachfolgenden Beispiel, welches im Systemhintergrund als "Daemon" laufen soll. Dieses Skript muss eine Endlosschleife enthalten. Auf das Backup-Skript (usbautobackup.sh) wird nicht näher eingegangen.
/home/root/backup/usbautobackup.sh
#!/bin/sh
while [ 1 ]
do
# place your code here
done
while [ 1 ]
do
# place your code here
done
Als zweiten Schritt wird unter /etc/init.d/ ein Start-Skript erstellt, dass beim Wechsel von Runlevel zu Runlevel vom System aufgerufen wird.
/etc/init.d/autobackup
#!/bin/sh
# Andreas Tobola, 2012
# The name of the deamon
DAEMON=autobackup
touch /var/lock/$DAEMON
# Carry out specific functions when asked to by the system
case "$1" in
start)
start-stop-daemon --background --start --pidfile /var/run/$DAEMON.pid --make-pidfile --exec /home/root/backup/usbautobackup.sh
echo "USB bar auto backup daemon started."
;;
stop)
start-stop-daemon --stop --pidfile /var/run/$DAEMON.pid
echo "USB bar auto backup daemon stoped."
;;
*)
echo "Usage: /etc/init.d/$DAEMON {start|stop}"
exit 1
;;
esac
exit 0
# Andreas Tobola, 2012
# The name of the deamon
DAEMON=autobackup
touch /var/lock/$DAEMON
# Carry out specific functions when asked to by the system
case "$1" in
start)
start-stop-daemon --background --start --pidfile /var/run/$DAEMON.pid --make-pidfile --exec /home/root/backup/usbautobackup.sh
echo "USB bar auto backup daemon started."
;;
stop)
start-stop-daemon --stop --pidfile /var/run/$DAEMON.pid
echo "USB bar auto backup daemon stoped."
;;
*)
echo "Usage: /etc/init.d/$DAEMON {start|stop}"
exit 1
;;
esac
exit 0
Geeignete Rechte setzen
chmod 755 /etc/init.d/autobackup
Das Skript zumindest unter dem aktuellen Runlevel verlinken. Mit dem Befehl runlevel, lässt sich herausfinden in welchem Runlevel das System im Normalfall arbeitet. Für Runlevel 2 wechselt man in das Verzeichnis /etc/rc2.d/. Für Runlevel 3 entsprechend /etc/rc3.d/.
cd /etc/rc2.d/
ln -s /etc/init.d/autobackup S80autobackup
ln -s /etc/init.d/autobackup K80autobackup
ln -s /etc/init.d/autobackup S80autobackup
ln -s /etc/init.d/autobackup K80autobackup
Siehe auch