Skip to content

Commit 6e64720

Browse files
committed
Added systemd service to run the explorer.
1 parent 44c81a1 commit 6e64720

6 files changed

Lines changed: 62 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ config-files/*.last_processed_batch.json
1616
nonce_*.bin
1717

1818
infra/ansible/playbooks/ini/**.ini
19+
infra/ansible/playbooks/files/**.pem

infra/ansible/playbooks/explorer.yaml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,23 @@
3636
ansible.builtin.git:
3737
repo: https://github.com/yetanotherco/aligned_layer
3838
dest: "/home/{{ ansible_user }}/repos/explorer/aligned_layer"
39-
version: explorer-ssl
4039
update: yes
4140

41+
- name: Create .ssl directory
42+
file:
43+
path: /home/{{ ansible_user }}/.ssl/
44+
state: directory
45+
46+
- name: Upload SSL key to server (infra/ansible/playbooks/files/key.pem)
47+
copy:
48+
src: key.pem
49+
dest: /home/{{ ansible_user }}/.ssl/key.pem
50+
51+
- name: Upload SSL certificate to server (infra/ansible/playbooks/files/cert.pem)
52+
copy:
53+
src: cert.pem
54+
dest: /home/{{ ansible_user }}/.ssl/cert.pem
55+
4256
tasks:
4357
- name: Add environment file for Explorer
4458
template:
@@ -56,6 +70,9 @@
5670
DB_HOST: "{{ lookup('ini', 'DB_HOST file=ini/config-explorer.ini') }}"
5771
TRACKER_API_URL: "{{ lookup('ini', 'TRACKER_API_URL file=ini/config-explorer.ini') }}"
5872
SECRET_KEY_BASE: "{{ lookup('ini', 'SECRET_KEY_BASE file=ini/config-explorer.ini') }}"
73+
KEYFILE_PATH: "{{ lookup('ini', 'KEYFILE_PATH file=ini/config-explorer.ini') }}"
74+
CERTFILE_PATH: "{{ lookup('ini', 'CERTFILE_PATH file=ini/config-explorer.ini') }}"
75+
5976

6077
- name: Build the explorer release
6178
args:
@@ -82,4 +99,23 @@
8299
vars:
83100
ansible_ssh_user: "{{ admin_user }}"
84101

85-
# TODO: add systemd service
102+
- name: Create .env for Explorer systemd service
103+
shell: cat /home/{{ ansible_user }}/repos/explorer/aligned_layer/explorer/.env | sed 's/export //g' > /home/{{ ansible_user }}/config/.env.explorer
104+
105+
- name: Create systemd services directory
106+
file:
107+
path: "/home/{{ ansible_user }}/.config/systemd/user/"
108+
state: directory
109+
110+
- name: Add service to systemd
111+
template:
112+
src: services/explorer.service.j2
113+
dest: "/home/{{ ansible_user }}/.config/systemd/user/explorer.service"
114+
force: no
115+
116+
- name: Start explorer service
117+
systemd_service:
118+
name: explorer
119+
state: started
120+
enabled: true
121+
scope: user

infra/ansible/playbooks/ini/config-explorer.ini.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ DB_PASS=
1010
DB_HOST=
1111
TRACKER_API_URL=
1212
SECRET_KEY_BASE=
13+
KEYFILE_PATH=
14+
CERTFILE_PATH=

infra/ansible/playbooks/postgres.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@
5555
DB_PASS: "{{ lookup('ini', 'DB_PASS', file=ini_file) }}"
5656
DB_NAME: "{{ lookup('ini', 'DB_NAME', file=ini_file) }}"
5757
ignore_errors: true
58+
no_log: true

infra/ansible/playbooks/templates/explorer/explorer_env.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export ENVIRONMENT={{ ENVIRONMENT }}
33
export ALIGNED_CONFIG_FILE={{ ALIGNED_CONFIG_FILE }}
44
export PHX_HOST={{ PHX_HOST }}
55
export ELIXIR_HOSTNAME={{ ELIXIR_HOSTNAME }}
6+
export PHX_SERVER=true
67

78
# Database
89
export DB_NAME={{ DB_NAME }}
@@ -13,3 +14,6 @@ export DB_HOST={{ DB_HOST }}
1314
# Tracker API
1415
export TRACKER_API_URL={{ TRACKER_API_URL }}
1516
export SECRET_KEY_BASE={{ SECRET_KEY_BASE }}
17+
18+
export KEYFILE_PATH={{ KEYFILE_PATH }}
19+
export CERTFILE_PATH={{ CERTFILE_PATH }}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[Unit]
2+
Description=Explorer
3+
After=network.target
4+
5+
[Service]
6+
Type=simple
7+
WorkingDirectory=/home/{{ ansible_user }}/repos/explorer/aligned_layer/explorer
8+
EnvironmentFile=/home/{{ ansible_user }}/config/.env.explorer
9+
ExecStart=/home/{{ ansible_user }}/repos/explorer/aligned_layer/explorer/_build/prod/rel/explorer/bin/explorer start
10+
Restart=always
11+
RestartSec=1
12+
StartLimitBurst=100
13+
LimitNOFILE=100000
14+
15+
[Install]
16+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)