Many times we need to install more than one instance of Jenkins on the same window machine. Along with installation, we need also setup window service so that Jenkins can itself start after the system reboot.
Let suppose you have already one instance of Jenkins is running, now you need to install another for this you need a Jenkins.war to install Jenkins as well java installed on the system.
Start Service:
Run below command. –DJENKINS_HOME is the path of Jenkin_Home where installation file will be install
java -DJENKINS_HOME=/path/to/configs -jar jenkins --httpPort=<port_num>
// java -DJENKINS_HOME=D:/Jenkins -jar jenkins.war --httpPort=8081
Now start you Jenkins with URL http://<hostname>:<your_port>. Let assume http://localhost:8081. It will start as a normal installation. Follow all processes of normal installation. After the installation process completed follow the below steps with the assumption that your port is 8081 and Jenkins_Home is “D:/Jenkins“
sc.exe create <service_name> binpath= "<path_to_jenkins.exe>" displayname= <service_displayname> start=auto
//Example
// sc.exe create jenkins_new binpath= "D:/jenkinsjenkins.exe" displayname= "jenkins_new" start=auto
A space is required between value and equal sign. ex.
binpath= "value"
<service_name>:
Specifies the name given to the Service key in the registry. Note that this is different from the display name (which is what you see with net start command and the Services tool in Control Panel.)
<service_displayname>:
is the label that will identify the service in the service manager interface.
<path_to_jenkins.exe>:
path of jenkins.exe. It is normally exists at JENKINS_HOME path
Run above command cmd (open as administrator). If everything successful 👌 you will see the below message.
![Service installation](https://res.cloudinary.com/dv059kn7m/images/f_webp,q_auto/v1587875781/image-9/image-9.png?_i=AA 1173w, https://res.cloudinary.com/dv059kn7m/images/w_300,h_65,c_scale/f_webp,q_auto/v1587875781/image-9/image-9.png?_i=AA 300w, https://res.cloudinary.com/dv059kn7m/images/w_1024,h_221,c_scale/f_webp,q_auto/v1587875781/image-9/image-9.png?_i=AA 1024w, https://res.cloudinary.com/dv059kn7m/images/w_768,h_166,c_scale/f_webp,q_auto/v1587875781/image-9/image-9.png?_i=AA 768w, https://res.cloudinary.com/dv059kn7m/images/w_278,h_60,c_scale/f_webp,q_auto/v1587875781/image-9/image-9.png?_i=AA 278w, https://res.cloudinary.com/dv059kn7m/images/w_1170,h_253,c_scale/f_webp,q_auto/v1587875781/image-9/image-9.png?_i=AA 1170w)
![](https://res.cloudinary.com/dv059kn7m/images/f_webp,q_auto/v1587876074/image-10/image-10.png?_i=AA 970w, https://res.cloudinary.com/dv059kn7m/images/w_300,h_76,c_scale/f_webp,q_auto/v1587876074/image-10/image-10.png?_i=AA 300w, https://res.cloudinary.com/dv059kn7m/images/w_768,h_195,c_scale/f_webp,q_auto/v1587876074/image-10/image-10.png?_i=AA 768w, https://res.cloudinary.com/dv059kn7m/images/w_237,h_60,c_scale/f_webp,q_auto/v1587876074/image-10/image-10.png?_i=AA 237w)
If service is stopped then you can start from service manager.
Delete service:
You can also delete created service with the below command
sc delete <service_name>
//Example
// sc delete jenkins_new
![Jenkins service delete](https://res.cloudinary.com/dv059kn7m/images/f_webp,q_auto/v1587876136/image-12/image-12.png?_i=AA 606w, https://res.cloudinary.com/dv059kn7m/images/w_300,h_62,c_scale/f_webp,q_auto/v1587876136/image-12/image-12.png?_i=AA 300w, https://res.cloudinary.com/dv059kn7m/images/w_289,h_60,c_scale/f_webp,q_auto/v1587876136/image-12/image-12.png?_i=AA 289w)
Start/Stop/Restart Jenkins:
Open Console/Command line –> Go to your Jenkins installation directory. Execute the following commands respectively:
- To stop:
jenkins.exe stop
- To start:
jenkins.exe start
- To restart:
jenkins.exe restart
To stop Jenkins Please avoid shutting down the Java process or the Windows service. These are not usual commands. Use those only if your Jenkins is causing problems.
Use Jenkins’ way to stop that protects from data loss.
http://[hostname]/[command]
where [command] can be any one of the following:
- exit
- restart
- reload
Example: If my local PC is running Jenkins at port 8080, it will be
http://localhost:8080/restart
Reference: https://stackoverflow.com/questions/14869311/start-stop-and-restart-jenkins-service-on-windows