4

I'm trying to setup a upstart conf for my nodejs app. I have to run 2 script scrip_1.js and script_2.js. Here the conf

start on startup
stop on shutdown

respawn

console log

env PROJ=/project/path

script
    cd $PROJ
    exec node script_1.js 2>&1 >> $PROJ/logs/script_1.log
    exec node script_2.js 2>&1 >> $PROJ/logs/script_2.log
end script

The problem is only script_1.js running. If I move the exec node script_2.js... right before cd $PROJ then only script_2.js running.

How can I make this upstart conf?

Thank you!

fernandopasik
  • 9,565
  • 7
  • 48
  • 55
neo0
  • 592
  • 3
  • 10
  • 18

1 Answers1

8

Create a separate job for both script 1 and script 2.

CameronNemo
  • 616
  • 3
  • 10
  • I'm using 2 conf in `/etc/init/` for each command. You mean that? – neo0 Jul 24 '14 at 10:01
  • Yes, /etc/init/myscript1.conf and /etc/init/myscript2.conf or whatever you want to name them. – CameronNemo Jul 24 '14 at 20:28
  • 1
    so with upstart conf we can not run 2 commands like my original script? – neo0 Jul 25 '14 at 01:41
  • No, it can only monitor one process per conf. – CameronNemo Jul 25 '14 at 03:45
  • where in the specs is this stated that it can only monitor one process per conf? thanks – Alex Oct 13 '19 at 18:23
  • There are job classes, job instances, and job processes. A conf file defines a job class, and when an instance of that class is started various job processes can be started. The job lifecycle detailed in the manpage is a good overview (https://man.voidlinux.org/startup#Job_Lifecycle). Usually only one process will be running, but post-start and pre-stop are exceptions. The main exec/script stanza will only ever yield a single process that is monitored. – CameronNemo Oct 14 '19 at 06:19