Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
customiser un service systemd
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index French
View previous topic :: View next topic  
Author Message
bdouxx
Tux's lil' helper
Tux's lil' helper


Joined: 28 Dec 2009
Posts: 117

PostPosted: Mon Jun 27, 2016 7:08 am    Post subject: customiser un service systemd Reply with quote

bonjour

Avec openrc, il y avait le répertoire /etc/conf.d pour pouvoir changer les valeurs sans que cela soit écrasé a chaque mise à jour.
Comment est on censé faire avec systemd?
Actuellement j('ai envie de changer le port de jenkins-bin pour le mettre a 8081, j'y arrive bien en modifiant le fichier /usr/lib/systemd/system/jenkins.service mais je me dis qu'a la prochaine mise a jour cela va être écrasé , et je ne vois pas bien comment faire autrement.

j'aurai bien fait récupérer les info du répertoire conf.d par le service mais cela semble déconseillé.

https://wiki.gentoo.org/wiki/Project:Systemd/conf.d_files
Back to top
View user's profile Send private message
guitou
Guru
Guru


Joined: 02 Oct 2003
Posts: 534
Location: France

PostPosted: Mon Jun 27, 2016 8:25 am    Post subject: Reply with quote

Hello.

La logique Linux voudrait que ca se fasse dans /etc, et dans cette perspective le repertoire /etc/systemd me semble un bon candidat.

++
Gi)
Back to top
View user's profile Send private message
bdouxx
Tux's lil' helper
Tux's lil' helper


Joined: 28 Dec 2009
Posts: 117

PostPosted: Mon Jun 27, 2016 11:22 am    Post subject: Reply with quote

Le problème est que les fichiers présents dans ce répertoire sont normalement créé par la commande "systemctl enable nom_du_service", un lien symbolique est créé vers le fichier de /usr/lib/systemd/system/

Donc si je copie le fichier actuel pour le modifier, il ne me sera jamais proposé de le mettre à jour en cas de nouvelle version.

Si je ne me trompe pas, dans /etc/conf.d/ si une mise à jour est nécessaire, on nous propose quoi faire ( zap, merge ...)
Back to top
View user's profile Send private message
sebB
l33t
l33t


Joined: 02 Mar 2011
Posts: 806
Location: S.O. France

PostPosted: Mon Jun 27, 2016 12:27 pm    Post subject: Reply with quote

Salut,

Regarde si ca peut t'aider.

Quote:
Variable value

However, the above solution doesn't work well when sysadmin is supposed to change the value of the environment variable locally. More specifically, the new value would need to be set every time the unit file is updated.

For this case, an extra file is to be used. How — usually depends on the distribution policy.

One particularly interesting solution is to use /etc/systemd/system/myservice.service.d directory. Unlike other solutions, this directory is supported by systemd itself and therefore comes with no distribution-specific paths.

In this case, you place a file like /etc/systemd/system/myservice.service.d/local.conf that adds the missing parts of unit file:

[Service]
Environment="FOO=bar baz"

Afterwards, systemd merges the two files when starting the service (remember to systemd daemon-reload after changing either of them). And since this path is used directly by systemd, you don't use EnvironmentFile= for this.

If the value is supposed to be changed only on some of the affected systems, you may combine both solutions, providing a default directly in the unit and a local override in the other file.
Back to top
View user's profile Send private message
GentooUser@Clubic
l33t
l33t


Joined: 01 Nov 2004
Posts: 829

PostPosted: Mon Jun 27, 2016 12:38 pm    Post subject: Reply with quote

La "bonne" méthode est de créer un fichier /etc/systemd/system/jenkins.service.d/override.conf qui va contenir un truc du genre :

Code:
[Service]
ExecStart=
ExecStart=/usr/bin/java -Djava.awt.headless=true -DJENKINS_HOME=/var/lib/jenkins/home -jar /opt/jenkins/jenkins.war --daemon --logfile=/var/log/jenkins/jenkins.log --httpPort=8081 --debug=5 --handlerCountMax=100 --handlerCountMaxIdle=20 --accessLoggerClassName=winstone.accesslog.SimpleAccessLogger --simpleAccessLogger.format=combined --simpleAccessLogger.file=/var/log/jenkins/access_log


Note le besoin de vider la variable avant de pouvoir la redéfinir.

Si tu tape systemctl edit jenkins ça va créer le fichier et ouvrir directement un éditeur.

Par contre, si la commande ExecStart change dans le .service original, il faudra mettre à jour ta version.
Back to top
View user's profile Send private message
bdouxx
Tux's lil' helper
Tux's lil' helper


Joined: 28 Dec 2009
Posts: 117

PostPosted: Mon Jun 27, 2016 2:27 pm    Post subject: Reply with quote

nickel, merci

Je vais continuer de lire la doc sur systemd pour voir comment gérer les variables, passer certains arguments dans une variable est lever un bug pour mettre à jour les fichiers de l'ebuild.
Back to top
View user's profile Send private message
Syl20
l33t
l33t


Joined: 04 Aug 2005
Posts: 619
Location: France

PostPosted: Mon Jun 27, 2016 3:52 pm    Post subject: Reply with quote

Pour être sûr de ne pas te tromper sur le chemin et le nom du fichier, penche-toi sur la commande
Code:
# systemctl edit
Back to top
View user's profile Send private message
k-root
Guru
Guru


Joined: 08 Jan 2005
Posts: 428

PostPosted: Mon Jun 27, 2016 6:17 pm    Post subject: Re: customiser un service systemd Reply with quote

bdouxx wrote:
Actuellement j('ai envie de changer le port de jenkins-bin pour le mettre a 8081, j'y arrive bien en modifiant le fichier /usr/lib/systemd/system/jenkins.service mais je me dis qu'a la prochaine mise a jour cela va être écrasé , et je ne vois pas bien comment faire autrement.



Instanced service units -> https://www.freedesktop.org/software/systemd/man/systemd.service.html

exemple : https://fedoramagazine.org/systemd-template-unit-files/

exemple bis avec postgresql et gentoo : https://www.kprod.eu/blog/?p=121
_________________
boozo wrote:
Gentoo, ça mange des ours et baffe des buffles par 37°C avec un bob et des tongs
Back to top
View user's profile Send private message
bdouxx
Tux's lil' helper
Tux's lil' helper


Joined: 28 Dec 2009
Posts: 117

PostPosted: Mon Jun 27, 2016 9:09 pm    Post subject: Reply with quote

merci pour vos éclaircissements.

en me basant sur le fichier jenkins-bin.confd pour faire le fichier jenkins-bin.service, voila ce que j'obtiens.

par contre GentooUser@Clubic, je ne vois trouvé pourquoi il faut vider la variable avant

Code:
[Unit]
Description=Jenkins Daemon

[Service]

# Directory where Jenkins store its configuration and working files (checkouts, build reports, artifacts, ...).
Environment=JENKINS_HOME=/var/lib/jenkins/home

# Options to pass to java when running Jenkins.
Environment=JENKINS_JAVA_OPTIONS=-Djava.awt.headless=true

# Port Jenkins is listening on.
Environment=JENKINS_PORT=8080

# Debug level for logs -- the higher the value, the more verbose. 5 is INFO.
Environment=JENKINS_DEBUG_LEVEL=5

# Maximum number of HTTP worker threads.
Environment=JENKINS_HANDLER_MAX=100

# Maximum number of idle HTTP worker threads.
Environment=JENKINS_HANDLER_IDLE=20

# War File
Environment=JENKINS_WAR=/opt/jenkins/jenkins.war


Type=forking
ExecStart=/usr/bin/java $JENKINS_JAVA_OPTIONS -DJENKINS_HOME=${JENKINS_HOME} -jar ${JENKINS_WAR} --daemon --logfile=/var/log/jenkins/jenkins.log --httpPort=${JENKINS_PORT} --debug=${JENKINS_DEBUG_LEVEL} --handlerCountMax=${JENKINS_HANDLER_MAX} --handlerCountMaxIdle=${JENKINS_HANDLER_IDLE} --accessLoggerClassName=winstone.accesslog.SimpleAccessLogger --simpleAccessLogger.format=combined --simpleAccessLogger.file=/var/log/jenkins/access_log
User=jenkins

[Install]
WantedBy=multi-user.target



mon fichier /etc/systemd/system/jenkins.service.d/override.conf que j'édite via "systemctl edit jenkins.service"
est le suivant :

Code:
[Service]
Environment=JENKINS_PORT=8081


En faisant ainsi, cela fonctionne sur mon ordi, cela vous semble correct ? si oui, je vais déclarer le bug.


Merci encore
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index French All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum