Forráskód Böngészése

Restructure role to work with Gogs 0.5.11.

Jeff Geerling 9 éve
szülő
commit
6e3f54083f
6 módosított fájl, 25 hozzáadás és 79 törlés
  1. 1 1
      defaults/main.yml
  2. 14 0
      tasks/init-setup.yml
  3. 6 16
      tasks/main.yml
  4. 0 62
      templates/gogs-init.j2
  5. 2 0
      vars/Debian.yml
  6. 2 0
      vars/RedHat.yml

+ 1 - 1
defaults/main.yml

@@ -1,7 +1,7 @@
 ---
 gogs_user: git
 gogs_user_home: /home/git
-gogs_binary_url: https://github.com/gogits/gogs/releases/download/v0.3.1/linux_amd64.zip
+gogs_binary_url: https://github.com/gogits/gogs/releases/download/v0.5.11/linux_amd64.zip
 gogs_http_port: "3000"
 gogs_use_mysql: false
 gogs_db_name: gogs

+ 14 - 0
tasks/init-setup.yml

@@ -0,0 +1,14 @@
+---
+- name: Make Gogs init script executable.
+  file:
+    path: "{{ gogs_user_home }}/{{ gogs_init_script_path }}"
+    mode: 0755
+
+- name: Symlink Gogs binary and startup scripts.
+  file:
+    src: "{{ item.src }}"
+    dest: "{{ item.dest }}"
+    state: link
+  with_items:
+    - { src: "{{ gogs_user_home }}/gogs/gogs", dest: "/usr/local/bin/gogs" }
+    - { src: "{{ gogs_user_home }}/{{ gogs_init_script_path }}" , dest: "/etc/init.d/gogs" }

+ 6 - 16
tasks/main.yml

@@ -1,4 +1,8 @@
 ---
+# Include variables and define needed variables.
+- name: Include OS-specific variables.
+  include_vars: "{{ ansible_os_family }}.yml"
+
 - name: Ensure unzip is installed (RedHat).
   yum: pkg=unzip state=installed
   when: ansible_os_family == 'RedHat'
@@ -27,16 +31,9 @@
     chdir={{ gogs_user_home }}
     creates={{ gogs_user_home }}/gogs/gogs
 
+- include: init-setup.yml
 - include: gogs-mysql.yml
 
-- name: Copy gogs init file.
-  template:
-    src: gogs-init.j2
-    dest: /etc/init.d/gogs
-    owner: root
-    group: root
-    mode: 0755
-
 - name: Create Gogs log folder.
   file:
     path: "{{ gogs_user_home }}/gogs/log"
@@ -45,12 +42,5 @@
     group: "{{ gogs_user }}"
     mode: 0755
 
-- name: Check if Gogs is running.
-  command: service gogs status
-  changed_when: false
-  register: gogs_status
-
 - name: Ensure Gogs is running.
-  shell: >
-    su -c "service gogs start" -s /bin/bash {{ gogs_user }}
-  when: "'running' not in gogs_status.stdout"
+  service: name=gogs state=started enabled=yes

+ 0 - 62
templates/gogs-init.j2

@@ -1,62 +0,0 @@
-#! /bin/bash
-# /etc/init.d/gogs
-#
-
-### BEGIN INIT INFO
-# Provides:          gogs
-# Required-Start:    $remote_fs $syslog
-# Required-Stop:     $remote_fs $syslog
-# Default-Start:     2 3 4 5
-# Default-Stop:      0 1 6
-# Short-Description: Start gogs at boot time.
-# Description:       Control gogs.
-### END INIT INFO
-
-start_gogs() {
-  nohup {{ gogs_user_home }}/gogs/start.sh > {{ gogs_user_home }}/gogs/log/gogs.log 2>&1&
-}
-
-# Gogs needs a home path.
-export HOME={{ gogs_user_home }}
-
-# Carry out specific functions when asked to by the system
-case "$1" in
-  start)
-    ps aux | grep 'gogs' | grep -v grep | grep -vq start
-    if [ $? = 0 ]; then
-      echo "Gogs is already running."
-    else
-      start_gogs
-    fi
-    ;;
-  stop)
-    ps aux | grep 'gogs' | grep -v grep | grep -vq stop
-    if [ $? = 0 ]; then
-      echo "Stopping Gogs."
-      kill `ps -ef | grep 'gogs' | grep -v grep | awk '{print $2}'`
-    else
-      echo "Gogs is already stopped."
-    fi
-    ;;
-  restart)
-    ps aux | grep 'gogs' | grep -v grep | grep -vq restart
-    if [ $? = 0 ]; then
-      kill `ps -ef | grep 'gogs' | grep -v grep | awk '{print $2}'`
-    fi
-    start_gogs
-    ;;
-  status)
-    ps aux | grep 'gogs' | grep -v grep | grep -vq status
-    if [ $? = 0 ]; then
-      echo "Gogs is running."
-    else
-      echo "Gogs is stopped."
-    fi
-    ;;
-  *)
-    echo "Usage: /etc/init.d/gogs {start|stop|restart|status}"
-    exit 1
-    ;;
-esac
-
-exit 0

+ 2 - 0
vars/Debian.yml

@@ -0,0 +1,2 @@
+---
+gogs_init_script_path: gogs/scripts/init/debian/gogs

+ 2 - 0
vars/RedHat.yml

@@ -0,0 +1,2 @@
+---
+gogs_init_script_path: gogs/scripts/init/centos/gogs