Skip to content

Commit

Permalink
Merge pull request #291 from haiwen/python-venv-on-deb12_from_crowtrobot
Browse files Browse the repository at this point in the history
Python venv on deb12 from crowtrobot
  • Loading branch information
freeplant authored May 17, 2024
2 parents e13a79c + ae97f4a commit 9455979
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 12 deletions.
118 changes: 113 additions & 5 deletions manual/deploy/start_seafile_at_system_bootup.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,116 @@
# Start Seafile at System Bootup

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

Create systemd service file /etc/systemd/system/seafile.service
* 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**.

Firstly, you should create a script to activate the python virtual environment, which 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
```

### Seafile component

```
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=bash ${seafile_dir}/run_with_venv.sh seafile.sh start
ExecStop=bash ${seafile_dir}/seafile-server-latest/seafile.sh stop
LimitNOFILE=infinity
User=seafile
Group=seafile
[Install]
WantedBy=multi-user.target
```

### Seahub component

```
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=bash ${seafile_dir}/run_with_venv.sh seahub.sh start
ExecStop=bash ${seafile_dir}/seafile-server-latest/seahub.sh stop
User=seafile
Group=seafile
[Install]
WantedBy=multi-user.target
```

### Seafile cli client (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**.


### Seafile component

```
sudo vim /etc/systemd/system/seafile.service
Expand Down Expand Up @@ -31,7 +139,7 @@ WantedBy=multi-user.target
```


## Seahub component
### Seahub component

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

Expand Down Expand Up @@ -61,7 +169,7 @@ WantedBy=multi-user.target
```


## Seafile cli client (optional)
### Seafile cli client (optional)

Create systemd service file /etc/systemd/system/seafile-client.service

Expand Down Expand Up @@ -96,7 +204,7 @@ WantedBy=multi-user.target
```

## Enable service start on system boot
### Enable service start on system boot

```
sudo systemctl enable seafile.service
Expand Down
42 changes: 37 additions & 5 deletions manual/deploy/using_mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ sudo pip3 install --timeout=3600 django==3.2.* future==0.18.* mysqlclient==2.1.*
```

**For Seafile 11.0.x**
**For Seafile 11.0.x (Debian 11, Ubuntu 22.04, etc.)**

```
# Ubuntu 22.04 (almost the same for Ubuntu 20.04 and Debian 11, Debian 10)
Expand All @@ -123,12 +123,35 @@ 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 [Start Seafile at System Bootup](./start_seafile_at_system_bootup.md) 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
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
```

### 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 @@ -141,13 +164,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 Down Expand Up @@ -212,6 +235,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 @@ -362,9 +388,12 @@ To access Seafile's web interface and to create working sharing links without a

## Starting Seafile Server

Run the following commands in `/opt/seafile-server-latest`:
Run the following commands in `/opt/seafile/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 @@ -410,6 +439,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
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ sudo pip3 install --timeout=3600 django==3.2.* future==0.18.* mysqlclient==2.1.*
psd-tools django-pylibmc django_simple_captcha==0.5.20 pycryptodome==3.16.* cffi==1.15.1 lxml
```

**For Seafile 11.0.x**
**For Seafile 11.0.x (Debian 11, Ubuntu 20.04, Centos 8, etc.)**

```
# on Ubuntu 22.04 (on Ubuntu 20.04/Debian 11/Debian 10, it is almost the same)
Expand Down Expand Up @@ -125,6 +125,32 @@ sudo pip3 install --timeout=3600 django==4.2.* future==0.18.* mysqlclient==2.1.*

**Note**: The recommended deployment option for Seafile PE on CentOS/Redhat is [Docker](https://manual.seafile.com/docker/pro-edition/deploy_seafile_pro_with_docker/).

**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 [Start Seafile at System Bootup](../deploy/start_seafile_at_system_bootup.md) 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 python3-ldap libmysqlclient-dev ldap-utils libldap2-dev dnsutils
sudo apt-get install -y memcached libmemcached-dev
sudo apt-get install -y poppler-utils
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 python-ldap==3.4.3 lxml
```

### Installing Java Runtime Environment


Expand Down Expand Up @@ -385,9 +411,12 @@ You need at least setup HTTP to make Seafile's web interface work. This manual p

## Starting Seafile Server

Run the following commands in `/opt/seafile-server-latest`:
Run the following commands in `/opt/seafile/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 # Start Seafile service
./seahub.sh start # Start seahub website, port defaults to 127.0.0.1:8000
```
Expand Down

0 comments on commit 9455979

Please sign in to comment.