I think that was the approach that I followed and it seemed to take some 
gymnastics to make work.  I think I might have to revisit what I did as the 
configuration that Alan posted might fix some of the oddities I run into.  
 I suspect my approach was not optimal.  In either case I think I did 
something like the following.  I have it all in an Ansible playbook and 
once I got it working I kind of left it.
My systemd unit file (/etc/systemd/system/pm2-dspace.service) looks like 
the following (running RHEL 8.9):
[Unit]
Description=PM2 process manager
Documentation=https://pm2.keymetrics.io/
After=network.target

[Service]
Type=forking
User=dspace
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Environment=PATH=/home/dspace/.local/bin:/home/dspace/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Environment=PM2_HOME=/home/dspace/.pm2
PIDFile=/home/dspace/.pm2/pm2.pid
Restart=on-failure

ExecStart=/usr/local/lib/node_modules/pm2/bin/pm2 resurrect
ExecReload=/usr/local/lib/node_modules/pm2/bin/pm2 reload all
ExecStop=/usr/local/lib/node_modules/pm2/bin/pm2 kill

[Install]
WantedBy=multi-user.target

To get this to work though I believe I needed to "sudo npm install --global 
pm2"
Then as the dspace user I created /opt/dspace-angular/dspace-ui.json with
{
    "apps": [
        {
           "name": "dspace-ui",
           "cwd": "{{ dspace_ui_deploy_dir }}",
           "script": "dist/server/main.js",
           "instances": "max",
           "exec_mode": "cluster",
           "env": {
              "NODE_ENV": "production"
           }
        }
    ]
}

And then as the dspace user:
/usr/local/bin/pm2 start dspace-ui.json /
/usr/local/bin/pm2 save
/usr/local/bin/pm2 stop dspace-ui.json
/usr/local/bin/pm2 kill
At this point on a reboot systemd will start the pm2  dspace-ui but using 
systemd to stop pm2 leaves things in a odd state, possibly because PM2 God 
Daemon is running.  As the dspace use I am able to pm2 stop dspace-ui and 
do some of the various other pm2 commands (I just added another cpu and 
just did a pm2  scale dspace-ui +1 and then a pm2 save and on a reboot 
systemd resurrected the saved config so I went from 2 workers to 3.  I 
admit though that I do not and did not fully understand what pm2 was 
doing.  I was just happy that I was able to make it work on a reboot.
On Wednesday, January 17, 2024 at 11:46:10 AM UTC-5 Jorge Torres wrote:

> PM2 docs have a section for start on reboot, it creates a service based on 
> the system service manager.
> https://pm2.keymetrics.io/docs/usage/startup/
> El Wednesday, January 17, 2024 a la(s) 10:42:04 AM UTC-3, Alan Orth 
> escribió:
>
>> Dear Joshua,
>>
>> I am starting pm2 via a systemd service unit, 
>> /etc/systemd/system/dspace-angular.service:
>>
>> [Unit]
>> Description=DSpace Angular (PM2)
>> After=network.target tomcat9.service
>> Wants=tomcat9.service
>>
>> [Service]
>> User=dspace
>> Group=dspace
>> LimitNOFILE=infinity
>> LimitNPROC=infinity
>> LimitCORE=infinity
>> Environment=NODE_ENV=production
>> Environment=PM2_HOME=/home/dspace/.pm2
>> Restart=on-failure
>> WorkingDirectory=/home/dspace/src/git/dspace-angular
>> ExecStart=/home/dspace/.node_modules/lib/node_modules/pm2/bin/pm2 start 
>> ./dist/server/main.js --name dspace-ui -i 4 --no-daemon
>> ExecReload=/home/dspace/.node_modules/lib/node_modules/pm2/bin/pm2 reload 
>> dspace-ui
>> ExecStop=/home/dspace/.node_modules/lib/node_modules/pm2/bin/pm2 stop 
>> dspace-ui
>> # Don't log pm2 to the systemd journal! Use pm2 logs instead.
>> StandardOutput=null
>>
>> [Install]
>> WantedBy=multi-user.target
>>
>> Then start and enable the service like you would any other system 
>> service. Works well, but I'm surprised at how pm2 makes this difficult. I 
>> find pm2's ergonomics very strange. In the service file above you can see I 
>> tell pm2 to not start its own management daemon. How can so much of the 
>> insanely massive Node.js ecosystem depend on this random package for 
>> clustering? And how can there be no other alternatives? Bizarre...
>>
>> Hope that helps,
>>
>> On Tue, Jan 9, 2024 at 12:15 AM Joshua Kim <jos...@udel.edu> wrote:
>>
>>> Hello,
>>>
>>> Does anyone use automatic start for dspace front end at reboot by using 
>>> service ? If so, would you share with us? The 7.x documentation shows only 
>>> manual start like pm2 start dspace-ui.json. 
>>>
>>> -- 
>>> All messages to this mailing list should adhere to the Code of Conduct: 
>>> https://www.lyrasis.org/about/Pages/Code-of-Conduct.aspx
>>> --- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "DSpace Technical Support" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to dspace-tech...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/dspace-tech/2b8f0685-8327-4eac-9f0e-683c7d8c22ben%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/dspace-tech/2b8f0685-8327-4eac-9f0e-683c7d8c22ben%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
>>
>> -- 
>> Alan Orth
>> alan...@gmail.com
>> https://picturingjordan.com
>> https://englishbulgaria.net
>> https://mjanja.ch
>>
>

-- 
All messages to this mailing list should adhere to the Code of Conduct: 
https://www.lyrasis.org/about/Pages/Code-of-Conduct.aspx
--- 
You received this message because you are subscribed to the Google Groups 
"DSpace Technical Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dspace-tech+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dspace-tech/2f41a45a-48c4-4688-b477-dce0e9212632n%40googlegroups.com.

Reply via email to