1

Sir, I have a node.js script call 'Test_timeevent.js'. I use 'forever' module to avoid timeevent.js crash. I hope when Ubuntu start,this 'forever' can start timeevent.js. So,Test_timeevent.js will run always. The Test_timeevent.js code is below:

var schedule = require("node-schedule");
var rule1     = new schedule.RecurrenceRule();
var times1    = [1,6,11,16,21,26,31,36,41,46,51,56];
var li_count=0;
rule1.second  = times1;
var j = schedule.scheduleJob(rule1, function(){
        li_count= li_count +1;
  console.log(li_count);
});

I write a run_vb.sh in the '/etc/init.d' .The code is below:

#!/bin/sh
### BEGIN INIT INFO
# Provides: barkelyhwang
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: SMD service
# Description: timeevent service daemon
### END INIT INFO

forever start /home/barkely/nodeproject/vbs/Test_timeevent.js
exit 0

Then,I change run_vb.sh mode by:

sudo chmod +x /etc/init.d/run_vb.sh

And then,I execute 'update-rc.d' :

sudo update-rc.d run_vb.sh defaults 99 1

After reboot my Ubuntu Server, I execute 'ps -aux',the result is:

root       1677  0.0  1.0 889064 45028 ?        Ssl  10:37   0:00 /usr/bin/node /usr/local/lib/node_modules/forever/bin/monitor /home/barkely/nodeproject/vbs/Test_timeevent.js
root       1686  0.0  0.1  92828  6764 ?        Ss   10:37   0:00 sshd: barkely [priv]
root       1688  0.0  0.8 882192 36368 ?        Sl   10:37   0:00 /usr/bin/node /home/barkely/nodeproject/vbs/Test_timeevent.js

I find it seem to be executed,but when I check the output of forever of Test_timeevent.js,there are no output log. Normally,this folder should be like this:

barkely@barkelyVM:~/.forever$ ls -al
total 24
drwxr-xr-x  4 barkely barkely 4096 Nov 14 15:34 .
drwxr-xr-x 19 barkely barkely 4096 Nov 14 15:25 ..
-rw-rw-r--  1 barkely barkely  293 Nov 14 15:34 config.json
drwxr-xr-x  2 barkely barkely 4096 Nov 14 15:35 pids
-rw-rw-r--  1 barkely barkely    4 Nov 14 15:35 **pQFQ.log**
drwxr-xr-x  2 barkely barkely 4096 Nov 14 15:34 sock

There is a log file called 'pQFQ.log'.

What step I lost?My script don't start when Ubuntu start.

My Ubuntu is Ubuntu Server 16.04.4 LTS. Node.js :v10.5.0

  • Can you please replace the output of ps -ax with ps -aux. I assume it is a permission issue, because the servies is started with a differnt user then barkely – Simon Sudler Nov 14 '18 at 8:15
  • www-data 1662 0.0 0.2 325548 8672 ? S 10:37 0:00 /usr/sbin/apache2 -k start root 1677 0.0 1.0 889064 45028 ? Ssl 10:37 0:00 /usr/bin/node /usr/local/lib/node_modules/forever/bin/monitor /home/barkely/nodeproject/vbs/Test_timeevent.js root 1686 0.0 0.1 92828 6764 ? Ss 10:37 0:00 sshd: barkely [priv] root 1688 0.0 0.8 882192 36368 ? Sl 10:37 0:00 /usr/bin/node /home/barkely/nodeproject/vbs/Test_timeevent.js barkely 1694 0.0 0.1 45276 4592 ? Ss 10:37 0:00 /lib/systemd/systemd --user – 黃智祥 Nov 15 '18 at 2:44
  • Please add the output to your question. Use this link askubuntu.com/posts/1092771/edit – Simon Sudler Nov 15 '18 at 7:50
  • I don’t see anything in your script creating a log file at all. And the log file is from the barkely user, which is strange, because the nodejs process is owned by root. While you’re a investigating, where the strange log file is coming from, I would advise to change your startup script to systemd. It makes it easier to monitor and debug the service – Simon Sudler Nov 15 '18 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.