Skip to content
This repository has been archived by the owner on Feb 19, 2019. It is now read-only.

(GH-489) Install-ChocolateyService feature #506

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open

(GH-489) Install-ChocolateyService feature #506

wants to merge 28 commits into from

Conversation

030
Copy link

@030 030 commented Jul 8, 2014

Feature created which is able to create a Windows service by passing packageName, serviceName, createServiceCommand and availablePort (optional).

If the service already exist, this will be stopped and removed before creating the Service.

If the availablePort parameter is passed, a check will be executed whether the port is available or not. If the port is in LISTENING state, a ChocolateyError will be thrown and the installation exits. If no port parameter is passed, no check will be done.

If the createServiceCommand parameter cannot be executed an error will be thrown and the installer exits.

Some code had to be moved to separate functions to avoid code duplication.

10 tests were run. A bat file containing ping localhost was created and run using NSSM to mimic installation and running of a service.

030 added 20 commits July 4, 2014 23:32
… according instructions CONTRIBUTING document
…of 5seconds if it is not able to start the first time to avoid incorrect error
…tart. If optional port is specified then a check is done to see whether port is available. Creation of service mimiced by installing ping localhost bat file using NSSM as service. Test directory cleaned after finishing test
@030
Copy link
Author

030 commented Jul 8, 2014

I misunderstood regarding the documentation. It has been added again.

@030
Copy link
Author

030 commented Jul 8, 2014

Remove-Service has been renamed to Uninstall-ChocolateyService

@030
Copy link
Author

030 commented Jul 8, 2014

Tests have been run again and everything still works.

PS C:\chocolatey-1\tests\unit> C:\Chocolatey\lib\pester.2.0.2\tools\bin\pester.bat .\In
stall-ChocolateyService.Tests.ps1
Executing all tests in C:\chocolatey-1\tests\unit\Install-ChocolateyService.Tests.ps1
Please run chocolatey /? or chocolatey help - chocolatey v0.9.8.24
Describing Install-ChocolateyService
  When provided parameters are correct the service should be created and started
The default install location has been changed to 'C:\ProgramData\chocolatey'.
  This install will be updated to that location in the next version. It
  is strongly suggested you move this installation to the new location
  as soon as possible to limit write access from all users. Do not forget
  to update PATH & ChocolateyInstall environment variables.
Chocolatey (v0.9.8.24) is installing 'NSSM' and dependencies. By installing you accept the license for 'NSSM' and each d
ependency you are installing.
'NSSM 2.21.1.0' already installed.
If you want to reinstall the current version of an existing package, please use the -force command.

Finished installing 'NSSM' and dependencies - if errors not shown in console, none detected. Check log for errors if uns
ure.
C:\installChocolateyServiceTest directory does not exist and will be created


    Directory: C:\


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        07/08/2014     22:12            installChocolateyServiceTest
installServiceTest service will be installed
nssm install installServiceTest "C:\installChocolateyServiceTest\testService.bat"
Service "installServiceTest" installed successfully!
installServiceTest service will be started
installServiceTest service has been started
[+]    service creation should succeed 722ms
[+]    service start should succeed 21ms
  When provided parameters are correct and service exist it should be removed, subsequently created and started
The default install location has been changed to 'C:\ProgramData\chocolatey'.
  This install will be updated to that location in the next version. It
  is strongly suggested you move this installation to the new location
  as soon as possible to limit write access from all users. Do not forget
  to update PATH & ChocolateyInstall environment variables.
Chocolatey (v0.9.8.24) is installing 'NSSM' and dependencies. By installing you accept the license for 'NSSM' and each d
ependency you are installing.
'NSSM 2.21.1.0' already installed.
If you want to reinstall the current version of an existing package, please use the -force command.

Finished installing 'NSSM' and dependencies - if errors not shown in console, none detected. Check log for errors if uns
ure.
installServiceTest service already exists and will be removed

__GENUS          : 2
__CLASS          : __PARAMETERS
__SUPERCLASS     :
__DYNASTY        : __PARAMETERS
__RELPATH        :
__PROPERTY_COUNT : 1
__DERIVATION     : {}
__SERVER         :
__NAMESPACE      :
__PATH           :
ReturnValue      : 0
PSComputerName   :

installServiceTest service will be installed
nssm install installServiceTest "C:\installChocolateyServiceTest\testService.bat"
Service "installServiceTest" installed successfully!
installServiceTest service will be started
installServiceTest service has been started
[+]    service creation should succeed after deletion of previous service 521ms
[+]    service start should succeed after deletion of previous service 6ms
  When availablePort parameter is passed to this function and it is in LISTENING state and not available
The default install location has been changed to 'C:\ProgramData\chocolatey'.
  This install will be updated to that location in the next version. It
  is strongly suggested you move this installation to the new location
  as soon as possible to limit write access from all users. Do not forget
  to update PATH & ChocolateyInstall environment variables.
Chocolatey (v0.9.8.24) is installing 'NSSM' and dependencies. By installing you accept the license for 'NSSM' and each d
ependency you are installing.
'NSSM 2.21.1.0' already installed.
If you want to reinstall the current version of an existing package, please use the -force command.

Finished installing 'NSSM' and dependencies - if errors not shown in console, none detected. Check log for errors if uns
ure.
installServiceTest service already exists and will be removed

__GENUS          : 2
__CLASS          : __PARAMETERS
__SUPERCLASS     :
__DYNASTY        : __PARAMETERS
__RELPATH        :
__PROPERTY_COUNT : 1
__DERIVATION     : {}
__SERVER         :
__NAMESPACE      :
__PATH           :
ReturnValue      : 0
PSComputerName   :

installServiceTest service will be installed
nssm install installServiceTest "C:\installChocolateyServiceTest\testService.bat"
Service "installServiceTest" installed successfully!
135 is in LISTENING state and not available.
[+]    should return an error 256ms
  When no packageName parameter is passed to this function
[+]    should return an error 9ms
  When no serviceName parameter is passed to this function
[+]    should return an error 8ms
  When no createServiceCommand parameter is passed to this function
[+]    should return an error 8ms
  When service does not exist
The default install location has been changed to 'C:\ProgramData\chocolatey'.
  This install will be updated to that location in the next version. It
  is strongly suggested you move this installation to the new location
  as soon as possible to limit write access from all users. Do not forget
  to update PATH & ChocolateyInstall environment variables.
Chocolatey (v0.9.8.24) is installing 'NSSM' and dependencies. By installing you accept the license for 'NSSM' and each d
ependency you are installing.
'NSSM 2.21.1.0' already installed.
If you want to reinstall the current version of an existing package, please use the -force command.

Finished installing 'NSSM' and dependencies - if errors not shown in console, none detected. Check log for errors if uns
ure.
unavailableServiceName service will be installed
nssm install installServiceTest "C:\installChocolateyServiceTest\testService.bat"
Error creating service!
[+]    should return an error 12ms
  When createServiceCommand is incorrect
The default install location has been changed to 'C:\ProgramData\chocolatey'.
  This install will be updated to that location in the next version. It
  is strongly suggested you move this installation to the new location
  as soon as possible to limit write access from all users. Do not forget
  to update PATH & ChocolateyInstall environment variables.
Chocolatey (v0.9.8.24) is installing 'NSSM' and dependencies. By installing you accept the license for 'NSSM' and each d
ependency you are installing.
'NSSM 2.21.1.0' already installed.
If you want to reinstall the current version of an existing package, please use the -force command.

Finished installing 'NSSM' and dependencies - if errors not shown in console, none detected. Check log for errors if uns
ure.
installServiceTest service already exists and will be removed

__GENUS          : 2
__CLASS          : __PARAMETERS
__SUPERCLASS     :
__DYNASTY        : __PARAMETERS
__RELPATH        :
__PROPERTY_COUNT : 1
__DERIVATION     : {}
__SERVER         :
__NAMESPACE      :
__PATH           :
ReturnValue      : 0
PSComputerName   :

installServiceTest service will be installed
unavailableServiceName "C:\installChocolateyServiceTest\testService.bat"
[+]    should return an error 14ms
Remove test directory after finishing testing
Tests completed in 1.58s
Passed: 10 Failed: 0

@030
Copy link
Author

030 commented Jul 8, 2014

At the moment the createServiceCommand needs to be a valid command. I have tried to add more options to this, but the destinction between the services I would like to create using the Install-ChocolateyService is too large, e.g. apacheds (NSSM + two options), dcm4chee (NSSM + 1 option), tomcatzip (native service.bat) and postgresqlzip (native service.bat). Should I add more examples regarding the creation of a service?

@ferventcoder
Copy link
Contributor

@030 Some real live examples would be good.

@030
Copy link
Author

030 commented Jul 14, 2014

@ferventcoder Real live examples have been added

@030
Copy link
Author

030 commented Aug 2, 2014

Could you specify the label? What does 0-triaging mean in this case? Does it mean that this feature will be dropped or implemented soon?

@gep13
Copy link
Member

gep13 commented Aug 3, 2014

In this case, triaging is referring to checking the pull request, for suitability, problems, additional suggestions, etc. This is the first pass at getting the pull request pulled into the main code base of Chocolatey. This is a good thing :-)

You will hear from Rob if there are any changes that need to be made.

@030
Copy link
Author

030 commented Aug 11, 2014

@gep13 Thank you for the explanation

@030
Copy link
Author

030 commented Aug 23, 2014

If no port is specified the service will not be started as TRUE will be returned

@ferventcoder
Copy link
Contributor

I'm still confused what kind of service this is installing. Is this not a Windows Service (most of those do NOT require ports)?

@030
Copy link
Author

030 commented Aug 26, 2014

The port is optional. E.g. PostgreSQL, DCM4CHEE, Tomcat, JBoss require that ports are available. The script installs a Windows service indeed.

@030
Copy link
Author

030 commented Aug 26, 2014

Should Install-ChocolateyService be renamed to Install-WindowsService?

@ferventcoder
Copy link
Contributor

No need, I was trying to understand how port would keep the service from being started if no port is specified when it is optional.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants