From 2bfbcf2495aaaa947bb8d13557f99ee88dad7a63 Mon Sep 17 00:00:00 2001 From: flynn Date: Mon, 21 Jan 2019 22:56:36 +0100 Subject: [PATCH] add systemd service and start script --- .gitignore | 1 + defaults/main.yml | 8 ++++++-- tasks/main.yml | 35 ++++++++++++++++++++++++++++------- templates/cat.service | 12 ++++++++++++ templates/start.sh | 12 ++++++++++++ 5 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 .gitignore create mode 100644 templates/cat.service create mode 100644 templates/start.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/defaults/main.yml b/defaults/main.yml index 82bb574..5695f05 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,7 +1,6 @@ --- # defaults file for . cat_user: cat -cat_homedir: cat cat_postgres_db: cat cat_postgres_user: cat_user @@ -9,6 +8,11 @@ cat_postgres_user: cat_user # sensitive info cat_postgres_password: "{{ vault_cat_postgres_password }}" -cat_git_destination: /home/{{ cat_user }}/cat_src +cat_git_destination: "/home/{{ cat_user }}/cat_src" port: 3000 + +authorize-uri: "https://adams.ugent.be/oauth/oauth2/authorize/" +access-token-uri: "https://adams.ugent.be/oauth/oauth2/token/" +oauth-consumer-key: "tomtest" +oauth-consumer-secret: "blargh" \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index be4653c..51207f3 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -73,10 +73,31 @@ args: chdir: "{{ cat_git_destination }}" -- name: Run jar - become: yes - become_user: "{{ cat_user }}" - shell: java -jar {{cat_git_destination }}/target/uberjar/cat.jar - environment: - DATABASE_URL: "postgresql://localhost:5432/{{ cat_postgres_db }}?user={{ cat_postgres_user }}&password={{ cat_postgres_password }}" - PORT: "{{ port }}" + +######################## +# Setup systemd script # +######################## + +- name: Copy start script + template: + - src: start.sh + dest: "{{ cat_git_destination }}" + owner: cat + group: cat + +- name: Install service file + template: + src: cat.service + dest: /home/{{ cat_user }}/.config/systemd/user/cat.service + owner: cat + group: cat + +- name: Make the user service execute on system start instead of user login + shell: loginctl enable-linger {{ cat_user }} + +- name: Enable cat service + systemd: + enabled: yes + state: started + name: cat + diff --git a/templates/cat.service b/templates/cat.service new file mode 100644 index 0000000..e55c7ea --- /dev/null +++ b/templates/cat.service @@ -0,0 +1,12 @@ +[Unit] +Description=Cuddles and wrong abbreviations +After=network.target + +[Service] +Type=simple +WorkingDirectory={{ cat_git_destination }} +ExecStart={{ cat_git_destination }}/start +Restart=on-failure # or always, on-abort, etc + +[Install] +WantedBy=default.target \ No newline at end of file diff --git a/templates/start.sh b/templates/start.sh new file mode 100644 index 0000000..72298d6 --- /dev/null +++ b/templates/start.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +# Run the java jar + +DATABASE_URL="postgresql://localhost:5432/{{ cat_postgres_db }}?user={{ cat_postgres_user }}&password={{ cat_postgres_password }}" +PORT="{{ port }}" +AUTHORIZE-URI="{{ authorize_uri }}" +ACCESS-TOKEN-URI="{{ access-token-uri }}" +OAUTH-CONSUMER-KEY="{{ OAUTH-CONSUMER-KEY }}" +OAUTH-CONSUMER-SECRET="{{ OAUTH-CONSUMER-SECRET }}" + +java -jar {{ cat_git_destination }}/target/uberjar/cat.jar