Running PS daemonized on nodejs/windows

Hi,

I’ve reverted to running the server version of PS via NodeJS and Windows. First of all the GUI feels more “snappy” and faster than the desktop version which is great! :slight_smile:

However I can get it to run with the Git Bash console but when i try to run it daemonized it does not seem to start. I’m sure I do something wrong but I don’t know what… I’ve followed the docs for running PS on NodeJS/Windows. And also I’m quite unfamiliar with the Git Bash console so bear that in mind.

Username@Hostname MINGW64 ~/photostructure-for-servers (main)
$ ./start.sh
No local changes to save
Already up to date.
yarn install v1.22.10
[1/4] Resolving packages…
success Already up-to-date.
Done in 0.23s.
Please wait, setting up…
PhotoStructure is ready: http://localhost:1787/

Username@Hostname MINGW64 ~/photostructure-for-servers (main)
$ ./start.sh --pidfile $PIDFILE
No local changes to save
Already up to date.
yarn install v1.22.10
[1/4] Resolving packages…
success Already up-to-date.
Done in 0.23s.
Daemonized PhotoStructure. {
pid: 4192,
args: [
‘C:\Users\Username\photostructure-for-servers\bin\main.js’,
‘–pidfile’
]
}

Username@Hostname MINGW64 ~/photostructure-for-servers (main)
$ ./start.sh --pidfile /var/run/photostructure.pid
No local changes to save
Already up to date.
yarn install v1.22.10
[1/4] Resolving packages…
success Already up-to-date.
Done in 0.23s.
Daemonized PhotoStructure. {
pid: 3900,
args: [
‘C:\Users\Username\photostructure-for-servers\bin\main.js’,
‘–pidfile’,
‘C:/Program Files/Git/var/run/photostructure.pid’
]
}

When running the first one of these I see all the NodeJS processes spawn and everything works fine. The next two does not seem to spawn the processes. And and I cannot access the GUI of course.

Any idéa what I’m doing wrong?

Kind regards
Hannes

Dang!

Are you running this from a cygwin terminal?

No, git bash

I’ve followed the instructions in
PhotoStructure | PhotoStructure for Node

Sorry, brainfart on my part (that’s what I get for responding at 5am)

The --pidfile and --daemon functionality only works on macOS and Linux.

The proper way to do this on Windows would be to run as a service (probably via sc). There’s a package (node-windows) to make this simpler, but it seems to be all but abandoned, so I’m a bit hesitant to pull that in as a dependency.

Given that this will take a bit of time to code up, I’m going to promote this as a feature request now.

On Windows, the easiest way to make an arbitrary executable into a service is probably to use NSSM. I’ve used it in the past to run things that don’t have native Windows service support (like Prometheus) on Windows Server.

Another alternative on Windows is to use Docker. It’d probably be a bit slower though (but not too slow if you use the newer WSL 2.0 based Docker.

1 Like

No worries, I’m not very good at NodeJS/Bash so I couldn’t really tell what I was trying to do :slight_smile: :stuck_out_tongue_closed_eyes:

That would be awesome to be able to run it as a Windows Service!

+1 Vote from me then, (my real votes are consumed :cry:)

Thanks for the tip, I’m going to try NSSM :slight_smile:

And regards to Docker, I did try do run the docker on windows containers but realized short after that it had to be run on linux based containers which I didn’t have.

It’s a good idéa with WSL 2 but I’m alittle hesitant because I’m really bad at the linux part of it. I would probably need some kind of guide.

I tried NSSM and it worked perfect! And was very easy to setup. Below is the steps I took to set it up.

  1. Download NSSM
  2. Start CMD as Admin and set directory to where you extracted the NSSM.exe files ie
    cd C:\NSSM\win64
  3. Run "nssm.exe install photostructure “C:\Program Files\NodeJS\node.exe”
  4. Run “nssm.exe set photostructure AppDirectory C:\Users<username>\photostructure-for-servers”
  5. Run “nssm.exe set photostructure AppParameters photostructure”
    6 Run “nssm start photostructure”

Thats pritty much it, however when i browsed to the photostructure GUI i got a clean-slate setup experience and I realised that the windows service was running using the “local system” account. That account uses its own default folders and it does not find the existing library. So a last step

  1. Open services.msc, find the service, right-click properties, “logon” and change from “local system account” to “specify account”. I used the same credentials that I used when running photostructure from git-bash.

One caveat is that since its not running the start.sh bash script it wont autoupdate I guess so I’ll simply start it manually with git-bash once 1.0.0 comes out :slight_smile:

Edit: I also adjusted the recovery settings of the service to set it to restart-service in case it would fail.

2 Likes

I’m glad that NSSM worked!

@mrm NSSM is public domain so one approach to supporting usage as a service on Windows could be to just bundle NSSM with PhotoStructure and let it handle the service side of things. PhotoStructure could have an “install as a service” button that runs all the NSSM commands to set up the service (it’d need to do it with elevated permissions).

1 Like

I just found serviceman, which is cross-platform.

I’ll look into integrating nssm or it in a future release. :+1: