Skip to content

Commit

Permalink
Merge pull request #3 from bitSheriff/feature/autostart
Browse files Browse the repository at this point in the history
Auto start (systemd service) added
  • Loading branch information
bitSheriff authored Sep 26, 2023
2 parents 89583c4 + 63b15eb commit c8b3b31
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
47 changes: 45 additions & 2 deletions autostart_shelfslide.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,47 @@
#!/bin/bash
# copy this file to "~/.config/autostart/"

python3 ~/ShelfSlide/shelfslide.py
# Path to the Python program
PROGRAM_PATH="$HOME/ShelfSlide/shelfslide.py"

# Name of the systemd service
SERVICE_NAME="shelfslide"

# Get the username of the person running the script
CURRENT_USER="$USER"

# Check if the service already exists
if systemctl is-active --quiet ${SERVICE_NAME}.service; then
echo "The service ${SERVICE_NAME} already exists."
exit 1
fi

# Check if the script is executed with root privileges
if [ "$EUID" -ne 0 ]; then
echo "This script requires root privileges. Please run it as root."
exit 1
fi

# Create the unit file
cat <<EOF > /etc/systemd/system/${SERVICE_NAME}.service
[Unit]
Description=ShelfSlide Python Program
[Service]
ExecStart=/usr/bin/python3 ${PROGRAM_PATH}
WorkingDirectory=$HOME/ShelfSlide
User=$CURRENT_USER
Group=$CURRENT_USER
[Install]
WantedBy=multi-user.target
EOF

# Reload systemd
systemctl daemon-reload

# Enable and start the service
systemctl enable ${SERVICE_NAME}.service
systemctl start ${SERVICE_NAME}.service

# Display the status of the service
systemctl status ${SERVICE_NAME}.service
3 changes: 2 additions & 1 deletion shelfslide.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,5 @@ def main():
##
# @brief Main function
if __name__ == "__main__":
main()
os.chdir(os.path.dirname(os.path.abspath(__file__)))
main()

0 comments on commit c8b3b31

Please sign in to comment.