Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save crystalclear/93c3d73a6193e1ea4b0b to your computer and use it in GitHub Desktop.

Select an option

Save crystalclear/93c3d73a6193e1ea4b0b to your computer and use it in GitHub Desktop.

Revisions

  1. @learncodeacademy learncodeacademy renamed this gist Oct 17, 2014. 1 changed file with 0 additions and 0 deletions.
  2. @learncodeacademy learncodeacademy revised this gist Oct 17, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions node-deploy-as-service.md
    Original file line number Diff line number Diff line change
    @@ -31,6 +31,7 @@ restart node-app #performs a stop and start. This is all we need for deployments
    ```

    ###Step 2: give your `deploy` user permission to restart the node-app service without requiring a password
    You can make changes to this entry later by running `visudo` as root, but for now, just run this.
    ```bash
    echo "deploy ALL=(root) NOPASSWD: /sbin/restart node-app" >> /etc/sudoers
    ```
  3. @learncodeacademy learncodeacademy revised this gist Oct 17, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion node-deploy-as-service.md
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ exec /usr/local/bin/node bin/www
    ```bash
    start node-app
    stop node-app
    restart node-app #performs a stop and start
    restart node-app #performs a stop and start. This is all we need for deployments
    ```

    ###Step 2: give your `deploy` user permission to restart the node-app service without requiring a password
  4. @learncodeacademy learncodeacademy revised this gist Oct 17, 2014. 1 changed file with 10 additions and 10 deletions.
    20 changes: 10 additions & 10 deletions node-deploy-as-service.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    Deploying a node app with Forever is great...until your server restarts unexpectedly.
    Then your app stops running and you have to re-deploy.

    To get around this, we're going to run our node app as a service.
    Services are great, because, once started, the system auto-restarts them if they fail, or if the server restarts.
    To get around this, we're going to run our node app as an Upstart service.
    Upstart services are great, because, once started, the system auto-restarts them if they fail, or if the server restarts.

    ###Step 1: Create a service for your node app
    - __ssh in as *root*__ `ssh root@youripaddress`
    @@ -17,30 +17,30 @@ nano /etc/init/node-app.conf
    start on filesystem and started networking
    respawn
    chdir /home/deploy/node-app
    env NODE_ENV=production
    env NODE_ENV=production #change this to staging if this is a staging server
    env PORT=3000
    exec /usr/local/bin/node bin/www
    ```

    - **Now your app will always start on reboot!**
    - You can also now you can start | stop | restart your app with these commands
    ```bash
    service node-app start
    service node-app stop
    service node-app restart
    start node-app
    stop node-app
    restart node-app #performs a stop and start
    ```

    ###Step 2: give your `deploy` user permission to run services without a password
    ###Step 2: give your `deploy` user permission to restart the node-app service without requiring a password
    ```bash
    echo "deploy ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
    echo "deploy ALL=(root) NOPASSWD: /sbin/restart node-app" >> /etc/sudoers
    ```

    ###Step 3: on Adjust your flightplan.js file
    ###Step 3: Adjust your flightplan.js file - remove the forever lines, replacing them with the last line here
    View full file, minus these changes [here](https://gist.github.com/learncodeacademy/35045e64d2bbe6eb14f9)
    ```javascript
    remote.log('Reload application');
    remote.sudo('ln -snf ~/' + tmpDir + ' ~/'+appName, {user: username});
    remote.sudo('service node-app restart', {user: 'root'});
    remote.exec('sudo restart node-app');
    ```


  5. @learncodeacademy learncodeacademy revised this gist Oct 16, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion node-deploy-as-service.md
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ Services are great, because, once started, the system auto-restarts them if they

    ###Step 1: Create a service for your node app
    - __ssh in as *root*__ `ssh root@youripaddress`
    - Create a node-app.conf file in /etc/init
    - Create a node-app.conf file in /etc/init<br/>
    IMPORTANT: whatever filename you pick is what you will use to start|stop|restart your service i.e. `service node-app start`
    ```bash
    nano /etc/init/node-app.conf
  6. @learncodeacademy learncodeacademy revised this gist Oct 16, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion node-deploy-as-service.md
    Original file line number Diff line number Diff line change
    @@ -7,10 +7,11 @@ Services are great, because, once started, the system auto-restarts them if they
    ###Step 1: Create a service for your node app
    - __ssh in as *root*__ `ssh root@youripaddress`
    - Create a node-app.conf file in /etc/init
    IMPORTANT: whatever filename you pick is what you will use to start|stop|restart your service i.e. `service node-app start`
    ```bash
    nano /etc/init/node-app.conf
    ```
    IMPORTANT: whatever filename you just picked is what you will use to start|stop|restart your service i.e. `service node-app start`

    - Give the file the following contents
    ```bash
    start on filesystem and started networking
  7. @learncodeacademy learncodeacademy revised this gist Oct 16, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion node-deploy-as-service.md
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ Services are great, because, once started, the system auto-restarts them if they
    ```bash
    nano /etc/init/node-app.conf
    ```
    - IMPORTANT: whatever filename you just picked is what you will use to start|stop|restart your service i.e. `service node-app start`
    IMPORTANT: whatever filename you just picked is what you will use to start|stop|restart your service i.e. `service node-app start`
    - Give the file the following contents
    ```bash
    start on filesystem and started networking
  8. @learncodeacademy learncodeacademy revised this gist Oct 16, 2014. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions node-deploy-as-service.md
    Original file line number Diff line number Diff line change
    @@ -8,8 +8,7 @@ Services are great, because, once started, the system auto-restarts them if they
    - __ssh in as *root*__ `ssh root@youripaddress`
    - Create a node-app.conf file in /etc/init
    ```bash
    cd /etc/init
    nano node-app.conf
    nano /etc/init/node-app.conf
    ```
    - IMPORTANT: whatever filename you just picked is what you will use to start|stop|restart your service i.e. `service node-app start`
    - Give the file the following contents
  9. @learncodeacademy learncodeacademy revised this gist Oct 16, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion node-deploy-as-service.md
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ Services are great, because, once started, the system auto-restarts them if they
    - Create a node-app.conf file in /etc/init
    ```bash
    cd /etc/init
    vim node-app.conf
    nano node-app.conf
    ```
    - IMPORTANT: whatever filename you just picked is what you will use to start|stop|restart your service i.e. `service node-app start`
    - Give the file the following contents
  10. @learncodeacademy learncodeacademy revised this gist Oct 16, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions node-deploy-as-service.md
    Original file line number Diff line number Diff line change
    @@ -7,12 +7,12 @@ Services are great, because, once started, the system auto-restarts them if they
    ###Step 1: Create a service for your node app
    - __ssh in as *root*__ `ssh root@youripaddress`
    - Create a node-app.conf file in /etc/init
    - IMPORTANT: whatever filename you pick here is what you will use to start|stop|restart your service i.e. `service node-app start`
    ```bash
    cd /etc/init
    vim node-app.conf
    ```
    - Give it the following contents
    - IMPORTANT: whatever filename you just picked is what you will use to start|stop|restart your service i.e. `service node-app start`
    - Give the file the following contents
    ```bash
    start on filesystem and started networking
    respawn
  11. @learncodeacademy learncodeacademy revised this gist Oct 16, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion node-deploy-as-service.md
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,8 @@ Services are great, because, once started, the system auto-restarts them if they

    ###Step 1: Create a service for your node app
    - __ssh in as *root*__ `ssh root@youripaddress`
    - Create a node-app.conf file in /etc/init - whatever name you pick here is what you will use to start|stop|restart your service
    - Create a node-app.conf file in /etc/init
    - IMPORTANT: whatever filename you pick here is what you will use to start|stop|restart your service i.e. `service node-app start`
    ```bash
    cd /etc/init
    vim node-app.conf
  12. @learncodeacademy learncodeacademy revised this gist Oct 16, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion node-deploy-as-service.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    Deploying a node app with Forever is great...until your server restarts unexpectedly.
    Then your app stops running and you have to redeploy.
    Then your app stops running and you have to re-deploy.

    To get around this, we're going to run our node app as a service.
    Services are great, because, once started, the system auto-restarts them if they fail, or if the server restarts.
  13. @learncodeacademy learncodeacademy revised this gist Oct 16, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion node-deploy-as-service.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    Deploying a node app with Forever is great...until your server restarts unexpectedly.
    Then your app stops running.
    Then your app stops running and you have to redeploy.

    To get around this, we're going to run our node app as a service.
    Services are great, because, once started, the system auto-restarts them if they fail, or if the server restarts.

  14. @learncodeacademy learncodeacademy renamed this gist Oct 16, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  15. @learncodeacademy learncodeacademy created this gist Oct 16, 2014.
    44 changes: 44 additions & 0 deletions node-deploy-init-d.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    Deploying a node app with Forever is great...until your server restarts unexpectedly.
    Then your app stops running.
    To get around this, we're going to run our node app as a service.
    Services are great, because, once started, the system auto-restarts them if they fail, or if the server restarts.

    ###Step 1: Create a service for your node app
    - __ssh in as *root*__ `ssh root@youripaddress`
    - Create a node-app.conf file in /etc/init - whatever name you pick here is what you will use to start|stop|restart your service
    ```bash
    cd /etc/init
    vim node-app.conf
    ```
    - Give it the following contents
    ```bash
    start on filesystem and started networking
    respawn
    chdir /home/deploy/node-app
    env NODE_ENV=production
    env PORT=3000
    exec /usr/local/bin/node bin/www
    ```

    - **Now your app will always start on reboot!**
    - You can also now you can start | stop | restart your app with these commands
    ```bash
    service node-app start
    service node-app stop
    service node-app restart
    ```

    ###Step 2: give your `deploy` user permission to run services without a password
    ```bash
    echo "deploy ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
    ```

    ###Step 3: on Adjust your flightplan.js file
    View full file, minus these changes [here](https://gist.github.com/learncodeacademy/35045e64d2bbe6eb14f9)
    ```javascript
    remote.log('Reload application');
    remote.sudo('ln -snf ~/' + tmpDir + ' ~/'+appName, {user: username});
    remote.sudo('service node-app restart', {user: 'root'});
    ```