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