Jeg skulle installere en Jenkins agent på mit media center og ville gerne have det som en service.
Det var faktisk ikke sådan lige til at lave, men her er en løsning som virker.
Først skal filen /etc/systemd/system/jenkins.service oprettes.
$ vi /etc/systemd/system/jenkins.service
Så skal du skrive dette som startup script. Husk java skal være installeret.
Du skal også rette HOSTNAME til din jenkins hostnavn.
[Unit]
Description=Jenkins Server Daemon
Wants=network-online.target
After=network-online.target
[Service]
User=jenkins
ExecStart=/usr/bin/java -jar /home/jenkins/agent.jar -url http://192.168.0.110:8080/ -secret 19e2417ae9e60b... -name HOSTNAME -webSocket -workDir "/home/jenkins"
#Restart=always
RestartSec=3
Type=forking
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
# systemctl enable jenkins.service
Derefter kan du enable og starte din service med denne kommando.
$ systemctl enable jenkins.service
$ systemctl start jenkins
$ systemctl status jenkins
● jenkins.service - Jenkins Server Daemon
Loaded: loaded (/etc/systemd/system/jenkins.service; enabled; vendor preset: enabled)
Active: activating (start) since Thu 2024-11-21 23:14:01 CET; 1min 4s ago
Cntrl PID: 2185 (java)
Tasks: 45 (limit: 9395)
Memory: 132.4M
CPU: 3.583s
CGroup: /system.slice/jenkins.service
└─2185 /usr/bin/java -jar /home/jenkins/agent.jar -url http://192.168.0.110:8080/ -secret d9e2476270a79a622de0e66c07ae9e60b9befe0b97f221c1d4914b1092657de3 -name mcenter -webSocket -workDir /home/jenkins
Nov 21 23:14:01 mcenter java[2185]: Nov 21, 2024 11:14:01 PM hudson.remoting.Launcher createEngine
Nov 21 23:14:01 mcenter java[2185]: INFO: Setting up agent: mcenter
Nov 21 23:14:01 mcenter java[2185]: Nov 21, 2024 11:14:01 PM hudson.remoting.Engine startEngine
Nov 21 23:14:01 mcenter java[2185]: INFO: Using Remoting version: 3283.v92c105e0f819
Nov 21 23:14:01 mcenter java[2185]: Nov 21, 2024 11:14:01 PM org.jenkinsci.remoting.engine.WorkDirManager initializeWorkDir
Nov 21 23:14:01 mcenter java[2185]: INFO: Using /home/jenkins/remoting as a remoting work directory
Nov 21 23:14:02 mcenter java[2185]: Nov 21, 2024 11:14:02 PM hudson.remoting.Launcher$CuiListener status
Nov 21 23:14:02 mcenter java[2185]: INFO: WebSocket connection open
Nov 21 23:14:02 mcenter java[2185]: Nov 21, 2024 11:14:02 PM hudson.remoting.Launcher$CuiListener status
Nov 21 23:14:02 mcenter java[2185]: INFO: Connected