Größe: 1332
Kommentar:
|
Größe: 3175
Kommentar:
|
Gelöschter Text ist auf diese Art markiert. | Hinzugefügter Text ist auf diese Art markiert. |
Zeile 64: | Zeile 64: |
DefaultDependencies=no After=local-fs.target Before=basic.target Conflicts=umount.target |
|
Zeile 66: | Zeile 70: |
Type=oneshot RemainAfterExit=yes |
|
Zeile 68: | Zeile 74: |
User=root | |
Zeile 72: | Zeile 78: |
Zeile 74: | Zeile 81: |
Script: {{{ #!highlight bash #!/bin/bash ### BEGIN INIT INFO # Provides: varlog # Required-Start: $local_fs # Required-Stop: $local_fs # X-Start-Before: $syslog # X-Stop-After: $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start/stop tmpfs logfile saving and restore. ### END INIT INFO # # Increases overall system performance. # Increases the life of your SDcard by reducing filesystem IO (read/writes). # PATH=/sbin:/usr/sbin:/bin:/usr/bin |
|
Zeile 75: | Zeile 101: |
varlogSave=/var/save.log/ [ ! -d $varlogSave ] && mkdir -p $varlogSave function _save() { if [ -x "$(which rsync)" ]; then rsync -a --delete /var/log/ ${varlogSave} else cp -Rpu "/var/log/*" $varlogSave fi sync } case $1 in start) echo "*** Starting tmpfs file restore: varlog." if [ -z "$(grep /var/log /proc/mounts)" ]; then echo "*** mounting /var/log" _save varlogsize=$(grep /var/log /etc/fstab|awk {'print $4'}|cut -d"=" -f2) [ -z "$varlogsize" ] && varlogsize="70M" mount -t tmpfs tmpfs /var/log -o defaults,size=$varlogsize chmod 775 /var/log fi cp -Rpu ${varlogSave}* /var/log/ ;; stop) echo "*** Stopping tmpfs file saving: varlog." _save umount -f /var/log/ ;; *) echo "Usage: $0 {start|stop}" exit 1 ;; esac exit 0 [/php] Ein weiterer Gedanke wäre noch einen Schritt weiter zu gehen und im "start" Abschnitt die letzte Zeile wie folgt abzuändern: [code] cp -Rp --attributes-only ${varlogSave}* /var/log/ }}} |
Raspberry Service designen
Am Beispiel von WPA-Ping (wird von mir NICHT genutzt)
Das Script sieht so aus:
cat >> /usr/local/bin/wpaping << "EOFWPA" #!/bin/bash # # Loop forever doing wpa_cli SCAN commands # sleeptime=120 # number of seconds to sleep. 2 minutes (120 seconds) is a good value while [ 1 ]; do wpa_cli -i wlan0 scan sleep $sleeptime done EOFWPA
Der Service selber wird so gestaltet:
cat >> /lib/systemd/system/wpaping.service << "EOFWPA" [Unit] Description=WPA Supplicant pinger Requires=network-online.target [Service] ExecStart=/usr/local/bin/wpaping User=root StandardInput=null StandardOutput=null StandardError=null Restart=on-failure [Install] WantedBy=multi-user.target EOFWPA
Um den Service dauerhaft zu starten, einfach den Standard-Weg beschreiten:
systemctl daemon-reload; systemctl enable wpaping.service; systemctl start wpaping.service
Runlevel herausfinden:
runlevel
Eigener Versuch:
[Unit] Description=Sync Logfiles between SD Card and ramdisk Requires=var-log.mount DefaultDependencies=no After=local-fs.target Before=basic.target Conflicts=umount.target [Service] Type=oneshot RemainAfterExit=yes ExecStart=/home/hss/scripts/rsync-log-files-boot.sh ExecStop=/home/hss/scripts/rsync-log-files-shutdown.sh User=root [Install] WantedBy=multi-user.target
Script:
1 #!/bin/bash
2 ### BEGIN INIT INFO
3 # Provides: varlog
4 # Required-Start: $local_fs
5 # Required-Stop: $local_fs
6 # X-Start-Before: $syslog
7 # X-Stop-After: $syslog
8 # Default-Start: 2 3 4 5
9 # Default-Stop: 0 1 6
10 # Short-Description: Start/stop tmpfs logfile saving and restore.
11 ### END INIT INFO
12 #
13 # Increases overall system performance.
14 # Increases the life of your SDcard by reducing filesystem IO (read/writes).
15 #
16 PATH=/sbin:/usr/sbin:/bin:/usr/bin
17
18
19 varlogSave=/var/save.log/
20 [ ! -d $varlogSave ] && mkdir -p $varlogSave
21
22
23 function _save() {
24 if [ -x "$(which rsync)" ]; then
25 rsync -a --delete /var/log/ ${varlogSave}
26 else
27 cp -Rpu "/var/log/*" $varlogSave
28 fi
29 sync
30 }
31
32
33 case $1 in
34 start)
35 echo "*** Starting tmpfs file restore: varlog."
36 if [ -z "$(grep /var/log /proc/mounts)" ]; then
37 echo "*** mounting /var/log"
38 _save
39 varlogsize=$(grep /var/log /etc/fstab|awk {'print $4'}|cut -d"=" -f2)
40 [ -z "$varlogsize" ] && varlogsize="70M"
41 mount -t tmpfs tmpfs /var/log -o defaults,size=$varlogsize
42 chmod 775 /var/log
43 fi
44 cp -Rpu ${varlogSave}* /var/log/
45 ;;
46 stop)
47 echo "*** Stopping tmpfs file saving: varlog."
48 _save
49 umount -f /var/log/
50 ;;
51 *)
52 echo "Usage: $0 {start|stop}"
53 exit 1
54 ;;
55 esac
56
57
58 exit 0
59 [/php]
60
61
62 Ein weiterer Gedanke wäre noch einen Schritt weiter zu gehen und im "start" Abschnitt die letzte Zeile wie folgt abzuändern:
63 [code]
64 cp -Rp --attributes-only ${varlogSave}* /var/log/