One-click deployment blog script

Foreword

Recently completed the development project, the next step is iterative, and more adequate free time, and began to carry out his own blog up.
Here to talk about the situation of his own blog: I am using jekyll build a blog, as to how to install jekyll not described in detail here, because they installed four or five times, but the problem encountered each installation is different, every time installation can be found many tutorials have installed, you need to install or own it to Google or Baidu.

text

Deployment Process

First is that the deployment process blog it:

  1. Blog manually kill the process
  2. Enter the blog directory
  3. Update code
  4. Log in warehouse
  5. Execute the command to start the blog
  6. Start complete

problem

  1. Each time you update the code to login
  2. Manually enter the command more
  3. Blog start command long, easy to forget

script

Each update should pull

The solution is to use ssh update, now locally generated keys, key in the copy to the repository, and then pull the code; specific process does not elaborate here, a lot of complete online tutorial on ssh's.

Complete the process

  1. Enter the directory

cd /usr/local/bin
  1. create

vi myblog
vim myblog
  1. Write

Press the i button to start writing the script written below the best not to copy, direct hand to knock, copy the format may not lead to script error

  1. Completion of
    the finished press esckey, enter :wq, and 回车key programming.

  2. Complete script


#!/bin/bash

#进入项目目录
cd /usr/local/myblog/myblog

# 更新代码
git  pull

# 获取博客进程ID
PID=$(ps -ef | grep "jekyll" | grep -v grep | awk '{ print $2 }')

if [ -z "$PID" ]
then
    echo Application is already stopped
else
    echo kill $PID
    kill -9  $PID
fi

# 后台启动jekyll命令
bundle exec jekyll server --detach

note:

  1. If the finish and then upload Linux, the script will be a great probability of error, because of the format on a Windows system; it is proposed to create a file and write directly on the Linux command;
  2. I was directly putting commands in the /usr/local/bindirectory
  3. After writing the script commands to remember to set permissions

to sum up

The first to write the script, do not know there are a lot of things, there are still a lot to learn;

Guess you like

Origin www.cnblogs.com/guoyuchuan/p/12079621.html