If you use System D, add a file like this to /etc/systemd/system/
.
[Unit]
Description=Jenkins slave connection
Wants=network.target
After=network.target
[Service]
ExecStart=java -jar agent.jar -jnlpUrl http://jenkinsurl:port/endpoint.jnlp -secret 4lph4num3r1cs3cr3t -workDir "/base/path/of/your/jenkinsjar"
Restart=always
WorkingDirectory=/base/path/of/your/jenkinsjar
User=my-user
Group=my-group
RestartSec=20s
[Install]
WantedBy=multi-user.target
Alias=jenkins.service
Permissions and ownership of the file may vary based on the service or OS. Long list files in /lib/systemd/system/
to get an idea of what perms you need or want (probably root:root 644
).
Notice the command is the command that Jenkins provides for you when you create an agent jar. Just use that for ExecStart
.
For user
and group
, I use the user that owns the directory where the Jenkins workspace is located. For example, if the Jenkins workspace is in /home/ubuntu
, I specify ubuntu
as user
and group
.
After that...
Prefix these with sudo
if you're not running as root:
Probably a good idea to reload System D: systemctl daemon-reload
.
Start: systemctl start jenkins.service
. Notice this command pertains to the last line of the file Alias
.
Enable it if you want the service to start with your computer: systemctl enable jenkins.service
.
Here are the Git Gists I based my file on:
https://gist.github.com/unakatsuo/d4711f52a0ab0b9bc8010018149a7e84
https://gist.github.com/dragolabs/05dfe1c0899221ce51204dbfe7feecbb
I'm sure there's a lot more that can be done for the service config but in my case, I manage a lot of different servers and just need the thing to start automatically after boot!