Search code examples
gitupstart

Upstart - navigate to directory, git pull, then run daemontools


I am trying to create an upstart conf to both do a "git pull" on a local git repository and then start daemontools "svscan". They nee to be done in that order because the daemon processes rely n having the latest version of the files in the git repository.

I tried:

start on runlevel [12345]
respawn
pre-start script
  cd /scripts
  git pull
end script
exec /command/svscanboot

and also:

start on runlevel [12345]
respawn
chdir /scripts
exec git pull
exec /command/svscanboot

But neither of these work. I'm looking for help in how to tell upstart to navigate to another directory and then execute a command there, prior to running a third command.


Solution

  • You could try this (I had to wrap my git pull in sudo for it to work?):

    start on runlevel [12345]
    
    respawn
    
    pre-start script
      export HOME="/home/user"
      cd $HOME/scripts/
      exec sudo -u user git pull
    end script
    
    script
      export HOME="/home/user"
      cd $HOME/commands/
      exec sudo -u user svscanboot >> /var/log/svscanboot.log 2>&1
    end script