Merge branch 'benchmark-finishing' into 'develop'
[akkoma] / docs / installation / migrating_from_source_otp_en.md
1 # Switching a from-source install to OTP releases
2 ## What are OTP releases?
3 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.
4 ### Can I still run the develop branch if I decide to use them?
5 Yes, we produce builds for every commit in `develop`. However `develop` is considered unstable, please don't use it in production because of faster access to new features, unless you need them as an app developer.
6 ## Why would one want to switch?
7 Benefits of OTP releases over from-source installs include:
8 * **Less space used.** OTP releases come without source code, build tools, have docs and debug symbols stripped from the compiled bytecode and do not cointain tests, docs, revision history.
9 * **Minimal system dependencies.** Excluding the database and reverse proxy, only `curl`, `unzip` and `ncurses` are needed to download and run the release. Because Erlang runtime and Elixir are shipped with Pleroma, one can use the latest BEAM optimizations and Pleroma features, without having to worry about outdated system repos or a missing `erlang-*` package.
10 * **Potentially less bugs and better performance.** This extends on the previous point, because we have control over exactly what gets shipped, we can tweak the VM arguments and forget about weird bugs due to Erlang/Elixir version mismatches.
11 * **Faster and less bug-prone mix tasks.** On a from-source install one has to wait untill a new Pleroma node is started for each mix task and they execute outside of the instance context (for example if a user was deleted via a mix task, the instance will have no knowledge of that and continue to display status count and follows before the cache expires). Mix tasks in OTP releases are executed by calling into a running instance via RPC, which solves both of these problems.
12
13 ### Sounds great, how do I switch?
14 Currently we support Linux machines with GNU (e.g. Debian, Ubuntu) or musl (e.g. Alpine) libc and `x86_64`, `aarch64` or `armv7l` CPUs. If you are unsure, check the [Detecting flavour](otp_en.md#detecting-flavour) section in OTP install guide. If your platform is supported, proceed with the guide, if not check the [My platform is not supported](#my-platform-is-not-supported) section.
15 ### I don't think it is worth the effort, can I stay on a from-source install?
16 Yes, currently there are no plans to deprecate them.
17
18 ### My platform is not supported
19 If you think your platform is a popular choice for running Pleroma instances, or has the potential to become one, you can [file an issue on our Gitlab](https://git.pleroma.social/pleroma/pleroma/issues/new). If not, guides on how to build and update releases by yourself will be available soon.
20 ## Pre-requisites
21 You will be running commands as root. If you aren't root already, please elevate your priviledges by executing `sudo su`/`su`.
22
23 The system needs to have `curl` and `unzip` installed for downloading and unpacking release builds.
24
25 Debian/Ubuntu:
26 ```sh
27 apt install curl unzip
28 ```
29 Alpine:
30 ```
31 apk add curl unzip
32
33 ```
34 ## Moving content out of the application directory
35 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.
36
37 Pleroma should be stopped before proceeding.
38
39 ### Moving uploads/custom public files directory
40 ```sh
41 # Create uploads directory and set proper permissions (skip if using a remote uploader)
42 # Note: It does not have to be `/var/lib/pleroma/uploads`, you can configure it to be something else later
43 mkdir -p /var/lib/pleroma/uploads
44 chown -R pleroma /var/lib/pleroma
45
46 # Create custom public files directory
47 # Note: It does not have to be `/var/lib/pleroma/static`, you can configure it to be something else later
48 mkdir -p /var/lib/pleroma/static
49 chown -R pleroma /var/lib/pleroma
50
51 # If you use the local uploader with default settings your uploads should be located in `~pleroma/uploads`
52 mv ~pleroma/uploads/* /var/lib/pleroma/uploads
53
54 # If you have created the custom public files directory with default settings it should be located in `~pleroma/instance/static`
55 mv ~pleroma/instance/static /var/lib/pleroma/static
56 ```
57
58 ### Moving emoji
59 Assuming you have all emojis in subdirectories of `priv/static/emoji` moving them can be done with
60 ```sh
61 mkdir /var/lib/pleroma/static/emoji
62 ls -d ~pleroma/priv/static/emoji/*/ | xargs -i sh -c 'mv "{}" "/var/lib/pleroma/static/emoji/$(basename {})"'
63 ```
64
65 But, if for some reason you have custom emojis in the root directory you should copy the whole directory instead.
66 ```sh
67 mv ~pleroma/priv/static/emoji /var/lib/pleroma/static/emoji
68 ```
69 and then copy custom emojis to `/var/lib/pleroma/static/emoji/custom`.
70
71 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.
72
73 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).
74
75 ### Moving the config
76 ```sh
77 # Create the config directory
78 # The default path for Pleroma config is /etc/pleroma/config.exs
79 # but it can be set via PLEROMA_CONFIG_PATH environment variable
80 mkdir -p /etc/pleroma
81
82 # Move the config file
83 mv ~pleroma/config/prod.secret.exs /etc/pleroma/config.exs
84
85 # Change `use Mix.Config` at the top to `import Config`
86 $EDITOR /etc/pleroma/config.exs
87 ```
88 ## Installing the release
89 Before proceeding, get the flavour from [Detecting flavour](otp_en.md#detecting-flavour) section in OTP installation guide.
90 ```sh
91 # Delete all files in pleroma user's directory
92 rm -r ~pleroma/*
93
94 # Set the flavour environment variable to the string you got in Detecting flavour section.
95 # For example if the flavour is `arm64-musl` the command will be
96 export FLAVOUR="arm64-musl"
97
98 # Clone the release build into a temporary directory and unpack it
99 # Replace `stable` with `unstable` if you want to run the unstable branch
100 su pleroma -s $SHELL -lc "
101 curl 'https://git.pleroma.social/api/v4/projects/2/jobs/artifacts/stable/download?job=$FLAVOUR' -o /tmp/pleroma.zip
102 unzip /tmp/pleroma.zip -d /tmp/
103 "
104
105 # Move the release to the home directory and delete temporary files
106 su pleroma -s $SHELL -lc "
107 mv /tmp/release/* ~pleroma/
108 rmdir /tmp/release
109 rm /tmp/pleroma.zip
110 "
111
112 # Start the instance to verify that everything is working as expected
113 su pleroma -s $SHELL -lc "./bin/pleroma daemon"
114
115 # Wait for about 20 seconds and query the instance endpoint, if it shows your uri, name and email correctly, you are configured correctly
116 sleep 20 && curl http://localhost:4000/api/v1/instance
117
118 # Stop the instance
119 su pleroma -s $SHELL -lc "./bin/pleroma stop"
120 ```
121
122 ## Setting up a system service
123 OTP releases have different service files than from-source installs so they need to be copied over again.
124
125 **Warning:** The service files assume pleroma user's home directory is `/opt/pleroma`, please make sure all paths fit your installation.
126
127 Debian/Ubuntu:
128 ```sh
129 # Copy the service into a proper directory
130 cp ~pleroma/installation/pleroma.service /etc/systemd/system/pleroma.service
131
132 # Reload service files
133 systemctl daemon-reload
134
135 # Reenable pleroma to start on boot
136 systemctl reenable pleroma
137
138 # Start pleroma
139 systemctl start pleroma
140 ```
141
142 Alpine:
143 ```sh
144 # Copy the service into a proper directory
145 cp -f ~pleroma/installation/init.d/pleroma /etc/init.d/pleroma
146
147 # Start pleroma
148 rc-service pleroma start
149 ```
150 ## Running mix tasks
151 Refer to [Running mix tasks](otp_en.md#running-mix-tasks) section from OTP release installation guide.
152 ## Updating
153 Refer to [Updating](otp_en.md#updating) section from OTP release installation guide.