« Linux : Création d'un service systemd » : différence entre les versions
De www.yakakliker.org
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| (4 versions intermédiaires par le même utilisateur non affichées) | |||
| Ligne 31 : | Ligne 31 : | ||
[Install] | [Install] | ||
WantedBy=default.target | WantedBy=default.target | ||
</syntaxhighlight> | |||
=== Créer un service à partir d'un fichier start.sh et stop.sh === | |||
<syntaxhighlight lang="bash"> | |||
[Unit] | |||
Description=Mon Service Personnalisé | |||
After=network.target | |||
[Service] | |||
Type=forking | |||
User=votre_utilisateur | |||
Group=votre_utilisateur | |||
WorkingDirectory=/chemin/vers/dossier/scripts | |||
ExecStart=/chemin/vers/dossier/scripts/start.sh | |||
ExecStop=/chemin/vers/dossier/scripts/stop.sh | |||
Restart=on-failure | |||
[Install] | |||
WantedBy=multi-user.target | |||
</syntaxhighlight> | |||
=== Activer des logs === | |||
<syntaxhighlight lang="bash"> | |||
StandardOutput=append:/home/appli/www/logs/std.log | |||
StandardError=append:/home/appli/www/logs/error.log | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Ligne 50 : | Ligne 76 : | ||
</script> | </script> | ||
</html> | </html> | ||
[[Catégorie:Linux]] | |||
[[Catégorie:Systemd]] | |||
[[Catégorie:Systemctl]] | |||
Dernière version du 7 septembre 2026 à 14:53
sudo /etc/systemd/system/application.service
Exemples
[Unit]
Description=nexus service
After=network.target
[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
User=nexus
Restart=on-abort
[Install]
WantedBy=multi-user.target
[Unit]
Description=Gunicorn instance to serve application
After=network.target
[Service]
User=application
Group=application
WorkingDirectory=/home/application/www/flask
Environment="PATH=/home/application/www/flask"
ExecStart=/home/application/.pyenv/versions/3.9.20/bin/gunicorn -w 4 -c gunicorn_conf.py 'application:app' --bind 127.0.0.1:8000
[Install]
WantedBy=default.target
Créer un service à partir d'un fichier start.sh et stop.sh
[Unit]
Description=Mon Service Personnalisé
After=network.target
[Service]
Type=forking
User=votre_utilisateur
Group=votre_utilisateur
WorkingDirectory=/chemin/vers/dossier/scripts
ExecStart=/chemin/vers/dossier/scripts/start.sh
ExecStop=/chemin/vers/dossier/scripts/stop.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
Activer des logs
StandardOutput=append:/home/appli/www/logs/std.log
StandardError=append:/home/appli/www/logs/error.log