OHIF as Node JS Service (systemctl) #1

Open
opened 2025-03-10 17:26:52 +07:00 by mario · 0 comments
Owner

1. Build Locally

Build app to generate /dist folder:

cd <Path to OHIF Viewer Root Dir>
yarn run build

2. Prepare the Static Files

Copy only the /dist folder to the server since it already contains the serve.json file:

# On your local machine:
scp -r platform/app/dist user@server:/var/www/ohif-391

3. Install Node melalui NVM

# On the server:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
source ~/.bashrc
nvm install v20
nvm use v20

4. Create the .service File

Since the serve.json is already inside /dist, you don’t need to explicitly specify its path. The serve command will automatically detect and use it.

Create /etc/systemd/system/ohif-viewer.service:

[Unit]
Description=OHIF Viewer Service
After=network.target

[Service]
Type=simple
User=pacs
Group=pacs
WorkingDirectory=/home/pacs/ohif-viewer/platform/app
ExecStart=/home/pacs/.nvm/versions/node/v20.19.0/bin/npx serve ./dist -c ../public/serve.json
Restart=always
RestartSec=3
Environment=NODE_ENV=production
Environment=PATH=/home/pacs/.nvm/versions/node/v20.19.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
TimeoutStartSec=30
TimeoutStopSec=10
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target

5. Enable and Start the Service

sudo systemctl daemon-reload
sudo systemctl enable ohif-viewer
sudo systemctl start ohif-viewer
sudo systemctl status ohif-viewer
#### 1. **Build Locally** Build app to generate `/dist` folder: ```bash cd <Path to OHIF Viewer Root Dir> yarn run build ``` --- #### 2. **Prepare the Static Files** Copy only the `/dist` folder to the server since it already contains the `serve.json` file: ```bash # On your local machine: scp -r platform/app/dist user@server:/var/www/ohif-391 ``` #### 3. **Install Node melalui NVM** ```bash # On the server: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash source ~/.bashrc nvm install v20 nvm use v20 ``` #### 4. **Create the `.service` File** Since the `serve.json` is already inside `/dist`, you don’t need to explicitly specify its path. The `serve` command will automatically detect and use it. Create `/etc/systemd/system/ohif-viewer.service`: ```ini [Unit] Description=OHIF Viewer Service After=network.target [Service] Type=simple User=pacs Group=pacs WorkingDirectory=/home/pacs/ohif-viewer/platform/app ExecStart=/home/pacs/.nvm/versions/node/v20.19.0/bin/npx serve ./dist -c ../public/serve.json Restart=always RestartSec=3 Environment=NODE_ENV=production Environment=PATH=/home/pacs/.nvm/versions/node/v20.19.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin TimeoutStartSec=30 TimeoutStopSec=10 KillSignal=SIGINT [Install] WantedBy=multi-user.target ``` #### 5. **Enable and Start the Service** ```bash sudo systemctl daemon-reload sudo systemctl enable ohif-viewer sudo systemctl start ohif-viewer sudo systemctl status ohif-viewer ```
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mario/ohif-viewer#1