09. Run on Startup
Our ngrok server will automatically reconnect, but what about our node server? For that we'll have to set that up on our own. We'll use a package called pm2 (Process Management)
Install pm2 on the Pi:
sudo npm install -g pm2@latest
Now we can start our server with:
pm2 server.js
The server will be running in the background, but we can monitor the app with:
pm2 monit
Exit the monitoring screen with:
ctrl + c
Set pm2 to run at startup:
pm2 startup
Type the command it tells you after running the previous command
Reboot:
reboot
Check that shSMS is running:
pm2 status
You should see the shSMS process in the list
Let's do the same for ngrok:
Edit you ngrok config file:
nano ~/.ngrok2/ngrok.yml
Change it to this with exact spacing (4 spaces per indent)
authtoken: <your-auth-token>
tunnels:
default:
proto: http
addr: 4001
hostname: <your-subdomain>.ngrok.io
Navigate to your system folder:
cd /etc/systemd/system
Create service file:
sudo touch ngrok.service
Add the following and change it to match your own information
[Unit]
Description=Ngrok
After=network.service
[Service]
type=simple
User=<your_pi_username>
WorkingDirectory=/home/<your_pi_username>
ExecStart=/usr/bin/ngrok start --all --config=/home/<your_pi_username>/.ngrok2/ngrok.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target
4. Enable and start the service we just created: systemctl enable ngrok.service && systemctl start ngrok.service
5. Reboot: reboot
6. Send an SMS to confirm it worked
One note about setting up ngrok as a service: For whatever reason I'm not sure how to view the ngrok screen that shows you the status/url/activity/etc once it's set up to run as a service, so if not being able to see all that is an issue, you can stop ngrok from running at startup with
sudo systemctl disable ngrok.service
And then run the regular ngrok http --hostname=XXX 4001
Last updated