mirror of
https://github.com/suchmememanyskill/CYD-Klipper.git
synced 2026-03-21 05:33:24 +00:00
Allow running service under root
This commit is contained in:
@@ -1,8 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
if [ "$EUID" -eq 0 ]; then
|
if [ "$EUID" -eq 0 ]; then
|
||||||
echo "Please do not run as root"
|
read -r -p "Are you sure you want to run this service as root? [y/N] " response
|
||||||
|
response=${response,,} # tolower
|
||||||
|
if ! [[ "$response" =~ ^(yes|y)$ ]]; then
|
||||||
exit
|
exit
|
||||||
|
fi
|
||||||
|
SERVICE_PATH="/etc/systemd/system/cyd-klipper-serial.service"
|
||||||
|
else
|
||||||
|
mkdir -p ~/.config/systemd/user
|
||||||
|
SERVICE_PATH="~/.config/systemd/user/cyd-klipper-serial.service"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
@@ -15,20 +22,26 @@ source ./env/bin/activate
|
|||||||
pip3 install -r requirements.txt
|
pip3 install -r requirements.txt
|
||||||
|
|
||||||
# Create systemd unit file
|
# Create systemd unit file
|
||||||
mkdir -p ~/.config/systemd/user
|
|
||||||
echo "[Unit]" > ~/.config/systemd/user/cyd-klipper-serial.service
|
echo "[Unit]" > $SERVICE_PATH
|
||||||
echo "Description=CYD Klipper serial server" >> ~/.config/systemd/user/cyd-klipper-serial.service
|
echo "Description=CYD Klipper serial server" >> $SERVICE_PATH
|
||||||
echo "After=network.target" >> ~/.config/systemd/user/cyd-klipper-serial.service
|
echo "After=network.target" >> $SERVICE_PATH
|
||||||
echo "" >> ~/.config/systemd/user/cyd-klipper-serial.service
|
echo "" >> $SERVICE_PATH
|
||||||
echo "[Service]" >> ~/.config/systemd/user/cyd-klipper-serial.service
|
echo "[Service]" >> $SERVICE_PATH
|
||||||
echo "ExecStart=$(pwd)/run.sh" >> ~/.config/systemd/user/cyd-klipper-serial.service
|
echo "ExecStart=$(pwd)/run.sh" >> $SERVICE_PATH
|
||||||
echo "WorkingDirectory=$(pwd)" >> ~/.config/systemd/user/cyd-klipper-serial.service
|
echo "WorkingDirectory=$(pwd)" >> $SERVICE_PATH
|
||||||
echo "Restart=always" >> ~/.config/systemd/user/cyd-klipper-serial.service
|
echo "Restart=always" >> $SERVICE_PATH
|
||||||
echo "" >> ~/.config/systemd/user/cyd-klipper-serial.service
|
echo "" >> $SERVICE_PATH
|
||||||
echo "[Install]" >> ~/.config/systemd/user/cyd-klipper-serial.service
|
echo "[Install]" >> $SERVICE_PATH
|
||||||
echo "WantedBy=multi-user.target" >> ~/.config/systemd/user/cyd-klipper-serial.service
|
echo "WantedBy=multi-user.target" >> $SERVICE_PATH
|
||||||
|
|
||||||
# Start the service
|
# Start the service
|
||||||
systemctl --user daemon-reload
|
if [ "$EUID" -eq 0 ]; then
|
||||||
systemctl --user enable cyd-klipper-serial
|
systemctl daemon-reload
|
||||||
systemctl --user start cyd-klipper-serial
|
systemctl enable cyd-klipper-serial
|
||||||
|
systemctl start cyd-klipper-serial
|
||||||
|
else
|
||||||
|
systemctl --user daemon-reload
|
||||||
|
systemctl --user enable cyd-klipper-serial
|
||||||
|
systemctl --user start cyd-klipper-serial
|
||||||
|
fi
|
||||||
@@ -1,13 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
if [ "$EUID" -eq 0 ]; then
|
if [ "$EUID" -eq 0 ]; then
|
||||||
echo "Please do not run as root"
|
systemctl stop cyd-klipper-serial
|
||||||
exit
|
systemctl disable cyd-klipper-serial
|
||||||
|
|
||||||
|
rm /etc/systemd/system/cyd-klipper-serial.service
|
||||||
|
|
||||||
|
systemctl daemon-reload
|
||||||
|
else
|
||||||
|
systemctl --user stop cyd-klipper-serial
|
||||||
|
systemctl --user disable cyd-klipper-serial
|
||||||
|
|
||||||
|
rm ~/.config/systemd/user/cyd-klipper-serial.service
|
||||||
|
|
||||||
|
systemctl --user daemon-reload
|
||||||
fi
|
fi
|
||||||
|
|
||||||
systemctl --user stop cyd-klipper-serial
|
|
||||||
systemctl --user disable cyd-klipper-serial
|
|
||||||
|
|
||||||
rm ~/.config/systemd/user/cyd-klipper-serial.service
|
|
||||||
|
|
||||||
systemctl --user daemon-reload
|
|
||||||
Reference in New Issue
Block a user