linux script de démarrage dans systemd
Puis-je faire Cette mise en service ci-dessous, il n'y a pas d'erreurs, montrant une fois exécuté, mais le serveur le script ci-dessous ne fonctionne pas!
ln /lib/systemd/aquarium.service aquarium.service
systemctl daemon-reload
systemctl enable aquarium.service
systemctl start aquarium.service
grâce
aquarium.service:
[Unit]
Description=Start aquarium server
[Service]
WorkingDirectory=/home/root/python/code/aquarium/
ExecStart=/bin/bash server.* start
KillMode=process
[Install]
WantedBy=multi-user.target
ici est la server.sh script
#!/bin/bash
PID=""
function get_pid {
PID=`pidof python ./udpthread.py`
}
function stop {
get_pid
if [ -z $PID ]; then
echo "server is not running."
exit 1
else
echo -n "Stopping server.."
kill -9 $PID
sleep 1
echo ".. Done."
fi
}
function start {
get_pid
if [ -z $PID ]; then
echo "Starting server.."
./udpthread.py &
get_pid
echo "Done. PID=$PID"
else
echo "server is already running, PID=$PID"
fi
}
function restart {
echo "Restarting server.."
get_pid
if [ -z $PID ]; then
start
else
stop
sleep 5
start
fi
}
function status {
get_pid
if [ -z $PID ]; then
echo "Server is not running."
exit 1
else
echo "Server is running, PID=$PID"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
esac
De façon plus détaillée et complète réponse: unix.stackexchange.com/a/47715
OriginalL'auteur Ossama | 2013-02-28
Vous devez vous connecter pour publier un commentaire.
Essayez d'utiliser "Type=fork" et l'utilisation nom complet.
si cela ne fonctionne pas, le post de la sortie de cette commande:
J'ai oublié d'ajouter cette Mar 01 18:18:26 beaglebone (bash)[12545]: Échec à l'étape CHDIR frai /bin/bash": Aucun fichier ou répertoire
hmm, quel système vous utilisez ? Sur ArchLinux ces fichiers sont des liens symboliques:
% ls -l /bin/sh /bin/bash lrwxrwxrwx 1 root root 15 Jan 26 21:19 /bin/bash -> ../usr/bin/bash* lrwxrwxrwx 1 root root 15 Jan 26 21:19 /bin/sh -> ../usr/bin/bash*
Essayez de remplacement de "/bin/bash" avec "/bin/sh", et assurez-vous que les fichiers n'existe à l'aide de "ls-l"Salut, je suis à l'aide d'angstrom sur le beaglebone /bin/sh n'est pas trop de travail!! C'était censé être facile à mettre en place
Essayez, "ExecStart=/bin/sh /home/root/python/code/aquarium/server.sh démarrer"
OriginalL'auteur Victor Aurélio