systemctl_service_install.sh 663 B

123456789101112131415161718192021222324
  1. #!/bin/sh
  2. BASEDIR=$(dirname $(realpath "$0"))
  3. TMPFILE=modbuslog.service
  4. SERVICEFILE=/etc/systemd/system/modbuslog.service
  5. echo [Unit]>$TMPFILE
  6. echo Description=ModbusLogger>>$TMPFILE
  7. echo StartLimitInterval=0>>$TMPFILE
  8. echo >>$TMPFILE
  9. echo [Service]>>$TMPFILE
  10. echo Type=simple>>$TMPFILE
  11. echo Restart=always>>$TMPFILE
  12. echo RestartSec=1>>$TMPFILE
  13. echo ExecStart=$BASEDIR/modbuslog.py>>$TMPFILE
  14. echo User=pi>>$TMPFILE
  15. echo >>$TMPFILE
  16. echo [Install]>>$TMPFILE
  17. echo WantedBy=multi-user.target>>$TMPFILE
  18. sudo cp $TMPFILE $SERVICEFILE
  19. sudo systemctl daemon-reload
  20. sudo systemctl enable modbuslog.service
  21. sudo systemctl start modbuslog.service