Différences entre versions de « Ressources:Installer Octoprint sur OrangePI »

De wikiup
Sauter à la navigation Sauter à la recherche
Ligne 501 : Ligne 501 :
 
  <nowiki>
 
  <nowiki>
 
pi@orangepipcplus:~/OctoPrint$ sudo update-rc.d octoprint defaults
 
pi@orangepipcplus:~/OctoPrint$ sudo update-rc.d octoprint defaults
 +
</nowiki>
 +
 +
 +
=== Création des droits pour redémarrer le système à partir d'octoprint ===
 +
 +
on cree le fichier octoprint-shutdown dans /etc/sudoers.d/ pour y mettre la commande "pi ALL=NOPASSWD: /sbin/shutdown"
 +
<nowiki>
 +
pi@orangepipcplus:~/OctoPrint$ sudo nano /etc/sudoers.d/octoprint-shutdown
 +
</nowiki>
 +
 +
le contenu du fichier est le suivant
 +
<nowiki>
 +
pi ALL=NOPASSWD: /sbin/shutdown
 +
</nowiki>
 +
 +
 +
 
</nowiki>
 
</nowiki>

Version du 20 juin 2017 à 16:28

Installation d'Octoprint sur Orange PI PC Plus

Installation de l'Orange PI

Creation d'une carte SD

Télécharger la distribution linux armbian ubuntu server : [1]

décompresser l'archive,le fichier image doit être flasher sur une carte micro-sd de 8Go.

Plusieurs solution existe pour créer des sd à partir d'un fichier image. Sous Windows 10 on peut utiliser Etcher : [2]

Pour la documentation de création de carte micro-SD onpeut se reporter à la documentation armbian :[3]

Installation du système

Insérer la carte micro-sd dans l'Orange PI ATTENTION il est impératif que la carte Orange PI est accès à internet pour l'installation. Sinon l'orange PI rame et met des plombes à démarrer. La seule solution est de brancher un cable RJ45 sur l'Orange PI (est ilutile de préciser quele cable RJ45 doit lui même être relier à un routeur Internet ?). Ilest en théorie possible d'installer l'OrangePi àpartir de la console en utilisant une sonde de debug, manifestement le comportement n'est pas stable.

Démarrer l'Orange PI,le premier démarrage est relativement long (s'inquiéter apres 5 mn)


Déterminer l'adresse IP de l'Orange PI

Pour cela on utilise un scanner IP AngryIP scanner par example Ipscan.jpg ou nmap sous linux


Connexion en ssh à l'orange PI

ssh root@<adresse de l'orange> par example ssh root@192.168.1.126 le mot de passe par defaut est 1234.

à la première connexion,l'orange demande un nouveau mot de passe root et la creation d'un utilisateur standard dans notre cas le mot de passe root à été changé en "freehumans" nous créons également l'utilisateur pi (mot de passe "raspberry") comme compte utilisateur


[lenovo.ADB-6b89cf] ? ssh root@192.168.1.126
root@192.168.1.126's password:
X11 forwarding request failed on channel 0
You are required to change your password immediately (root enforced)
  ___                               ____  _   ____   ____
 / _ \ _ __ __ _ _ __   __ _  ___  |  _ \(_) |  _ \ / ___|    _
| | | | '__/ _` | '_ \ / _` |/ _ \ | |_) | | | |_) | |      _| |_
| |_| | | | (_| | | | | (_| |  __/ |  __/| | |  __/| |___  |_   _|
 \___/|_|  \__,_|_| |_|\__, |\___| |_|   |_| |_|    \____|   |_|
                       |___/

Welcome to ARMBIAN 5.30 stable Ubuntu 16.04.2 LTS 3.4.113-sun8i
System load:   0.19 0.07 0.06   Up time:       1:08 hour
Memory usage:  3 % of 1000MB    IP:            192.168.1.126
CPU temp:      56°C
Usage of /:    81% of 1.4G

[ General system configuration: armbian-config ]
Last login: Tue Jun 20 10:31:54 2017 from 192.168.1.142
Changing password for root.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:


Thank you for choosing Armbian! Support: www.armbian.com

Creating a new user account. Press <Ctrl-C> to abort

Please provide a username (eg. your forename): pi
Trying to add user pi
Adding user `pi' ...
Adding new group `pi' (1000) ...
Adding new user `pi' (1000) with group `pi' ...
Creating home directory `/home/pi' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for pi
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] y

Dear pi, your account pi has been created and is sudo enabled.
Please use this account for your daily work from now on.


Your display settings are currently 720p (1280x720). To change this use the
h3disp utility. Do you want to change display settings now? [nY] n



Warning: a reboot is needed to finish resizing the filesystem
Please reboot the system now

root@orangepipcplus:~#reboot

on reboot l'orange apres cette etape


Mise à jour du système

on se connecte en ssh et on met àjour le système avec apt-get update et apt-get upgrade

 
[lenovo.ADB-6b89cf] ? ssh root@192.168.1.126
root@192.168.1.126's password:
X11 forwarding request failed on channel 0
  ___                               ____  _   ____   ____
 / _ \ _ __ __ _ _ __   __ _  ___  |  _ \(_) |  _ \ / ___|    _
| | | | '__/ _` | '_ \ / _` |/ _ \ | |_) | | | |_) | |      _| |_
| |_| | | | (_| | | | | (_| |  __/ |  __/| | |  __/| |___  |_   _|
 \___/|_|  \__,_|_| |_|\__, |\___| |_|   |_| |_|    \____|   |_|
                       |___/

Welcome to ARMBIAN 5.30 stable Ubuntu 16.04.2 LTS 3.4.113-sun8i
System load:   1.06 0.52 0.20   Up time:       1 min
Memory usage:  5 % of 1000MB    IP:            192.168.1.126
CPU temp:      58°C
Usage of /:    17% of 7.2G

[ 0 security updates available, 6 updates total: apt upgrade ]
Last check: 2017-06-20 10:34

[ General system configuration: armbian-config ]
Last login: Tue Jun 20 10:32:17 2017 from 192.168.1.142

root@orangepipcplus:~# apt-get update
Hit:1 http://ports.ubuntu.com xenial InRelease
Hit:2 http://apt.armbian.com xenial InRelease
Hit:3 http://ports.ubuntu.com xenial-security InRelease
Hit:4 http://ports.ubuntu.com xenial-updates InRelease
Hit:5 http://ports.ubuntu.com xenial-backports InRelease
Reading package lists... Done

root@orangepipcplus:~# apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  hostapd libc-bin libc-dev-bin libc6 libc6-dev libgnutls-openssl27 libgnutls30 libssl-dev libssl1.0.0 linux-firmware linux-headers-sun8i linux-image-sun8i
  linux-libc-dev linux-u-boot-orangepipcplus-default linux-xenial-root-orangepipcplus locales multiarch-support openssl sunxi-tools vlan
20 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/68.3 MB of archives.
After this operation, 24.6 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Preconfiguring packages ...

...


root@orangepipcplus:~# reboot
Connection to 192.168.1.126 closed by remote host.
Connection to 192.168.1.126 closed.

On reboot apres la mise à jour

Préparation de l'utilisateur pi pour Octoprint

On donne à l'utilisateur, les droits d'admin système (sudo) ,les droits pour utiliser l'interface série (tty et dialout)


root@orangepipcplus:~# usermod -aG sudo pi
root@orangepipcplus:~# usermod -aG sudo tty
root@orangepipcplus:~# usermod -aG sudo dialout


Installation de python

Se connecter en ssh avec l'ulisateur "pi,on installe ensuite python et quelques utilitaires

pi@orangepipcplus:~$ sudo apt-get install python-pip python-dev python-setuptools python-virtualenv git libyaml-dev build-essential virtualenv
[sudo] password for pi:
Sorry, try again.
[sudo] password for pi:
Reading package lists... Done
Building dependency tree
Reading state information... Done
build-essential is already the newest version (12.1ubuntu2).
git is already the newest version (1:2.7.4-0ubuntu1.1).
The following additional packages will be installed:
  libexpat1-dev libpython-dev libpython2.7 libpython2.7-dev libyaml-0-2 python-pip-whl python-pkg-resources python2.7-dev
Suggested packages:
  libyaml-doc python-setuptools-doc
Recommended packages:
  python-all-dev python-wheel virtualenv
The following NEW packages will be installed:
  libexpat1-dev libpython-dev libpython2.7 libpython2.7-dev libyaml-0-2 libyaml-dev python-dev python-pip python-pip-whl python-pkg-resources python-setuptools
  python-virtualenv python2.7-dev
0 upgraded, 13 newly installed, 0 to remove and 0 not upgraded.
Need to get 30.2 MB of archives.
After this operation, 41.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] y


Installation d'Octoprint proprement dit

On télécharge Octoprint au niveau de la racine de l'utilisateur pi


pi@orangepipcplus:~$ cd ~
pi@orangepipcplus:~$ git clone https://github.com/foosel/OctoPrint.git
Cloning into 'OctoPrint'...
remote: Counting objects: 41429, done.
remote: Total 41429 (delta 0), reused 0 (delta 0), pack-reused 41429
Receiving objects: 100% (41429/41429), 61.10 MiB | 914.00 KiB/s, done.
Resolving deltas: 100% (26205/26205), done.
Checking connectivity... done.
pi@orangepipcplus:~$
 


On crée le repertoire de sauvegarde des options octoprint


pi@orangepipcplus:~$ mkdir ~/.octoprint
 

on installe octoprint proprement dit

creation de l'environnment virtuel python ("virtualenv")

pi@orangepipcplus:~/OctoPrint$ cd ~/Octoprint
pi@orangepipcplus:~/OctoPrint$ virtualenv venv
Running virtualenv with interpreter /usr/bin/python2
New python executable in /home/pi/OctoPrint/venv/bin/python2
Also creating executable in /home/pi/OctoPrint/venv/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
pi@orangepipcplus:~/OctoPrint$


On installe ensuite Octoprint dans l'environnement virtuel


pi@orangepipcplus:~/OctoPrint$ ./venv/bin/python setup.py install
running install
running bdist_egg
running egg_info
creating src/OctoPrint.egg-info
writing requirements to src/OctoPrint.egg-info/requires.txt
writing src/OctoPrint.egg-info/PKG-INFO
writing top-level names to src/OctoPrint.egg-info/top_level.txt
writing dependency_links to src/OctoPrint.egg-info/dependency_links.txt
writing entry points to src/OctoPrint.egg-info/entry_points.txt
writing manifest file 'src/O 
...


Création des fichiers de démarrage automatique d'octoprint

on edite le fichier ~/Octoprint/scripts/octoprint.init pour ajouter l'option "DAEMON=/home/pi/Octoprint/venv/bin/octoprint"

pi@orangepipcplus:~/OctoPrint$ sudo nano ~/OctoPrint/scripts/octoprint.init


on obtient le fichier suivant

#!/bin/sh

### BEGIN INIT INFO
# Provides:          octoprint
# Required-Start:    $local_fs networking
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: OctoPrint daemon
# Description:       Starts the OctoPrint daemon with the user specified in
#                    /etc/default/octoprint.
### END INIT INFO

# Author: Sami Olmari & Gina Häußge

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="OctoPrint Daemon"
NAME="OctoPrint"
PKGNAME=octoprint
PIDFILE=/var/run/$PKGNAME.pid
SCRIPTNAME=/etc/init.d/$PKGNAME
DEFAULTS=/etc/default/$PKGNAME
DAEMON=/home/pi/Octoprint/venv/bin/octoprint

# Read configuration variable file if it is present
[ -r $DEFAULTS ] && . $DEFAULTS

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

# Exit if the DAEMON is not set
if [ -z "$DAEMON" ]
then
    log_warning_msg "Not starting $PKGNAME, DAEMON not set in /etc/default/$PKGNAME."
    exit 0
fi

# Exit if the DAEMON is not installed
[ -x "$DAEMON" ] || exit 0

# Load the VERBOSE setting and other rcS variables
[ -f /etc/default/rcS ] && . /etc/default/rcS

if [ -z "$START" -o "$START" != "yes" ]
then
   log_warning_msg "Not starting $PKGNAME, edit /etc/default/$PKGNAME to start it."
   exit 0
fi

if [ -z "$OCTOPRINT_USER" ]
then
    log_warning_msg "Not starting $PKGNAME, OCTOPRINT_USER not set in /etc/default/$PKGNAME."
    exit 0
fi

COMMAND_ARGS=
if [ -n "$BASEDIR" ]
then
    COMMAND_ARGS="--basedir $BASEDIR $COMMAND_ARGS"
fi

if [ -n "$CONFIGFILE" ]
then
    COMMAND_ARGS="--config $CONFIGFILE $COMMAND_ARGS"
fi

#
# Function to verify if a pid is alive
#
is_alive()
{
   pid=`cat $1` > /dev/null 2>&1
   kill -0 $pid > /dev/null 2>&1
   return $?
}

#
# Function that starts the daemon/service
#
do_start()
{
   # Return
   #   0 if daemon has been started
   #   1 if daemon was already running
   #   2 if daemon could not be started

   is_alive $PIDFILE
   RETVAL="$?"

   if [ $RETVAL != 0 ]; then
       start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \
       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK --nicelevel=$NICELEVEL \
       -- serve $COMMAND_ARGS $DAEMON_ARGS
       RETVAL="$?"
   fi
}

#
# Function that stops the daemon/service
#
do_stop()
{
   # Return
   #   0 if daemon has been stopped
   #   1 if daemon was already stopped
   #   2 if daemon could not be stopped
   #   other if a failure occurred

   start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user $OCTOPRINT_USER --pidfile $PIDFILE
   RETVAL="$?"
   [ "$RETVAL" = "2" ] && return 2

   rm -f $PIDFILE

   [ "$RETVAL" = "0"  ] && return 0 || return 1
}

case "$1" in
  start)
   [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
   do_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"
   do_stop
   case "$?" in
      0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
      2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
   esac
   ;;
  status)
   status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
   ;;
  restart)
   log_daemon_msg "Restarting $DESC" "$NAME"
   do_stop
   case "$?" in
     0|1)      do_start
      case "$?" in
         0) log_end_msg 0 ;;
         1) log_end_msg 1 ;; # Old process is still running
         *) log_end_msg 1 ;; # Failed to start
      esac
      ;;
     *)
        # Failed to stop
      log_end_msg 1
      ;;
   esac
   ;;
  *)
   echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
   exit 3
   ;;
esac

On edite ensuite le fichier ~/OctoPrint/scripts/octoprint.default pour activer l'option "DAEMON=/home/pi/Octoprint/venv/bin/octoprint"

pi@orangepipcplus:~/OctoPrint$ sudo nano ~/OctoPrint/scripts/octoprint.default 

on obtient le fichier suivant



# Configuration for /etc/init.d/octoprint

# The init.d script will only run if this variable non-empty.
OCTOPRINT_USER=pi

# base directory to use
#BASEDIR=/home/pi/.octoprint

# configuration file to use
#CONFIGFILE=/home/pi/.octoprint/config.yaml

# On what port to run daemon, default is 5000
PORT=5000

# Path to the OctoPrint executable, you need to set this to match your installation!
#DAEMON=/home/pi/OctoPrint/venv/bin/octoprint
DAEMON=/home/pi/OctoPrint/venv/bin/octoprint



# What arguments to pass to octoprint, usually no need to touch this
DAEMON_ARGS="--port=$PORT"

# Umask of files octoprint generates, Change this to 000 if running octoprint as its own, separate user
UMASK=022

# Process priority, 0 here will result in a priority 20 process.
# -2 ensures Octoprint has a slight priority over user processes.
NICELEVEL=-2

# Should we run at startup?
START=yes


Démarrage automatique d'octoprint

On recopie les fichiers de demarrage dans les repertoires /etc/init.d et /etc/default

pi@orangepipcplus:~/OctoPrint$ sudo cp ~/OctoPrint/scripts/octoprint.init /etc/init.d/octoprint
pi@orangepipcplus:~/OctoPrint$ sudo cp ~/OctoPrint/scripts/octoprint.default /etc/default/octoprint

On marque les fichiers comme executable

pi@orangepipcplus:~/OctoPrint$ sudo chmod +x /etc/init.d/octoprint
pi@orangepipcplus:~/OctoPrint$ sudo chmod +x /etc/default/octoprint

On demande au système de demarrer octoprint au démarrage

pi@orangepipcplus:~/OctoPrint$ sudo update-rc.d octoprint defaults


Création des droits pour redémarrer le système à partir d'octoprint

on cree le fichier octoprint-shutdown dans /etc/sudoers.d/ pour y mettre la commande "pi ALL=NOPASSWD: /sbin/shutdown"

pi@orangepipcplus:~/OctoPrint$ sudo nano /etc/sudoers.d/octoprint-shutdown 

le contenu du fichier est le suivant

pi ALL=NOPASSWD: /sbin/shutdown


</nowiki>