Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create flask upstart script in puppet manifest #1997

Closed
jeff1evesque opened this issue Jun 30, 2015 · 22 comments
Closed

Create flask upstart script in puppet manifest #1997

jeff1evesque opened this issue Jun 30, 2015 · 22 comments
Labels
Milestone

Comments

@jeff1evesque
Copy link
Owner

We need to create start_webserver.pp. This script will be responsible for installing flask, and defining the necessary upstart script, to ensure that our flask server is running each time the Ubuntu Server has started.

The following need to be removed (if present):

  • flask in $packages_flask_pip = ['flask', 'requests'] from install_packages.pp
@jeff1evesque jeff1evesque changed the title Create 'start_flask.pp' Create 'start_webserver.pp' Jun 30, 2015
@jeff1evesque
Copy link
Owner Author

After #2001 has been resolved, we will move corresponding python package installation from install_packages.pp to start_webserver.pp:

  • flask
  • requests

Then, we can safely remove python-pip package from install_packages.pp. However, we need to add include python at the top of install_packages.pp. Also, we will need to add corresponding python include statements at the top of start_webserver.pp.

@jeff1evesque
Copy link
Owner Author

We need to create the upstart script, /etc/init/start_flask.conf:

#!upstart
description 'start flask server'

## start job defined in this file after system services, and processes have already loaded
#       (to prevent conflict).
#
#  @filesystem, ensure job in this file executes after filesystems have been mounted
#  @[2345], represents all configuration states with general linux, and networking access
start on filesystem or runlevel [2345]

## stop flask server when machine gracefully shuts down
stop on shutdown

## start flask server (via bash shell)
exec python /vagrant/app.py

This will allow us the run the following command:

sudo service <servicename> <control>

with the following <command> options:

  • restart: this will stop, then start a service
  • start: this will start a service, if it's not running
  • stop: this will stop a service, if it's running
  • status: this will display the status of a service

Note: according to the Ubuntu upstart documentation, the following can ensure that the job defined in start_flask.conf starts each time the machine boots up:

  • filesystem: event signalling that filesystems have been mounted
  • local-filesystems: event signalling that local filesystems have been
    mounted

@jeff1evesque
Copy link
Owner Author

4f4f564: we forgot that redhat based distros may have a different format for upstart scripts.

@jeff1evesque
Copy link
Owner Author

We need to remove an unnecessary notify => Exec['dos2unix-line-endings'],.

@jeff1evesque
Copy link
Owner Author

We need to ensure that our pre-stop script stanza properly notifies the series of chained puppet commands. Otherwise, only after the second (and successive) series of vagrant up, followed by vagrant halt implementation, will correctly implement the pre-stop script stanza, which means the first vagrant up, followed by vagrant halt, will contain the following error within /var/log/upstart/flask.log:

 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
/proc/self/fd/9: 2: [: =: unexpected operator

One solution is the implement the following within start_webserver.pp:

...
                       ## log shut-down date, remove process id from log before '/vagrant' is unmounted
                       #
                       #  @[`date`], current date script executed
                       pre-stop script
                           echo "[`date`] flask server stopping" >> /vagrant/log/flask_server.log
                       end script
                       | EOT
            notify  => Exec['dos2unix-line-endings'],
        }

        ## convert clrf (windows to linux) in case host machine is windows.
        exec {'dos2unix-line-endings':
            command => 'dos2unix /etc/init/flask.conf',
            refreshonly => true,
            notify => Service['flask'],
        }

        ## start webserver
        service {'flask':
            ensure => 'running',
            enable => 'true',
        }
    }
    default: {
    }
}

@jeff1evesque
Copy link
Owner Author

We need to determine if the following from start_webserver.pp has some syntax error:

...
            notify => Service['flask'],
        }

        ## start webserver
        service {'flask':
            ensure => 'running',
            enable => 'true',
        }
...

The motivation for the above snippet, is because our generated /etc/init/flask.conf does not automatically run on initial build, nor successive vagrant up. However, if we manually vagrant up, then run sudo service flask start, our flask server, app.py is guaranteed to be running.

@jeff1evesque
Copy link
Owner Author

We need to adjust our flask upstart script by implementing another workaround upstart script in order to ensure the vagrant-mounted event.

@jeff1evesque jeff1evesque added this to the 0.1 milestone Aug 22, 2015
@jeff1evesque
Copy link
Owner Author

The workaround has been implemented in #2046. However, we will close this issue, since the creation of the upstart script has been resolved, and handle all other bugs, within their own corresponding issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant