DEV Community

jdrch
jdrch

Posted on

How to set up Stash as a Windows service

Note

There are quite a few packages out there called Stash. This guide is for this Stash.

Stash is provided as a standalone executable. Here's how to turn it into a Windows service that launches automatically when you login to Windows (and possibly before?)

Step 1: Download Stash

Download the latest stash-win.exe to C:\Program Files\stash. You can use other locations, but that one gives the executable max protection from non-admin actions.

As Windows generally doesn't give browsers access to Program Files, you'll likely have to download Stash to an intermediate folder and then use a file manager to move it to its final destination.

Step 2: Install Servy

I suggest using the non-net installer.

Step 3: Perform initial Stash service setup

Launch Servy.

Go to the Main tab. Technically, the only things you need to fill out here are Service Name * and Process Path *. Personally, I suggest using explicit Service Name *, Display Name, and Service Description inputs so you can remember exactly what the service does later on and don't delete or edit it by mistake. All those fields accept any value except for Process Path, which is stash-win.exe's final destination in Step 1.

Stash will run just fine with those settings, but it will also run as SYSTEM (highest Windows permissions), which is unsafe if the app becomes compromised. Click the Log On tab and enable the User Account radio button. In the corresponding field, enter your Windows username as described, then enter your Windows password in Password and Confirm Password.

Step 4: Grant %ProgramData%\Servy permissions to your Windows user account

In File Explorer, enter %ProgramData% in the address bar and hit Enter. Find the Servy folder and right-click it. Click Properties -> Security -> Edit.... In the Permissions for Servy window that pops up, click Add.... In the window that pops up, enter your Windows username in the Enter the object names to select (examples): field. Click OK. This will add your Windows user account to the Group or user names list in the Permissions for Servy window. Highlight your user account and ensure Read & execute, List folder contents, Read, and Write are selected in the Allow column. Click Apply and OK and then OK to exit the Servy Properties window.

Step 5: Finalize Stash service setup

Switch back to the Servy window. Click Install and wait for confirmation that that is complete

Step 6: Check that the service installed correctly

Open Windows Services via Start -> type services -> click on the Services System result with the gears icon. In the window that pops up, look for an entry matching what you set up Step 3. Click on it and then click Start on the left. Wait for the service to start, then go to http://localhost:9999 in a web browser. The Stash UI should show up.

If you make a mistake and need to start over again, open an elevated PowerShell prompt: Start -> type PowerShell -> select the latest version -> Click Run as administrator.

In the window that pops up, run

Remove-Service -Name "ServiceNameYouChoseInStep3"
Enter fullscreen mode Exit fullscreen mode

This will delete the service from Windows so you can start all over again.

Credits

Thanks zimanninetynine for the initial setup instructions!

Top comments (0)