add systemd service and start script
This commit is contained in:
parent
e5174cb1c6
commit
2bfbcf2495
5 changed files with 59 additions and 9 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
.idea/
|
|
@ -1,7 +1,6 @@
|
||||||
---
|
---
|
||||||
# defaults file for .
|
# defaults file for .
|
||||||
cat_user: cat
|
cat_user: cat
|
||||||
cat_homedir: cat
|
|
||||||
|
|
||||||
cat_postgres_db: cat
|
cat_postgres_db: cat
|
||||||
cat_postgres_user: cat_user
|
cat_postgres_user: cat_user
|
||||||
|
@ -9,6 +8,11 @@ cat_postgres_user: cat_user
|
||||||
# sensitive info
|
# sensitive info
|
||||||
cat_postgres_password: "{{ vault_cat_postgres_password }}"
|
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
|
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"
|
|
@ -73,10 +73,31 @@
|
||||||
args:
|
args:
|
||||||
chdir: "{{ cat_git_destination }}"
|
chdir: "{{ cat_git_destination }}"
|
||||||
|
|
||||||
- name: Run jar
|
|
||||||
become: yes
|
########################
|
||||||
become_user: "{{ cat_user }}"
|
# Setup systemd script #
|
||||||
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 }}"
|
- name: Copy start script
|
||||||
PORT: "{{ port }}"
|
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
|
||||||
|
|
||||||
|
|
12
templates/cat.service
Normal file
12
templates/cat.service
Normal file
|
@ -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
|
12
templates/start.sh
Normal file
12
templates/start.sh
Normal file
|
@ -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
|
Loading…
Reference in a new issue