systemd startup

Asked by Peter Eliopoulos

Has anyone been able to turn this into a systemd process to set to run at startup? I have tried a bunch of different combinations of commands in 20.04 but have been unsuccessful.

Question information

Language:
English Edit question
Status:
Solved
For:
Keep.Awake Edit question
Assignee:
DanglingPointer Edit question
Solved by:
Peter Eliopoulos
Solved:
Last query:
Last reply:
Revision history for this message
Peter Eliopoulos (peliopoulos) said :
#1

Here is my keepawake.service file:

[Unit]
Description=Inhibit suspend if Plex is streaming media or downloading
After=network.service

[Service]
ExecStart=/home/peter/keep.awake/keepawake.sh

[Install]
WantedBy=default.target

The keepawake.sh script works just fine from the command prompt. I have tried adding User= me and root to the service file. I have changed the script to include nohup and remove it. I have tried changing the After= value. No luck.

Revision history for this message
Peter Eliopoulos (peliopoulos) said :
#2

Figured it out. I created a service in the /etc/systemd/user folder for this, when I should have used a User service and put it in ~/.config/systemd/user folder.

Here is my command to make this work from start to finish from a regular command prompt in Ubuntu 20.04. Copy and paste the whole thing (everything between the "----" marks) in one go - it will install Keep.Awake in a folder in the Home folder, create other needed folders, create a .service file, create a script file (easier to find and tweak) and install the service file to run at startup :

----

sudo apt install -y brz libxss-dev libx11-dev libffi-dev python3-pip python3-netifaces python3-psutil python3-distro xz-utils && brz branch lp:keep.awake && mkdir -p /home/$USER/.config/systemd/user && bash -c "cat > /home/$USER/.config/systemd/user/keep.awake.service" <<'EOF1' && bash -c "cat > /home/$USER/.config/keep.awake.sh" <<'EOF2' && chmod +x /home/$USER/keep.awake/keep.awake.sh && systemctl --user enable keep.awake && systemctl --user start keep.awake
[Unit]
[Service]
ExecStart=/home/$USER/keep.awake/keep.awake.sh
[Install]
WantedBy=default.target
EOF1
#!/bin/bash
/home/$USER/keep.awake/v4/keepawake.py -s 100000 -l /home/$USER/keep.awake/ -v Detail -r
EOF2

----

Revision history for this message
DanglingPointer (ferncasado) said :
#3

Hi Peter,

Apologies for the delay in responding to your thread! I've been busy with work due to the pandemic needing more IT guys than ever!

That's great that it is finally working for you using systemD.

I've got the program running on many servers all over the place and they way I run it on Ubuntu (mostly 18.04 and 20.04) is uniformly the same; but the parameters for keepawake.py may be different for each server.

I do this:
1) I install using the instructions on https://launchpad.net/keep.awake to a folder called "keep.awake" on the server

2) I cd into the "keep.awake" folder. There should be a single folder there called "v4"

3) I create a file called "keepawake.sh" in that path next to the v4 folder.

4) In the file I write my nohup command for keepawake.py; which is usually something like this...

nohup /usr/bin/python3 /<your Path>/keep.awake/v4/keepawake.py -n <your NIC> -s 5120 -w 5400 -u 600 -l /var/log/Keep.Awake/ -v Verbose -r > /dev/null 2>&1 &

5) I save the file and make it executable by user group and others (775).

6) I create the path /var/log/Keep.Awake/

7) I give the folder a custom group of which my intended user for keepawake is a member
Ownership of the folder is root

7) I run gnome-session-properties
You can run this by hitting the window key on your keyboard and typing "startup applications" and clicking on the icon

8) I give it the following values for the 3 fields and save
Name: KeepAwake
Command: /<your Path>/KeepAwake/keepawake.sh
Comment: Keeps the server awake based on cpu, network and user activity

9) At this point you're almost done. Just restart. KeepAwake will now start each time you start ubuntu with your intended user for it.

I use wakeonlan to wake up various servers based on a schedule (in cron) so my main orchestration server can do stuff. Then I let KeepAwake just manage when they should sleep independently.

I use this for backups, long compute programs, kids Dolphin-Emulator computer, and a host of other IoT use devices and computers. I also use this extensively with my extended family's computers (they're all on Ubuntu now! and have ditched Windows. Basically I'm their IT guy).

There are many ways to achieve the same thing. I suppose your way is one. The above is another.

I'm glad you're getting value out of this little program I wrote some years back!