# Design Draft: Windows Installer

**URL:** <https://forum.storj.io/t/design-draft-windows-installer/1128>\
**Category:** design draft\
**Tags:** storagenode, windows\
**Created:** [August 14, 2019, 4:14pm UTC](https://forum.storj.io/t/design-draft-windows-installer/1128 "2019-08-14T16:14:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aleitner](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/aleitner/32/69_2.png) [@aleitner](https://forum.storj.io/u/aleitner)\
**Post date:** [August 14, 2019, 4:14pm UTC](https://forum.storj.io/t/design-draft-windows-installer/1128/1 "2019-08-14T16:14:11Z")

</div>

# Storage Node Installer for Windows

## Abstract

This design doc outlines how we setup Storage Node on Windows.

## Background

Currently we are using Docker to maintain Storage Nodes.  
Unfortunately Docker is not supported for Windows Home, which is popular OS among Storage Node Operators.  
Similarly, Docker ends up using more resources than running natively on Windows.

Therefore, it would be nice to be able to run Storage Node without Docker.

For an easy setup process we would need an installer that:

1. Sets up Storage Node to run in background,
2. sets up automatic updates and
3. ensures we log everything properly.

We need to take care that we:

- avoid triggering UAC unnecessarily,
- start storage node before logging in and
- restart on crashes.

## Design

The high-level idea is to create an installer using WIX and make Storage Node a Windows service.

### Installer

For creating an installer we can use WIX Toolkit.  
There is [go-msi](https://github.com/mh-cbon/go-msi), which helps to get us setup the basic template.  
We also need to ensure that we supply all the Operator information during installation.

To make the installer work we need to:

- Install [go-msi](https://github.com/mh-cbon/go-msi) on the build server.
- Create a wix.json file like [this one](https://github.com/mh-cbon/go-msi/blob/7f05345d485bba45400e3d82d46eaa067b47d652/wix.json)
- Add a guid with `go-msi set-guid` to uniquely identify the process.
- The wix.json should contain steps for:
  - adding Dashboard shortcut to the desktop
  - setting service recovery properties.
  - configuring Storage Node Operator information:
    - Wallet Address
    - Email
    - Address/ Port
    - Bandwidth
    - Storge
    - Identity directory
    - Storge Directory

  - install storagenode binary
  - register storagenode as a service
  - adding Storage Node binary to Windows UserPath (optional)
  - open Dashboard at the end of the installer.

- Finally run `go-msi make --msi your_program.msi --version 0.0.2` to create the installer.

### Service

We need to Storage Node to implement Windows service API, as shown in:

- Modify storage node/automatic updater startup code to implement [ServiceMain](https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nc-winsvc-lpservice_main_functiona).
  - See [golang/sys](https://github.com/golang/sys/blob/fde4db37ae7ad8191b03d30d27f258b5291ae4e3/windows/svc/example/service.go)

- Create inbound firewall rule using the following Powershell command: `New-NetFirewallRule -DisplayName "Storj v3" -Direction Inbound –Protocol TCP –LocalPort 28967 -Action allow`

This means that Windows handles starting and restarting the binary in the background.

## Implementation

1. Modify the storage node startup to implement ServiceMain so that the binary is considered a Windows Service.
2. Create script for registering binary as a Windows Background Service. (sc.exc command)
3. Create wix.json file for building an MSI.
4. Update the build process to include the creation of the MSI.
5. Ensure the windows installer is working properly

- Install Storage Node using msi.
- Ensure binaries run on Windows startup, and it runs as a background process when not logged in.
- Ensure UAC(s) is not triggered after installation.
- Ensure that storage node restarts automatically after a crash

## Open Issues/ Comments (if applicable)

- Consider writing an uninstaller.
- How do we prevent UAC from triggering?
- Consider using wix without go-msi.
- We need to sign both the binaries and the installer, make sure its done for the MSI.

---

<div class="post-metadata">

**Author:** ![Odmin](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/odmin/32/92_2.png) [@Odmin](https://forum.storj.io/u/Odmin)\
**Post date:** [August 14, 2019, 4:55pm UTC](https://forum.storj.io/t/design-draft-windows-installer/1128/2 "2019-08-14T16:55:22Z")

</div>

Also please take care about set service recovery properties during service instatation:  
For example:  
 ![image](https://lc-storj.ams3.digitaloceanspaces.com/original/1X/5baf7465e6b6bf1f2741461ffef971d0617563b4.png)

---

<div class="post-metadata">

**Author:** ![Odmin](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/odmin/32/92_2.png) [@Odmin](https://forum.storj.io/u/Odmin)\
**Post date:** [August 14, 2019, 6:06pm UTC](https://forum.storj.io/t/design-draft-windows-installer/1128/3 "2019-08-14T18:06:00Z")

</div>

Another thing that I remember, we should create inbound firewall rule during installation:  
PowerShell:  
`New-NetFirewallRule -DisplayName "Storj v3" -Direction Inbound –Protocol TCP –LocalPort 28967 -Action allow`

---

<div class="post-metadata">

**Author:** ![aleitner](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/aleitner/32/69_2.png) [@aleitner](https://forum.storj.io/u/aleitner)\
**Post date:** [August 14, 2019, 6:08pm UTC](https://forum.storj.io/t/design-draft-windows-installer/1128/4 "2019-08-14T18:08:48Z")

</div>

> [@Odmin](#):
>
> New-NetFirewallRule -DisplayName “Storj v3” -Direction Inbound –Protocol TCP –LocalPort 28967 -Action allow

updated to include the firewall restrictions and the service recovery properties

---

<div class="post-metadata">

**Author:** ![Odmin](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/odmin/32/92_2.png) [@Odmin](https://forum.storj.io/u/Odmin)\
**Post date:** [August 18, 2019, 10:13am UTC](https://forum.storj.io/t/design-draft-windows-installer/1128/5 "2019-08-18T10:13:29Z")

</div>

I have idea how to avoid triggering UAC, we can use standart `sc` command for installing storagenode service.  
Here is a [manual](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/sc-create)

---

<div class="post-metadata">

**Author:** ![kaloyan](https://storj.bcdn.literatehosting.com/letter_avatar/kaloyan/32/5_5575768a8748004e209b776fc1b2916d.png) [@kaloyan](https://forum.storj.io/u/kaloyan)\
**Post date:** [August 20, 2019, 10:15am UTC](https://forum.storj.io/t/design-draft-windows-installer/1128/6 "2019-08-20T10:15:13Z")

</div>

This design draft has been split into several smaller:

- Storage Node Installer for Windows: [https://github.com/storj/storj/pull/2780](https://github.com/storj/storj/pull/2780)
- Storage Node Automatic Updater: [https://github.com/storj/storj/pull/2789](https://github.com/storj/storj/pull/2789)
- Storage Node Watchdog: [https://github.com/storj/storj/pull/2798](https://github.com/storj/storj/pull/2798)
- Rotating Logger for Storage Node: [https://github.com/storj/storj/pull/2799](https://github.com/storj/storj/pull/2799)

Feel free to add comments directly in the PRs, or here in this forum topic.

---

<div class="post-metadata">

**Author:** ![kaloyan](https://storj.bcdn.literatehosting.com/letter_avatar/kaloyan/32/5_5575768a8748004e209b776fc1b2916d.png) [@kaloyan](https://forum.storj.io/u/kaloyan)\
**Post date:** [August 22, 2019, 10:04am UTC](https://forum.storj.io/t/design-draft-windows-installer/1128/7 "2019-08-22T10:04:04Z")

</div>

New PR [https://github.com/storj/storj/pull/2851](https://github.com/storj/storj/pull/2851) for editing the Windows Installer design doc, so we use directly the WiX toolset instead of go-msi.
