Merge branch 'stable' into release/2.0.0
[akkoma] / docs / installation / migrating_from_source_otp_en.md
1 # Switching a from-source install to OTP releases
2
3 ## What are OTP releases?
4 OTP releases are as close as you can get to binary releases with Erlang/Elixir. The release is self-contained, and provides everything needed to boot it, it is easily administered via the provided shell script to open up a remote console, start/stop/restart the release, start in the background, send remote commands, and more.
5
6 ## Pre-requisites
7 You will be running commands as root. If you aren't root already, please elevate your priviledges by executing `sudo su`/`su`.
8
9 The system needs to have `curl` and `unzip` installed for downloading and unpacking release builds.
10
11 ```sh tab="Alpine"
12 apk add curl unzip
13 ```
14
15 ```sh tab="Debian/Ubuntu"
16 apt install curl unzip
17 ```
18
19 ## Moving content out of the application directory
20 When using OTP releases the application directory changes with every version so it would be a bother to keep content there (and also dangerous unless `--no-rm` option is used when updating). Fortunately almost all paths in Pleroma are configurable, so it is possible to move them out of there.
21
22 Pleroma should be stopped before proceeding.
23
24 ### Moving uploads/custom public files directory
25
26 ```sh
27 # Create uploads directory and set proper permissions (skip if using a remote uploader)
28 # Note: It does not have to be `/var/lib/pleroma/uploads`, you can configure it to be something else later
29 mkdir -p /var/lib/pleroma/uploads
30 chown -R pleroma /var/lib/pleroma
31
32 # Create custom public files directory
33 # Note: It does not have to be `/var/lib/pleroma/static`, you can configure it to be something else later
34 mkdir -p /var/lib/pleroma/static
35 chown -R pleroma /var/lib/pleroma
36
37 # If you use the local uploader with default settings your uploads should be located in `~pleroma/uploads`
38 mv ~pleroma/uploads/* /var/lib/pleroma/uploads
39
40 # If you have created the custom public files directory with default settings it should be located in `~pleroma/instance/static`
41 mv ~pleroma/instance/static /var/lib/pleroma/static
42 ```
43
44 ### Moving emoji
45 Assuming you have all emojis in subdirectories of `priv/static/emoji` moving them can be done with
46 ```sh
47 mkdir /var/lib/pleroma/static/emoji
48 ls -d ~pleroma/priv/static/emoji/*/ | xargs -i sh -c 'mv "{}" "/var/lib/pleroma/static/emoji/$(basename {})"'
49 ```
50
51 But, if for some reason you have custom emojis in the root directory you should copy the whole directory instead.
52 ```sh
53 mv ~pleroma/priv/static/emoji /var/lib/pleroma/static/emoji
54 ```
55 and then copy custom emojis to `/var/lib/pleroma/static/emoji/custom`.
56
57 This is needed because storing custom emojis in the root directory is deprecated, but if you just move them to `/var/lib/pleroma/static/emoji/custom` it will break emoji urls on old posts.
58
59 Note that globs have been replaced with `pack_extensions`, so if your emojis are not in png/gif you should [modify the default value](../configuration/cheatsheet.md#emoji).
60
61 ### Moving the config
62 ```sh
63 # Create the config directory
64 # The default path for Pleroma config is /etc/pleroma/config.exs
65 # but it can be set via PLEROMA_CONFIG_PATH environment variable
66 mkdir -p /etc/pleroma
67
68 # Move the config file
69 mv ~pleroma/config/prod.secret.exs /etc/pleroma/config.exs
70
71 # Change `use Mix.Config` at the top to `import Config`
72 $EDITOR /etc/pleroma/config.exs
73 ```
74 ## Installing the release
75 Before proceeding, get the flavour from [Detecting flavour](otp_en.md#detecting-flavour) section in OTP installation guide.
76 ```sh
77 # Delete all files in pleroma user's directory
78 rm -r ~pleroma/*
79
80 # Set the flavour environment variable to the string you got in Detecting flavour section.
81 # For example if the flavour is `amd64-musl` the command will be
82 export FLAVOUR="amd64-musl"
83
84 # Clone the release build into a temporary directory and unpack it
85 # Replace `stable` with `unstable` if you want to run the unstable branch
86 su pleroma -s $SHELL -lc "
87 curl 'https://git.pleroma.social/api/v4/projects/2/jobs/artifacts/stable/download?job=$FLAVOUR' -o /tmp/pleroma.zip
88 unzip /tmp/pleroma.zip -d /tmp/
89 "
90
91 # Move the release to the home directory and delete temporary files
92 su pleroma -s $SHELL -lc "
93 mv /tmp/release/* ~pleroma/
94 rmdir /tmp/release
95 rm /tmp/pleroma.zip
96 "
97
98 # Start the instance to verify that everything is working as expected
99 su pleroma -s $SHELL -lc "./bin/pleroma daemon"
100
101 # Wait for about 20 seconds and query the instance endpoint, if it shows your uri, name and email correctly, you are configured correctly
102 sleep 20 && curl http://localhost:4000/api/v1/instance
103
104 # Stop the instance
105 su pleroma -s $SHELL -lc "./bin/pleroma stop"
106 ```
107
108 ## Setting up a system service
109 OTP releases have different service files than from-source installs so they need to be copied over again.
110
111 **Warning:** The service files assume pleroma user's home directory is `/opt/pleroma`, please make sure all paths fit your installation.
112
113 ```sh tab="Alpine"
114 # Copy the service into a proper directory
115 cp -f ~pleroma/installation/init.d/pleroma /etc/init.d/pleroma
116
117 # Start pleroma
118 rc-service pleroma start
119 ```
120
121 ```sh tab="Debian/Ubuntu"
122 # Copy the service into a proper directory
123 cp ~pleroma/installation/pleroma.service /etc/systemd/system/pleroma.service
124
125 # Reload service files
126 systemctl daemon-reload
127
128 # Reenable pleroma to start on boot
129 systemctl reenable pleroma
130
131 # Start pleroma
132 systemctl start pleroma
133 ```
134
135 ## Running mix tasks
136 Refer to [Running mix tasks](otp_en.md#running-mix-tasks) section from OTP release installation guide.
137 ## Updating
138 Refer to [Updating](otp_en.md#updating) section from OTP release installation guide.