Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add steps to create and use python venv #237

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 103 additions & 2 deletions manual/deploy/start_seafile_at_system_bootup.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,115 @@
# Start Seafile at System Bootup

## For systems running systemd
## For systems running systemd and python virtual environments

* For example Debian 8 and newer, Linux Ubuntu 15.04 and newer
* For example Debian 12
Create systemd service files, change **${seafile_dir}** to your
**seafile** installation location and **seafile** to user, who runs
**seafile** (if appropriate). Then you need to reload systemd's daemons:
**systemctl daemon-reload**.

### Create the script to activate the python virtual environment
This file goes in the **${seafile_dir}** directory. Put another way, it does not go in "seafile-server-latest", but the directory above that. Throughout this manual the examples use /opt/seafile for this directory, but you might have chosen to use a different directory.

```
sudo vim /opt/seafile/run_with_venv.sh
```

The content of the file is:

```
#!/bin/bash
# Activate the python virtual environment (venv) before starting one of the seafile scripts

dir_name="$(dirname $0)"
source "${dir_name}/python-venv/bin/activate"
script="$1"
shift 1

echo "${dir_name}/seafile-server-latest/${script}" "$@"
"${dir_name}/seafile-server-latest/${script}" "$@"
```
make this script executable
```
sudo chmod 755 /opt/seafile/run_with_venv.sh
```

### Create systemd service file /etc/systemd/system/seafile.service

```
sudo vim /etc/systemd/system/seafile.service

```

The content of the file is:

```
[Unit]
Description=Seafile
# add mysql.service or postgresql.service depending on your database to the line below
After=network.target

[Service]
Type=forking
ExecStart=${seafile_dir}/run_with_venv.sh seafile.sh start
ExecStop=${seafile_dir}/seafile-server-latest/seafile.sh stop
LimitNOFILE=infinity
User=seafile
Group=seafile

[Install]
WantedBy=multi-user.target

```

### Create systemd service file /etc/systemd/system/seahub.service

```
sudo vim /etc/systemd/system/seahub.service

```

The content of the file is (please dont forget to change it if you want to run fastcgi):

```
[Unit]
Description=Seafile hub
After=network.target seafile.service

[Service]
Type=forking
# change start to start-fastcgi if you want to run fastcgi
ExecStart=${seafile_dir}/run_with_venv.sh seahub.sh start
ExecStop=${seafile_dir}/seafile-server-latest/seahub.sh stop
User=seafile
Group=seafile

[Install]
WantedBy=multi-user.target

```

### Create systemd service file /etc/systemd/system/seafile-client.service (optional)
The client doesn't require any packages from pip, so this is the same as for systems without pythong virtual environments. See that section below.

### Enable service start on system boot

```
sudo systemctl enable seafile.service
sudo systemctl enable seahub.service
sudo systemctl enable seafile-client.service # optional
```

## For systems running systemd without python virtual environment

* For example Debian 8 through Debian 11, Linux Ubuntu 15.04 and newer

Create systemd service files, change **${seafile_dir}** to your
**seafile** installation location and **seafile** to user, who runs
**seafile** (if appropriate). Then you need to reload systemd's daemons:
**systemctl daemon-reload**.


### Create systemd service file /etc/systemd/system/seafile.service

```
Expand Down
44 changes: 41 additions & 3 deletions manual/deploy/using_mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,25 @@ sudo pip3 install --timeout=3600 django==4.2.* future==0.18.* mysqlclient==2.1.*

```

**For Seafile 11.0.x on Debian 12**

Debian 12 (and most newer distributions) are now discouraging system-wide installation of python modules with pip. It is preferred now to install modules into a virtual environment which keeps them separate from the files installed by the system package manager, and enables diffeerent versions to be installed for different applications. With these python virtual environments (venv for short) to work, you have to activate the venv to make the packages installed in it available to the programs you run. That is done here with "source python-venv/bin/activate". Also be aware of the changes in the "Start Seafile at System Bootup" section later in this manual.

```
# Debian 12 (almost the same as Debian 11, but with python virtual environments to keep pip installs from conflicting with apt-get installs)
sudo apt-get update
sudo apt-get install -y python3 python3-dev python3-setuptools python3-pip libmariadb-dev-compat ldap-utils libldap2-dev python3.11-venv
sudo apt-get install -y memcached libmemcached-dev

## The pip installations will be done below, in the python virtual environment section
```

### Creating the program directory

The standard directory for Seafile's program files is `/opt/seafile`. Create this directory and change into it:

```
mkdir /opt/seafile
sudo mkdir /opt/seafile
cd /opt/seafile
```

Expand All @@ -129,13 +142,13 @@ It is good practice not to run applications as root.
Create a new user and follow the instructions on the screen:

```
adduser seafile
sudo adduser seafile
```

Change ownership of the created directory to the new user:

```
chown -R seafile: /opt/seafile
sudo chown -R seafile: /opt/seafile
```

All the following steps are done as user seafile.
Expand All @@ -146,6 +159,22 @@ Change to user seafile:
su seafile
```

### Create the python virtual environment and install dependencies with pip (Debian 12)
For newer systems like Debian 12 where we didn't install the depeneencies with pip above, we will install them here. Older systems can skip this step.
```
cd /opt/seafile

# create the vitual environment in the python-venv directory
python3 -m venv python-venv

# activate the venv
source python-venv/bin/activate
# Notice that this will usually change your prompt so you know the venv is active

# install packages into the active venv with pip (sudo isn't needed because this is installing in the venv, not system-wide).
pip3 install --timeout=3600 django==4.2.* future==0.18.* mysqlclient==2.1.* pymysql pillow==10.0.* pylibmc captcha==0.4 markupsafe==2.0.1 jinja2 sqlalchemy==2.0.18 psd-tools django-pylibmc django_simple_captcha==0.5.* djangosaml2==1.5.* pysaml2==7.2.* pycryptodome==3.16.* cffi==1.15.1 lxml python-ldap==3.4.3
```

### Downloading the install package

Download the install package from the [download page](https://www.seafile.com/en/download/) on Seafile's website using wget.
Expand Down Expand Up @@ -200,6 +229,9 @@ Note: While ccnet server was merged into the seafile-server in Seafile 8.0, the
Run the script as user seafile:

```
# For installations using python virtual environment, activate it if it isn't already active
source python-venv/bin/activate

cd seafile-server-8.0.4
./setup-seafile-mysql.sh

Expand Down Expand Up @@ -316,6 +348,9 @@ To access Seafile's web interface and to create working sharing links without a
Run the following commands in `/opt/seafile-server-latest`:

```
# For installations using python virtual environment, activate it if it isn't already active
source python-venv/bin/activate

./seafile.sh start # starts seaf-server
./seahub.sh start # starts seahub

Expand Down Expand Up @@ -361,6 +396,9 @@ pkill -f "seahub"
### Restarting

```
# For installations using python virtual environment, activate it if it isn't already active
source python-venv/bin/activate

./seafile.sh restart
./seahub.sh restart

Expand Down