Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Who can share start/stop script for SysVinit: /etc/init.d/radicale #737

Closed
cmonty14 opened this issue Oct 31, 2017 · 6 comments
Closed

Who can share start/stop script for SysVinit: /etc/init.d/radicale #737

cmonty14 opened this issue Oct 31, 2017 · 6 comments

Comments

@cmonty14
Copy link

Hi!
Can you share a configuration for running Radicale as a SysVinit service?
I managed the installation in LXC with Alpine Linux and the application is running.

THX

@cmonty14 cmonty14 changed the title Start/stop script for SysVinit Who can share start/stop script for SysVinit: /etc/init.d/radicale Nov 14, 2017
@frasten
Copy link

frasten commented Dec 21, 2017

I'm using this:

[Unit]
Description=A simple CalDAV (calendar) and CardDAV (contact) server
After=network.target
Requires=network.target

[Service]
ExecStart=/usr/bin/env python3 -m radicale
Restart=on-failure
User=radicale
# Deny other users access to the calendar data
UMask=0027
# Optional security settings
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true
PrivateDevices=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectControlGroups=true
NoNewPrivileges=true
ReadWritePaths=/var/lib/radicale/collections

[Install]
WantedBy=multi-user.target

@lanodan
Copy link

lanodan commented Dec 30, 2017

@frasten This is a systemd service file, Alpine Linux doesn’t have systemd…

As OpenRC is used by many non-SystemD distros, including Alpine I’ll take that you’d probably prefer OpenRC instead of actual SysVinit. (as they often end up with ~200 lines)
There is https://gitweb.gentoo.org/repo/gentoo.git/tree/www-apps/radicale/files/radicale.init.d for radicale 1.x.x

And I’m using this script for radicale 2.x.x

#!/sbin/openrc-run
#command="/srv/radicale/Radicale/radicale.py"
command="python"
command_args="-m radicale"
command_user="radicale"
command_background="yes"
pidfile="/var/run/radicale.pid"
description="A Free and Open-Source CalDAV and CardDAV Server"

depend() {
        need localmount
        need net
}

@Mikmu
Copy link

Mikmu commented Jan 10, 2018 via email

@dr0i
Copy link

dr0i commented Jul 28, 2021

This is my imperfect script at /etc/init.d/radicale:

#! /bin/sh

### BEGIN INIT INFO
# Provides:          radicale
# Required-Start:    $local_fs
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Provides webDav calendar
# Description: Provides radicale, a webDav server implementation
### END INIT INFO

N=/etc/init.d/radicale

set -e

case "$1" in
  start)
        python3 -m radicale --storage-filesystem-folder=/var/lib/radicale/collections >/dev/null 2>&1 &
        ;;
  stop)
        pid=$(ps -ef | grep '[p]ython3 -m radicale' | awk '{ print $2 }')
        kill $pid
        sleep 2
        echo "radicale killed"
        ;;
  status)
        pid=$(ps -ef | grep '[p]ython3 -m radicale' | awk '{ print $2 }')
        if [ -e /proc/${pid} -a -e /proc/${pid}/exe ]; then
                echo "radicale is running with PID $pid"
        else
                echo "radicale is not running"
        fi
        ;;
  *)
        echo "Usage: $N {start|stop|status}" >&2
        exit 1
        ;;
esac

exit 0

Invoke like: service radicale start.

@jnr2820
Copy link

jnr2820 commented Oct 19, 2021

Hi @dr0i ,

Thanks for posting this. Yours worked for me in a pinch.
I opened a new issue for the one that ships with the Radicale3 '.deb' not working: #1188
I'm hoping to get help/rewrite on the official script.

@pbiering pbiering closed this as completed Mar 2, 2024
@ecxod
Copy link

ecxod commented Jan 21, 2025

My Radicale is running Gunicorn, and the above script wasn't working properly because I'm on a Raspberry, and the main cause of the crash is that the usb raid it's running on is somehow being unmounted.
Starting from @dr0i's code, I created a script that uses netstat to check the status and mountpoint to detect the mount status, and reboot.

#! /bin/sh

### BEGIN INIT INFO
# Provides:          radicale
# Required-Start:    $local_fs
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Provides webDav calendar
# Description: Provides radicale, a webDav server implementation
### END INIT INFO

N=/etc/init.d/radicale

set -e

case "$1" in
  start)
        # Prüfen, ob die Platte richtig eingehängt ist
        if mountpoint -q /raid; then
            # Radicale starten
            echo "started radicale"
            su - radicale -c "
                cd /raid/home/radicale &&
                source virtual/bin/activate &&
                gunicorn -D --bind '192.168.178.6:5232' \
                            --env='RADICALE_CONFIG=~/.config/radicale/config' \
                            --workers 2 radicale
            "
        else
            echo "Verzeichnis nicht eingehängt. Versuche, es neu einzuhängen..."
            # Check if the disk is mounted correctly this time, if not reboot
            mount -a
            echo "Mountpoit eingehongen, bitte erneut versuchen zu starten"
            sleep 2
            if mountpoint -q /raid; then
                # Radicale starten
                echo "starte radicale"
                su - radicale -c "
                    cd /raid/home/radicale &&
                    source virtual/bin/activate &&
                    gunicorn -D --bind '192.168.178.6:5232' \
                                --env='RADICALE_CONFIG=~/.config/radicale/config' \
                                --workers 2 radicale
                "
            else
                echo "Directory still not mounted. Now trying to restart Raspberry..."
                reboot -h now
            fi
        fi
        ;;
  stop)
        # Terminate any hanging processes
        pkill -P1 gunicorn
        sleep 2
        echo "radicale killed"
        ;;
  status)
        # Using netstat to find the PID of the process running on port 5232
        pid=$(netstat -tlp 2>/dev/null | awk '/:5232/ {split($NF, a, "/"); print a[1]}')
        if [ -n "$pid" ] && [ -e /proc/${pid} ]; then
            echo "Radicale is running with PID $pid"
        else
            echo "Radicale is not running"
        fi
        ;;
      *)
        echo "Usage: $N {start|stop|status}" >&2
        exit 1
        ;;
esac

exit 0

Have fun

@Kozea Kozea locked and limited conversation to collaborators Jan 21, 2025
@pbiering pbiering converted this issue into discussion #1685 Jan 21, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

9 participants