@xataz
Bon voici mon résultats de ma première essais pour mettre headphones en multi-utilisateurs
ont commence par installer ceci
apt-get -y update
apt-get -y install git git-core
On ajoute notre utilisateur headphones:
useradd --no-create-home headphones_daniel
passwd headphones_daniel
On se mets dans /opt et on télécharge Headphones:
cd /opt
git clone https://github.com/rembo10/headphones.git
On change les permissions :
chown -R headphones:nogroup /opt/headphones
ont le lance avec
cd /opt/headphones
python Headphones.py
On crée le fichier de configuration:
nano /etc/default/headphones
inscrit ca dedans
HP_USER=headphones #$RUN_AS, username to run headphones under, the default is headphones
HP_HOME=/opt/headphones #$APP_PATH, the location of Headphones.py, the default is /opt/headphones
HP_DATA=/opt/headphones #$DATA_DIR, the location of headphones.db, cache, logs, the default is /opt/headphones
Mise en place du script de demarrage
cp /opt/headphones/init-scripts/init.ubuntu /etc/init.d/headphones_daniel
chmod +x /etc/init.d/headphones_daniel
On mets le demarrage automatique pour notre script
update-rc.d headphones_daniel defaults
update-rc.d headphones_daniel enable
Le multi-utilisateurs je crois que c'est à cette étape que je doit le faire
nano /etc/init.d/headphones_daniel
j'ajoute ça dedans
#!/bin/sh
## HP_USER= #$RUN_AS, username to run headphones under, the default is headphones
## HP_HOME= #$APP_PATH, the location of Headphones.py, the default is /opt/headphones
## HP_DATA= #$DATA_DIR, the location of headphones.db, cache, logs, the default is /opt/headphones
## HP_PIDFILE= #$PID_FILE, the location of headphones.pid, the default is /var/run/headphones/headphones.pid
## PYTHON_BIN= #$DAEMON, the location of the python binary, the default is /usr/bin/python
## HP_OPTS= #$EXTRA_DAEMON_OPTS, extra cli option for headphones, i.e. " --config=/home/headphones/config.ini"
## HP_PORT= #$PORT_OPTS, hardcoded port for the webserver, overrides value in config.ini
##
## EXAMPLE if want to run as different user
## add HP_USER=username to /etc/default/headphones
## otherwise default headphones is used
#
### BEGIN INIT INFO
# Provides: headphones_daniel
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Should-Start: $NetworkManager
# Should-Stop: $NetworkManager
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts instance of Headphones
# Description: starts instance of Headphones using start-stop-daemon
### END INIT INFO
HP_USER=daniel
HP_INSTALL=/opt/headphones
# Pas touche
NAME=headphones_$HP_USER
DESC="Headphones pour $HP_USER"
HP_HOME=$HP_INSTALL
HP_DATA=$HP_HOME/data/$HP_USER
HP_OPTS=--config=$HP_DATA/config.ini
HP_PIDFILE=$HP_DATA/headphones.pid
# App name
SETTINGS_LOADED=FALSE
. /lib/lsb/init-functions
# Source Headphones configuration
if [ -f /etc/default/headphones ]; then
SETTINGS=/etc/default/headphones
else
log_warning_msg "/etc/default/headphones not found using default settings.";
fi
check_retval() {
if [ $? -eq 0 ]; then
log_end_msg 0
return 0
else
log_end_msg 1
exit 1
fi
}
load_settings() {
if [ $SETTINGS_LOADED != "TRUE" ]; then
. $SETTINGS
## The defaults
# Run as username
RUN_AS=${HP_USER-headphones}
# Path to app HP_HOME=path_to_app_Headphones.py
APP_PATH=${HP_HOME-/opt/headphones}
# Data directory where headphones.db, cache and logs are stored
DATA_DIR=${HP_DATA-/opt/headphones}
# Path to store PID file
PID_FILE=${HP_PIDFILE-/var/run/headphones/headphones.pid}
# Path to python bin
DAEMON=${PYTHON_BIN-/usr/bin/python}
# Extra daemon option like: HP_OPTS=" --config=/home/headphones/config.ini"
EXTRA_DAEMON_OPTS=${HP_OPTS-}
# Hardcoded port to run on, overrides config.ini settings
[ -n "$HP_PORT" ] && {
PORT_OPTS=" --port=${HP_PORT} "
}
DAEMON_OPTS=" Headphones.py --quiet --daemon --nolaunch --pidfile=${PID_FILE} --datadir=${DATA_DIR} ${PORT_OPTS}${EXTRA_DAEMON_OPTS}"
SETTINGS_LOADED=TRUE
fi
[ -x "$DAEMON" ] || {
log_warning_msg "$DESC: Can't execute daemon, aborting. See $DAEMON";
return 1;}
return 0
}
load_settings || exit 0
is_running () {
# returns 1 when running, else 0.
if [ -e "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
RET=$?
[ $RET -gt 1 ] && exit 1 || return $RET
else
return 1
fi
}
handle_pid () {
PID_PATH=$(dirname "$PID_FILE")
[ -d "$PID_PATH" ] || mkdir -p "$PID_PATH" && chown -R "$RUN_AS" "$PID_PATH" > /dev/null || {
log_warning_msg "$DESC: Could not create $PID_FILE, See $SETTINGS, aborting.";
return 1;}
if [ -e "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ! kill -0 "$PID" > /dev/null 2>&1; then
log_warning_msg "Removing stale $PID_FILE"
rm "$PID_FILE"
fi
fi
}
handle_datadir () {
[ -d "$DATA_DIR" ] || mkdir -p "$DATA_DIR" && chown -R "$RUN_AS" "$DATA_DIR" > /dev/null || {
log_warning_msg "$DESC: Could not create $DATA_DIR, See $SETTINGS, aborting.";
return 1;}
}
handle_updates () {
chown -R "$RUN_AS" "$APP_PATH" > /dev/null || {
log_warning_msg "$DESC: $APP_PATH not writable by $RUN_AS for web-updates";
return 0; }
}
start_headphones () {
handle_pid
handle_datadir
handle_updates
if ! is_running; then
log_daemon_msg "Starting $DESC"
start-stop-daemon -o -d $APP_PATH -c $RUN_AS --start $EXTRA_SSD_OPTS --pidfile $PID_FILE --exec $DAEMON -- $DAEMON_OPTS
check_retval
else
log_success_msg "$DESC: already running (pid $PID)"
fi
}
stop_headphones () {
if is_running; then
log_daemon_msg "Stopping $DESC"
start-stop-daemon -o --stop --pidfile "$PID_FILE" --retry 15
check_retval
else
log_success_msg "$DESC: not running"
fi
}
case "$1" in
start)
start_headphones
;;
stop)
stop_headphones
;;
restart|force-reload)
stop_headphones
start_headphones
;;
status)
status_of_proc -p "$PID_FILE" "$DAEMON" "$DESC"
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac
exit 0
ensuite
nano /opt/headphones/config.ini
Et on mets les valeurs suivantes sur ces variables:
http_host = 0.0.0.0
customhost = votredomaine.tld
http_port = 8881
et
chmod +x /etc/init.d/headphones_daniel
Configuration de nginx
nano /etc/nginx/sites-enabled/rutorrent.conf
j'ajoute ça
location /headphones {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_redirect off;
if ($remote_user = "daniel") {
proxy_pass http://127.0.0.1:8881;
break;
}
if ($remote_user = "sb2016") {
proxy_pass http://127.0.0.1:8882;
break;
}
if ($remote_user = "sb20161") {
proxy_pass http://127.0.0.1:8883;
break;
}
}
et un petit
/etc/init.d/nginx restart
sa donne ça
[ ok ] Restarting nginx (via systemctl): nginx.service.
ensuite ont démarre headphones
service headphones start
résultats
Failed to start headphones.service: Unit headphones.service failed to load: No such file or directory.
bon pour le reste je sais pas trop quoi faire..