-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup_autostart.sh
71 lines (59 loc) · 1.84 KB
/
setup_autostart.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# Usage: ./setup_autostart.sh /path/to/raspicam raspicam_cfg_filename /path/to/imgstorage
# Check if all parameters are provided
if [ "$#" -ne 3 ]; then
echo "Usage: $0 workingdirectory_for_raspicam raspicam_cfg_filename workingdirectory_for_imgstorage"
exit 1
fi
# Assign parameters to variables
WORKINGDIR_RASPICAM=$1
RASPICAM_CFG_FILENAME=$2
WORKINGDIR_IMGSTORAGE=$3
# Create systemd service file for raspicam
RASPICAM_SERVICE=/etc/systemd/system/raspicam.service
echo "Creating systemd service file for raspicam at $RASPICAM_SERVICE"
sudo bash -c "cat > $RASPICAM_SERVICE" << EOF
[Unit]
Description=bb_raspicam
After=network.target
[Service]
Type=simple
User=pi
WorkingDirectory=$WORKINGDIR_RASPICAM
ExecStart=/usr/bin/python3 raspicam.py $RASPICAM_CFG_FILENAME
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
# Create systemd service file for imgstorage
IMGSTORAGE_SERVICE=/etc/systemd/system/imgstorage.service
echo "Creating systemd service file for imgstorage at $IMGSTORAGE_SERVICE"
sudo bash -c "cat > $IMGSTORAGE_SERVICE" << EOF
[Unit]
Description=bb_imgstorage_nfs
After=network.target
[Service]
Type=simple
User=pi
WorkingDirectory=$WORKINGDIR_IMGSTORAGE
ExecStart=/usr/bin/python3 imgstorage.py
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
# Reload systemd to recognize new services
echo "Reloading systemd daemon"
sudo systemctl daemon-reload
# Enable services
echo "Enabling services to start at boot"
sudo systemctl enable raspicam.service
sudo systemctl enable imgstorage.service
echo ""
echo "Setup complete! raspicam and imgstorage will start on boot."
echo "To start manually, use these commands:"
echo "sudo systemctl start raspicam.service"
echo "sudo systemctl start imgstorage.service"
echo ""
echo "To stop:"
echo "sudo systemctl stop raspicam.service"
echo "sudo systemctl stop imgstorage.service"