Autostart Devices

From ago control wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "== Autostart Devices == Here is an example on creating a service to automatically start your custom device driver: As root, copy your custom file to /opt/agocontrol/bin . C...")
 
m (Autostart Devices)
 
(3 intermediate revisions by 2 users not shown)
Line 2: Line 2:
  
 
Here is an example on creating a service to automatically start your custom device driver:
 
Here is an example on creating a service to automatically start your custom device driver:
 +
 +
'''IMPORTANT'''  Your custom file's first line MUST be:
 +
#!/usr/bin/python
  
 
As root, copy your custom file to /opt/agocontrol/bin .  Change the file permissions so that the file has read and execute permissions :
 
As root, copy your custom file to /opt/agocontrol/bin .  Change the file permissions so that the file has read and execute permissions :
 
  chmod a+rx /opt/agocontrol/bin/agohumidity.py
 
  chmod a+rx /opt/agocontrol/bin/agohumidity.py
 +
 +
Make sure root owns the file:
 +
chown root /opt/agocontrol/bin/agohumidity.py
 +
chgrp root /opt/agocontrol/bin/agohumidity.py
  
 
Create a new file in /lib/systemd/system/ called agohumidity.service :
 
Create a new file in /lib/systemd/system/ called agohumidity.service :
Line 23: Line 30:
 
  WantedBy=multi-user.target
 
  WantedBy=multi-user.target
  
Change the description and ExecStart to match the needs of your device driver.
+
Note: If you are using RPI and use GPIO, you must change "User=agocontrol" to  "User=root" in above, else you don't have privileges to control the GPIO pins
 +
 
 +
Change the filename, description and ExecStart to match the needs of your device driver.
  
 
Next, enable the service:
 
Next, enable the service:

Latest revision as of 22:02, 4 December 2014

[edit] Autostart Devices

Here is an example on creating a service to automatically start your custom device driver:

IMPORTANT Your custom file's first line MUST be:

#!/usr/bin/python

As root, copy your custom file to /opt/agocontrol/bin . Change the file permissions so that the file has read and execute permissions :

chmod a+rx /opt/agocontrol/bin/agohumidity.py

Make sure root owns the file:

chown root /opt/agocontrol/bin/agohumidity.py
chgrp root /opt/agocontrol/bin/agohumidity.py

Create a new file in /lib/systemd/system/ called agohumidity.service :

[Unit]
Description=ago control Weather Device

[Service]
ExecStart=/opt/agocontrol/bin/agohumidity.py
WorkingDirectory=/opt/agocontrol/bin
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol

[Install]
WantedBy=multi-user.target

Note: If you are using RPI and use GPIO, you must change "User=agocontrol" to "User=root" in above, else you don't have privileges to control the GPIO pins

Change the filename, description and ExecStart to match the needs of your device driver.

Next, enable the service:

systemctl enable agohumidity.service

Then, start the service:

systemctl start agohumidity.service

Finally, ensure that the service is running:

root@debian# systemctl status agohumidity.service
agohumidity.service - ago control Weather Device
          Loaded: loaded (/lib/systemd/system/agohumidity.service; enabled)
          Active: active (running) since Wed, 31 Dec 1969 18:00:26 -0600; 43 years and 9 months ago
        Main PID: 361 (python)
          CGroup: name=systemd:/system/agohumidity.service
                  â 361 python /opt/agocontrol/bin/agohumidity.py

You can temporarily stop the service by using:

systemctl stop agohumidity.service

To permanently disable the service use:

systemctl disable agohumidity.service
Personal tools