Merge branch 'develop' into feature/gen-magic
[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 === "Alpine"
12 ```sh
13 apk add curl unzip
14 ```
15
16 === "Debian/Ubuntu"
17 ```sh
18 apt install curl unzip
19 ```
20
21 ## Moving content out of the application directory
22 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.
23
24 Pleroma should be stopped before proceeding.
25
26 ### Moving uploads/custom public files directory
27
28 ```sh
29 # Create uploads directory and set proper permissions (skip if using a remote uploader)
30 # Note: It does not have to be `/var/lib/pleroma/uploads`, you can configure it to be something else later
31 mkdir -p /var/lib/pleroma/uploads
32 chown -R pleroma /var/lib/pleroma
33
34 # Create custom public files directory
35 # Note: It does not have to be `/var/lib/pleroma/static`, you can configure it to be something else later
36 mkdir -p /var/lib/pleroma/static
37 chown -R pleroma /var/lib/pleroma
38
39 # If you use the local uploader with default settings your uploads should be located in `~pleroma/uploads`
40 mv ~pleroma/uploads/* /var/lib/pleroma/uploads
41
42 # If you have created the custom public files directory with default settings it should be located in `~pleroma/instance/static`
43 mv ~pleroma/instance/static /var/lib/pleroma/static
44 ```
45
46 ### Moving emoji
47 Assuming you have all emojis in subdirectories of `priv/static/emoji` moving them can be done with
48 ```sh
49 mkdir /var/lib/pleroma/static/emoji
50 ls -d ~pleroma/priv/static/emoji/*/ | xargs -i sh -c 'mv "{}" "/var/lib/pleroma/static/emoji/$(basename {})"'
51 ```
52
53 But, if for some reason you have custom emojis in the root directory you should copy the whole directory instead.
54 ```sh
55 mv ~pleroma/priv/static/emoji /var/lib/pleroma/static/emoji
56 ```
57 and then copy custom emojis to `/var/lib/pleroma/static/emoji/custom`.
58
59 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.
60
61 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).
62
63 ### Moving the config
64 ```sh
65 # Create the config directory
66 # The default path for Pleroma config is /etc/pleroma/config.exs
67 # but it can be set via PLEROMA_CONFIG_PATH environment variable
68 mkdir -p /etc/pleroma
69
70 # Move the config file
71 mv ~pleroma/config/prod.secret.exs /etc/pleroma/config.exs
72
73 # Change `use Mix.Config` at the top to `import Config`
74 $EDITOR /etc/pleroma/config.exs
75 ```
76 ## Installing the release
77 Before proceeding, get the flavour from [Detecting flavour](otp_en.md#detecting-flavour) section in OTP installation guide.
78 ```sh
79 # Delete all files in pleroma user's directory
80 rm -r ~pleroma/*
81
82 # Set the flavour environment variable to the string you got in Detecting flavour section.
83 # For example if the flavour is `amd64-musl` the command will be
84 export FLAVOUR="amd64-musl"
85
86 # Clone the release build into a temporary directory and unpack it
87 # Replace `stable` with `unstable` if you want to run the unstable branch
88 su pleroma -s $SHELL -lc "
89 curl 'https://git.pleroma.social/api/v4/projects/2/jobs/artifacts/stable/download?job=$FLAVOUR' -o /tmp/pleroma.zip
90 unzip /tmp/pleroma.zip -d /tmp/
91 "
92
93 # Move the release to the home directory and delete temporary files
94 su pleroma -s $SHELL -lc "
95 mv /tmp/release/* ~pleroma/
96 rmdir /tmp/release
97 rm /tmp/pleroma.zip
98 "
99
100 # Start the instance to verify that everything is working as expected
101 su pleroma -s $SHELL -lc "./bin/pleroma daemon"
102
103 # Wait for about 20 seconds and query the instance endpoint, if it shows your uri, name and email correctly, you are configured correctly
104 sleep 20 && curl http://localhost:4000/api/v1/instance
105
106 # Stop the instance
107 su pleroma -s $SHELL -lc "./bin/pleroma stop"
108 ```
109
110 ## Setting up a system service
111 OTP releases have different service files than from-source installs so they need to be copied over again.
112
113 **Warning:** The service files assume pleroma user's home directory is `/opt/pleroma`, please make sure all paths fit your installation.
114
115 === "Alpine"
116 ```sh
117 # Copy the service into a proper directory
118 cp -f ~pleroma/installation/init.d/pleroma /etc/init.d/pleroma
119
120 # Start pleroma
121 rc-service pleroma start
122 ```
123
124 === "Debian/Ubuntu"
125 ```sh
126 # Copy the service into a proper directory
127 cp ~pleroma/installation/pleroma.service /etc/systemd/system/pleroma.service
128
129 # Reload service files
130 systemctl daemon-reload
131
132 # Reenable pleroma to start on boot
133 systemctl reenable pleroma
134
135 # Start pleroma
136 systemctl start pleroma
137 ```
138
139 ## Running mix tasks
140 Refer to [Running mix tasks](otp_en.md#running-mix-tasks) section from OTP release installation guide.
141 ## Updating
142 Refer to [Updating](otp_en.md#updating) section from OTP release installation guide.