We want the CSS to start automatically when server restarts, or when CSS crashes. We'll use pm2 to do that.
sudo npm install -g pm2
Then, make sure it will start when server restarts
# run as [user]
pm2 startup
This command will output another command that you should execute. In my case it looks like this:
## don't do this!
## generate your own with `pm2 startup`! (run it as [user])
## run as [user] or root
# sudo env PATH=$PATH:/snap/node/7581/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u [user] --hp /home/[user]
-
Create a file at
~/www/[projectname]/run.sh
:# run as [user] touch ~/www/[projectname]/run.sh
-
Open it with vim or nano, and paste your favourite way to run the CSS, for example:
#!/bin/bash # Source the nvm initialization script # this is a little tweak to make nvm available in the context of pm2 source /home/solidtest/.nvm/nvm.sh # put your favourite way to run CSS here, for example nvm exec 18 npx -y @solid/community-server@7 -f ./data/ -c ./config.json -p [port] -b https://[your.domain]
-
Make the script executable:
# run as [user] chmod +x ~/www/[projectname]/run.sh
-
Test it
# run as [user] # go to project folder cd ~/www/[projectname] # cd ~/www/[projectname]/CommunitySolidServer # if you run it from git repo # execute . ./run.sh
- Start CSS:
# run as [user] cd ~/www/[projectname] # cd ~/www/[projectname]/CommunitySolidServer # if you run it from git repo pm2 start run.sh --name [for-example-your.domain]
- Check that the server runs
- Persist the settings
# run as [user] pm2 save
- Try to reboot your machine and see if CSS starts automatically
# each user manages its own pm2 instance
# see list of pm2 processes
pm2 list
# you'll see a list including name and id of each process
# see log of a particular process
pm2 log [name-or-id]
# start, restart, and stop process
pm2 start [name-or-id]
pm2 restart [name-or-id]
pm2 stop [name-or-id]
# see details about a process
pm2 describe [name-or-id]
# see nice overview of running processes
pm2 monit