Pokazywanie postów oznaczonych etykietą linux. Pokaż wszystkie posty
Pokazywanie postów oznaczonych etykietą linux. Pokaż wszystkie posty

wtorek, 16 kwietnia 2013

RPi - Running services at boot

I wanted to start a few services while my Rasperry Pi is booting. Since my days as linux "administrator" are gone, I needed to do some research how to achieve that.

Services to be started: H2 database server, serial port listening service, tomcat - in that order.

Naturally, all applications have been installed.
First step - prepare script files:

/etc/init.d/h2 file:
#!/bin/bash

### BEGIN INIT INFO
# Provides:          h2
# Required-Start:
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: h2 database
# Description:       h2 database
### END INIT INFO


test -f /lib/lsb/init-functions || exit 1
. /lib/lsb/init-functions

H2_HOME=/opt/h2
DAEMON=h2server
ARGS=


#PID=$(get_pid $DAEMON)

case "$1" in
 start)
  log_begin_msg "Starting h2 database"
   $H2_HOME/bin/$DAEMON $ARGS & #>/dev/null
   log_end_msg 0
   ;;
 stop)
   log_begin_msg "Stopping $DAEMON"
   kill `ps aux | awk '/h2.*jar/{print $2}'` > /dev/null
   ;;
 restart)
   $0 stop
   sleep 1
   $0 start
   ;;
 *)
   echo "usage: $0 {start|stop|restart}"  
esac


/etc/init.d/rxreader file:
#!/bin/bash

### BEGIN INIT INFO
# Provides:          rxreader
# Required-Start: $tomcat
# Required-Stop: $tomcat
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: rxreader
# Description:       rxreader
### END INIT INFO


test -f /lib/lsb/init-functions || exit 1
. /lib/lsb/init-functions

RXRD_HOME=/opt/rxreader
DAEMON=read
ARGS=


case "$1" in
 start)
  log_begin_msg "Starting h2 database"
   #[ -z "$PID" ] && 
   $RXRD_HOME/bin/$DAEMON $ARGS & #>/dev/null
   log_end_msg 0
   ;;
 stop)
   log_begin_msg "Stopping $DAEMON"
   kill `ps aux | awk '/rxreader/{print $2}'` > /dev/null
   ;;
 restart)
   $0 stop
   sleep 1
   $0 start
   ;;
 *)
   echo "usage: $0 {start|stop|restart}"  
esac

/etc/init.d/tomcat file:
#!/bin/bash

### BEGIN INIT INFO
# Provides:          tomcat
# Required-Start: $h2
# Required-Stop: $h2
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: tomcat
# Description:       tomcat
### END INIT INFO


test -f /lib/lsb/init-functions || exit 1
. /lib/lsb/init-functions

TOMCAT_HOME=/opt/apache-tomcat-7
DAEMON=startup.sh
ARGS=


case "$1" in
 start)
  log_begin_msg "Starting apache tomcat"
   $TOMCAT_HOME/bin/$DAEMON $ARGS & #>/dev/null
   log_end_msg 0
   ;;
 stop)
   log_begin_msg "Stopping $DAEMON"
   $TOMCAT_HOME/bin/shutdown.sh
   ;;
 restart)
   $0 stop
   sleep 1
   $0 start
   ;;
 *)
   echo "usage: $0 {start|stop|restart}"  
esac

When file are in /etc/init.d directory we have to run update-rc command, which installs (or removes) System-V style init script links:
sudo update-rc.d h2 defaults
sudo update-rc.d tomcat defaults
sudo update-rc.d rxreader defaults

Now you can restart RPi or start services manually:
sudo service h2 start
sudo service rxreader start
sudo service tomcat start

czwartek, 27 grudnia 2012

Logging to Raspberry without password

Once upon a time I was spending a lot of time working with Linux servers. It's a distant past, but I still can recall some tips. One of them, quite useful when it comes to playing with RPi, is logging without password. I don't mean to give up passwords and allow anyone to enter my realms, but rather to automate the whole process from trusted machine.

How to achieve that?

On your workstations you need to generate authentication keys:
myuser@myhost:~$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/myuser/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/myuser/.ssh/id_rsa.
Your public key has been saved in /home/myuser/.ssh/id_rsa.pub.
The key fingerprint is:
2d:2c:d5:d1:cc:cc:1a:aa:a3:11:28:da:1b:1a:2a:3a


When you have them, the next step is copying your public key to RPi:
myuser@myhost:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub myuser@raspberrypi
myuser@raspberrypi's password: 
Now try logging into the machine, with "ssh 'myuser@raspberrypi'", and check in:

  ~/.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

And that's all.
From now on you will be automatically logged to your precious board.

poniedziałek, 14 maja 2012

Zmiana hasła w AD w konsoli linuksowej

Hasło użytkownika w AD z konsoli linuksowej można zmienić następująco:
smbpasswd -r kontroler_domeny -U username 

niedziela, 13 maja 2012

Arduino na Linuxie

Instalacja Arduino IDE na linuxie do skomplikowanych nie należy...
  • Pobrać paczkę z arduino.cc
  • Rozpakować w wybranej lokalizacji (ja preferuje /opt/apps/)
  • Pobrać i zainstalować gcc-avr i avr-libc
    sudo apt-get install gcc-avr avr-libc
  • I niby wszystko powinno działać. Jednakże może się okazać, że nie można wybrać z IDE portu USB.
    Wtedy należy dodać swojego użytkownika do grupy dialout:
    sudo usermod -aG dialout username 
Voila!

A przynajmniej tak było do wersji 1.0. Kolejna wersja ma coś sknoconego, podczas próby uruchomienia rzucany jest wyjątek:
java.lang.IllegalArgumentException: Illegal pattern character 'r'
at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:845)
at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:659)
at java.text.SimpleDateFormat.
(SimpleDateFormat.java:585)

Taaak....
Rozwiązanie 1: przed uruchomieniem arduino wykonać w konsoli:
export LANG=en_US.UTF-8


wtorek, 8 maja 2012

Transcoding

"Za moich czasów" ASCII było wystarczającym kodowaniem, ba, wiele znaków znałem na pamęć (wiem, geekowate :) )

Obecnie kodowań "jak mrówków". Na szczęście na linuxie można zmienić kodowanie bardzo prosto, za pomocą prostego narzędzia iconv:

iconv --from-code=CP1250 --to-code=UTF-8 file_in > file_out