startup nodebb after server reboot
-
What is the best way to configure nodebb to start automatically after restarting the server?
I did it with pm2 -pm2 start app.js --name "nodebb"
and then
pm2 startup
The disadvantage of this is that it is not possible to restart through the ACP, only using
pm2 restart nodebb
What is the right way to do it? -
I start my Nodebb with systemd on Debian Bookworm 12.
[Unit] Description=NodeBB Documentation=https://docs.nodebb.org After=system.slice multi-user.target mongod.service [Service] Type=forking User=USER StandardOutput=syslog StandardError=syslog SyslogIdentifier=nodebb WorkingDirectory=/home/USER/nodebb PIDFile=/home/USER/nodebb/pidfile ExecStart=/usr/bin/node loader.js Restart=always [Install] WantedBy=multi-user.target
And restart from ACP works fine.
-
Create an file
/etc/systemd/system/nodebb.service
Stop your nodebb and then start it with
systemctl enable nodebb.service systemctl start nodebb.service
More to read -> https://docs.nodebb.org/configuring/running/
-
It can be combined with systemctl and tmux for script startup, it is very convenient tmux a can go back to the background to see real-time logs
Here's my server startup script for reference, tmux is too convenient for me!
#!/bin/zsh # Define the function that sends the command send_command() { tmux send -t $1 $2 Enter } # Close and delete the tmux session named "db". tmux kill-session -t "db" # Create a tmux session named "db". tmux new -t "db" -d tmux rename-window -t "db:1" "mongod" # n the "mongod" pane, execute the command send_command "mongod" "cd /home/web/MongoDB/bin/ && ./mongod --config ./mongo.conf" # Creating Horizontally Split Panes tmux split-window -h -t "db:mongod" -d tmux select-window -t "db:mongod" tmux select-pane -t "2" # Close and delete the tmux session named "nodebb". tmux kill-session -t "nodebb" # Create a tmux session called "nodebb". tmux new -t "nodebb" -d tmux rename-window -t "nodebb:1" "grunt" # Execute the command in the "grunt" pane. send_command "nodebb" "cd /home/web/NodeBB/ && ./nodebb slog" # Creating Horizontally Split Panes tmux split-window -h -t "nodebb:grunt" -d tmux select-window -t "nodebb:grunt" tmux select-pane -t "2" exit 0
[Unit] Description=Startup Script After=network.target [Service] Type=forking Environment=TERM=xterm-256color ExecStartPre=/usr/bin/zsh -c 'source $HOME/.zshrc' ExecStart=/root/auto_script/startup.sh User=root Group=root [Install] WantedBy=multi-user.target
-
Thanks to everyone who helped!
While implementing the solution provided by @FrankM I noticed that the file being loaded isloader.js
and notapp.js
, and when I ranloader.js
withpm2
(pm2 start loader.js --name "nodebb"
), restarting from ACP works great!
So maybe on another occasion I'll try the cleansystemd
method
At the moment I prefer to continue using pm2 as a central tool for all the apps on my server, including nodebb
Thanks again -
-
-
@陈洁 wow, that is definitely a power user setup!
One thing I have struggled with is proper logging with systemd. At some point it seemed to stop emitting logs properly, and I could only either have logs sent to the journal for viewing with
journalctl
, or output to the regular log file atlogs/output.log
, not both.Regardless, @josef I'm glad you got it working