Hanaa
Hanaa

Reputation: 71

Is there a way to run HashiCorp Vault as a Windows Service?

I currently have vault server set up on my machine. However, I would like it to have an Automatic Startup after my machine is restarted. Essentially, I would want it to automatically run the vault server start up script e.g.:

     vault server -config C:\vault_0.6.2\config.hcl

and to unseal the vault using 3 keys. I have previously used Windows Service Wrapper (winsv) to install Spring Boot Applications as windows services. Would it be possible to use winsv to run vault? or if winsv could be used to execute 2 bat files (one containing vault server and another for vault unseal)? I am using Windows 10.
I appreciate the help, thanks!

Upvotes: 4

Views: 3461

Answers (2)

Instead of a service you can also create a scheduled task running at startup with the system account.

#Start Vault with scheduledtask (powershell)     
$action  = New-ScheduledTaskAction -Execute "$vaultpath\vault.exe" -Argument "server -config=`"$vaultpath\config.hcl`"" 

$trigger = New-ScheduledTaskTrigger -AtStartup  

try{

    $createTask = Register-ScheduledTask -Action $action -Trigger $trigger -TaskName   "Hashicorp_Vault" -Description "Run Hashicorp Vault" -User system -ErrorAction stop

    if($createTask){
        remove-variabel -name createTask
    }

}Catch{

    write-host "[Vault] : The Vault task already exists" -for green

}

https://d2c-it.nl/2019/03/27/hashicorp-vault-on-windows-with-powershell/

Upvotes: 3

Hanaa
Hanaa

Reputation: 71

In case someone attempts this in the future. The solution was to have a service start up the vault server. The service uses ProcessBuilder to run a bat script that contains this:

start /b vault server -config "C:\vault_0.6.2\config.hcl"

Then it uses another ProcessBuilder that runs a second bat script containing: vault unseal %1

,where %1 is a paramter that the service passes.

Upvotes: 3

Related Questions