diff --git a/Service/README.md b/Service/README.md new file mode 100644 index 00000000..9f800ee5 --- /dev/null +++ b/Service/README.md @@ -0,0 +1,29 @@ +# Autostart + +To enable the Freenove Smart Car Server to run at startup follow the steps for your distro. + +Credit of Leigh Dastey (ldastey@outlook.com). + +## SystemD Configuration + +**INSTALL_DIR below should be replaced throughout to the path of the file on your system** + +Edit **$INSTALL_DIR**/Service/smart-car-server and change $INSTALL_DIR to be the path of this file on your system + +Then run the following commands: + + sudo chmod 755 $INSTALL_DIR/Service/smart-car-server + sudo ln -s $INSTALL_DIR/Service/smart-car-server.service /lib/systemd/system/smart-car-server.service + sudo ln -s $INSTALL_DIR/Service/smart-car-server /etc/init.d/smart-car-server + sudo systemctl daemon-reload + sudo systemctl enable smart-car-server + sudo reboot + +When the Pi restarts you will be able to connect client applications (i.e. mobile app) and test you can connect. + +### SystemD Disable Autostart + +To disable the SystemD autostart run + + sudo systemctl disable smart-car-server + diff --git a/Service/smart-car-server b/Service/smart-car-server new file mode 100755 index 00000000..6e9ae9dd --- /dev/null +++ b/Service/smart-car-server @@ -0,0 +1,17 @@ +#!/bin/sh + +# +# Copy this file to /etc/init.d/ +# + +### BEGIN INIT INFO +# Provides: smart-car-server +# Required-Start: $all +# Required-Stop: $all +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Pi Smart Car Server +### END INIT INFO + +sudo /usr/bin/python $INSTALL_DIR/Code/Server/main.py -t -n + diff --git a/Service/smart-car-server.service b/Service/smart-car-server.service new file mode 100644 index 00000000..80384c6d --- /dev/null +++ b/Service/smart-car-server.service @@ -0,0 +1,12 @@ +[Unit] +Description=Pi Smart Car Server +Wants=network-online.target +After=network-online.target + +[Service] +Type=simple +ExecStartPre=/bin/sleep 20 +ExecStart=/bin/bash /etc/init.d/smart-car-server + +[Install] +WantedBy=multi-user.target