× В названия постов этого раздела нужно включать наименование платформы для которой написана инструкция, Например "Ubuntu 12"

Linux sysvinit [Debian/Ubuntu]

9 years 9 months ago - 9 years 9 months ago #284 by zimniy
zimniy created the topic: Linux sysvinit [Debian/Ubuntu]
Подходит для любого линукса, где используются sysvinit-скрипты. Пока это Debian, Ubuntu, Slackware (емнип) и прочие, не включившие systemd по-умолчанию

Для запуска я использовал последнюю версию из GIT. Советую поступить так же - обновлять проще будет.
Системные требования узнаём на сайте, зависимости узнаём там же и ставим.

Для Debian/Ubuntu это будет примерно так:
apt-get install mysql-server python3 python3-mysql-connector

Клонируем репозиторий куда-нибудь в /opt:
cd /opt
git clone https://github.com/mitshel/sopds.git

Создаём пользователя БД и саму БД по официальной инструкции:
mysql -uroot -proot_pass mysql  
mysql > create database if not exists sopds default charset=utf8;  
mysql > grant all on sopds.* to 'sopds'@'localhost' identified by 'sopds';  
mysql > commit;  
mysql > ^C 
cd /opt/sopds
mysql -usopds -psopds sopds < ./db/tables.sql  
mysql -usopds -psopds sopds < ./db/genres.sql

Для того, чтобы успокоить паранойю, будем запускать sopds через sudo. Поставим его, если отсутствует:
apt-get install sudo

Почти всё готово к запуску, прописываем сервис в автозагрузку:
#! /bin/sh
### BEGIN INIT INFO
# Provides:          sopds
# Required-Start:    $local_fs $remote_fs $networking
# Required-Stop:     $local_fs $remote_fs $networking
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Simple OPDS Server
# Description:       Simple OPDS Server.
### END INIT INFO

# Author: Dmitriy Safronov <zimniy@cyberbrain.pw>
#
PATH=/sbin:/usr/sbin:/bin:/usr/bin

# Service description
DESC="Simple OPDS Server"
NAME=sopds

## Defaults
# Drop privileges to
USERNAME=nobody
GROUPNAME=nogroup
# Run in
BASEDIR="/opt/$NAME"

###################################################################

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions

########################################################################

LAUNCHER="sudo -u $USERNAME -g $GROUPNAME -H $BASEDIR/py/sopdsd.py"

########################################################################

# Confiruration & directories creation

pre_config(){
    [ -f "$BASEDIR"/conf/sopds.conf ] && cp -f "$BASEDIR/conf/sopds.conf" "$BASEDIR/conf/sopds.conf.orig"
    [ -h "/etc/$NAME.conf" ] && rm -f "/etc/$NAME.conf"
    [ -f "/etc/$NAME.conf" ] || cp -f "$BASEDIR/conf/sopds.conf.orig" "/etc/$NAME.conf"; ln -fs -T "/etc/$NAME.conf" "$BASEDIR/conf/sopds.conf"
}

pre_start()
{
    install -m 0755 -o $USERNAME -g $GROUPNAME -d "/var/log/$NAME"
    ln -fs -T "/var/log/$NAME" "$BASEDIR/logs"
    install -m 0755 -o $USERNAME -g $GROUPNAME -d "/run/$NAME"
    install -m 0755 -o $USERNAME -g $GROUPNAME -d "/tmp/$NAME"
    pre_config
    chown -R $USERNAME:$GROUPNAME "$BASEDIR"
}

########################################################################

case "$1" in
    start)
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
        pre_start
        $LAUNCHER start
        case "$?" in
            0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
            2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
    stop)
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
        $LAUNCHER stop
        case "$?" in
            0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
            2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
    update)
        cd $BASEDIR
        git pull
        ;;
    *)
        $LAUNCHER $@
        ;;
esac

:
Сохраняем этот скрипт как /etc/init.d/sopds и устанавливаем:
update-rc.d sopds defaults

Копируем конфигурационный файл из /opt/sopds/conf/sopds.conf в /etc/sopds.conf и изменяем под наши нужды.

Запускаем сервис:
service sopds start
или
/etc/init.d/sopds start

P.S.: пользователя, группу и рабочую директорию можно изменить прямо в скрипте, а можно создать файл /etc/default/sopds и переопределить в нём.

And we keep driving into the night
It's a late goodbye, such a late goodbye
Last Edit: 9 years 9 months ago by zimniy. Reason: Указал дистрибутивы

Please Войти or Create an account to join the conversation.

  • zimniy
  • zimniy's Avatar Topic Author
  • Offline
  • Новый участник
  • Новый участник
  • semi-dead
More
9 years 9 months ago #285 by zimniy
zimniy replied the topic: Linux sysvinit [Debian/Ubuntu]
Обратите внимание, что PID'ы должны быть направлены в /run/sopds, а временная диектория - в /tmp/sopds в конфиге самого SOPDS!!!

And we keep driving into the night
It's a late goodbye, such a late goodbye

Please Войти or Create an account to join the conversation.

  • zimniy
  • zimniy's Avatar Topic Author
  • Offline
  • Новый участник
  • Новый участник
  • semi-dead
More
9 years 6 months ago #314 by chuiko
chuiko replied the topic: Linux sysvinit [Debian/Ubuntu]
Можно немного поподробнее про установку имею NAS  WD my cloud  на Debian. Буду очень благодарен за помощь в установке...

Please Войти or Create an account to join the conversation.

  • chuiko
  • chuiko's Avatar
  • Offline
  • Новый участник
  • Новый участник
More
Time to create page: 0.132 seconds