how to keep nodebb start when I reboot ubuntu16.04



  • when I reboot ubuntu,the nodebb need used ./nodebb start to start
    How to keep nodebb auto-start

    etc

    • Upstart
    • pm2
    • Forever

    Which is better?

    I'm used

    npm install -g forever
    cd /var/www/nodebb
    forever start app.js
    

    But it doesn't work when reboot

    Ubuntu 16.04.2 LTS
    Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused



  • @dxxt systemctl,

    For NodeBB < 1.5 I use this configuration (read below), but I don't know if the ExecStart script should be updated in the future:

    Just create a file called nodebb.service in /etc/systemd/system (or /etc/systemd/user, or any subfolder of systemd), stop nodebb as you run it now and do:

     sudo systemctl daemon-reload
     sudo systemctl start nodebb
    

    The configuration file is:

    [Unit]
    Description=NodeBB Service
    After=system.slice multi-user.target
    
    [Service]
    User=YOUR_USER
    Group=YOUR_USERGROUP
    
    StandardOutput=syslog
    StandardError=syslog
    SyslogIdentifier=nodebb
    
    Environment=NODE_ENV=production
    WorkingDirectory=/var/nodebb
    ExecStart=/usr/bin/node loader.js --no-daemon --no-silent
    Restart=always
    
    [Install]
    Alias=forum
    WantedBy=multi-user.target
    

    You can read mode about systemctl, that is the integrated Ubuntu service manager, read here



  • @Giggiux beat me to it :)

    you might need:

    After= mongod.service/redis.service (depends which one you use)

    This will at least wait for your DB to startup before starting. It helps after restarts


  • Admin

    Updated this in our docs @Giggiux and @Adam-Poniatowski 😄

    However, it may need changes if we really do need it to start up after mongo...



  • @julian I think that if it cannot connect to mongo/redis, it will just give startup error and try to restart again until it finds it



  • @julian I tried following the instructions in the documentation, and it still is a no go :(



  • @dxxt @teh_g Try this.

    Step 1 - This will start your nodebb after login in

    [Unit]
    Description=NodeBB forum for Node.js.
    Documentation=http://nodebb.readthedocs.io/en/latest/
    After=system.slice multi-user.target
    
    [Service]
    Type=simple
    User=your-linux-username
              
    StandardOutput=syslog
    StandardError=syslog
    SyslogIdentifier=nodebb
    
    Environment=NODE_ENV=production
    WorkingDirectory=/your/nodebb/folder
    ExecStart=/usr/bin/node /your/nodebb/folder/loader.js --no-daemon --no-silent
    Restart=always
    
    [Install]
    WantedBy=multi-user.target
    

    Step 2 - On terminal - This will start your nodebb on boot-up

    loginctl enable-linger your-linux-username


  • @Giggiux That is correct. It will keep restarting until mongo/redis has started. I added mongod.service in the After parameter and does startup normally. I know mongod takes a minute or 2 to start, as I have tested this and nodebb is in the failed state until mongod has fully started. Sometimes mongod will show that it has started but nodebb fails to start. I just waited a couple of minutes and checked nodebb again (systemctl status nodebb) and it was up/active, without my intervention :)


Log in to reply
 


Looks like your connection to NodeBB was lost, please wait while we try to reconnect.