Results 1 to 3 of 3

Thread: Running script at startup

  1. #1
    Join Date
    Jul 2009
    Location
    Palo Alto, CA
    Beans
    147
    Distro
    Xubuntu 12.04 Precise Pangolin

    Running script at startup

    I'm setting up an image for a webserver. I have a script on the server that fetches the latest source code for an application from a repository and does all the configuration necessary for deployment. This script is to be run by the unprivileged user for deployment.

    Right now:
    1. System boots
    2. Apache starts
    3. I log in, run my script, and restart apache

    What I want:
    1. System boots, starting all services *except* apache
    2. my script runs, with only the permission of the 'deployment' user
    3. start the apache services

    I haven't really been following upstart or how it works at all. I see apache still starts from System V-style init scripts. What's the right way to set this up cleanly?

    Thanks folks!

  2. #2
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: Running script at startup

    I guess you can have a look at
    /usr/share/doc/apache2.2-common/examples/secondary-init-script on your system

    Try to invoke your script from it like
    Code:
    [ start = "$1" ] && su -c name_of_your_script deployment
    . /etc/init.d/apache2
    Edit.
    Sorry, it's not the right way you're looking for. The simplest would be probably to put command invoking your script into /etc/init.d/apache2:
    Code:
    ...
    case $1 in
         start)
             su -c name_of_your_script deployment
             log_daemon_msg "Starting web server" "apache2"
    ...
    Last edited by schragge; February 13th, 2013 at 10:40 AM.

  3. #3
    Join Date
    Jul 2009
    Location
    Palo Alto, CA
    Beans
    147
    Distro
    Xubuntu 12.04 Precise Pangolin

    Re: Running script at startup

    Quote Originally Posted by schragge View Post
    [/code]Edit.
    Sorry, it's not the right way you're looking for. The simplest would be probably to put command invoking your script into /etc/init.d/apache2:
    Code:
    ...
    case $1 in
         start)
             su -c name_of_your_script deployment
             log_daemon_msg "Starting web server" "apache2"
    ...
    This worked well, thanks! I also like now that 'sudo service apache2 restart' also runs my script and redeploys the application. Pretty slick.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •