On my raspbian I defined the locale using raspi-config. When I ssh back into it, I can check this is still correct (same result for pi and for root users):
$ locale
LANG=fr_FR.UTF-8
LANGUAGE=fr_FR.UTF-8
LC_CTYPE="fr_FR.UTF-8"
LC_NUMERIC=fr_FR.UTF-8
LC_TIME=fr_FR.UTF-8
LC_COLLATE="fr_FR.UTF-8"
LC_MONETARY=fr_FR.UTF-8
LC_MESSAGES="fr_FR.UTF-8"
LC_PAPER=fr_FR.UTF-8
LC_NAME=fr_FR.UTF-8
LC_ADDRESS=fr_FR.UTF-8
LC_TELEPHONE=fr_FR.UTF-8
LC_MEASUREMENT=fr_FR.UTF-8
LC_IDENTIFICATION=fr_FR.UTF-8
LC_ALL=
Now, I want to start several (python) scripts at startup. I defined and installed this start script:
#!/usr/bin/env sh
### BEGIN INIT INFO
# Provides: pilberry
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start pilberry
### END INIT INFO
case "$1" in
start)
echo "Starting pilberry"
/home/pi/pilberry/bin/start
;;
stop)
echo "Stopping pilberry"
/home/pi/pilberry/bin/stop
;;
reload|restart)
"$0" stop
"$0" start
;;
*)
echo "Usage: $0 start|stop|restart|reload"
exit 1
esac
exit 0
I noticed that the python scripts that are started this way raise ascii encoding/decoding exceptions although they work perfectly if I run them from a terminal (also using the very same start script).
Using bash instead of sh doesn't change anything.
I have added this into the shell script:
locale > /home/pi/pilberry/log/locale_at_startup
And here's the result:
$ cat pilberry/log/locale_at_startup
LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=
I have tried to regenerate the locale (using locale-gen) at the beginning of the startup script (what clearly slows the starting phase), but I get the same result.
I don't really want to try a trick in the python scripts because the problem obviously does not come from python.
So, how is it possible to have the locale set correctly before running scripts at startup?