suspend_if_idle ignore own service
This commit is contained in:
		
							parent
							
								
									cfee1d74b0
								
							
						
					
					
						commit
						df607f0656
					
				
					 2 changed files with 11 additions and 6 deletions
				
			
		| 
						 | 
					@ -2,15 +2,19 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
UPTIME=$(cat /proc/uptime | cut -d. -f1)
 | 
					UPTIME=$(cat /proc/uptime | cut -d. -f1)
 | 
				
			||||||
MIN_UPTIME=$(expr 60 \* 30)
 | 
					MIN_UPTIME=$(expr 60 \* 30)
 | 
				
			||||||
if [[ $UPTIME -lt $MIN_UPTIME ]]
 | 
					if [[ "$UPTIME" -lt "$MIN_UPTIME" ]]
 | 
				
			||||||
then
 | 
					then
 | 
				
			||||||
  echo "ABORT: uptime ($UPTIME) lower than min ($MIN_UPTIME)"
 | 
					  echo "ABORT: uptime ($UPTIME) lower than min ($MIN_UPTIME)"
 | 
				
			||||||
  exit 0
 | 
					  exit 0
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					MY_SERVICE="$2"
 | 
				
			||||||
for SERVICE in $(systemctl list-timers --no-pager --no-legend --state active -o json | jq -r '.[] | .activates')
 | 
					for SERVICE in $(systemctl list-timers --no-pager --no-legend --state active -o json | jq -r '.[] | .activates')
 | 
				
			||||||
do
 | 
					do
 | 
				
			||||||
  if systemctl is-active "$SERVICE" --quiet
 | 
					  if [[ "$SERVICE" = "$MY_SERVICE" ]]
 | 
				
			||||||
 | 
					  then
 | 
				
			||||||
 | 
					    continue
 | 
				
			||||||
 | 
					  elif systemctl is-active "$SERVICE" --quiet
 | 
				
			||||||
  then
 | 
					  then
 | 
				
			||||||
    echo "ABORT: service $SERVICE is running by timer"
 | 
					    echo "ABORT: service $SERVICE is running by timer"
 | 
				
			||||||
    exit 0
 | 
					    exit 0
 | 
				
			||||||
| 
						 | 
					@ -18,13 +22,13 @@ do
 | 
				
			||||||
done
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
LOGINS=$(who -u | grep pts\/ | wc -l)
 | 
					LOGINS=$(who -u | grep pts\/ | wc -l)
 | 
				
			||||||
if ! [[ $LOGINS =~ "^0$" ]]
 | 
					if ! [[ "$LOGINS" =~ "^0$" ]]
 | 
				
			||||||
then
 | 
					then
 | 
				
			||||||
  echo "ABORT: $LOGINS user logins"
 | 
					  echo "ABORT: $LOGINS user logins"
 | 
				
			||||||
  exit 0
 | 
					  exit 0
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [[ $1 = now ]]
 | 
					if [[ "$1" = now ]]
 | 
				
			||||||
then
 | 
					then
 | 
				
			||||||
  echo "SESPENDING"
 | 
					  echo "SESPENDING"
 | 
				
			||||||
  sleep 10
 | 
					  sleep 10
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,10 +4,11 @@ from ipaddress import ip_interface
 | 
				
			||||||
    'systemd-timers/suspend-if-idle',
 | 
					    'systemd-timers/suspend-if-idle',
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
def timer(metadata):
 | 
					def timer(metadata):
 | 
				
			||||||
 | 
					    name = 'suspend-if-idle'#
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
        'systemd-timers': {
 | 
					        'systemd-timers': {
 | 
				
			||||||
            'suspend-if-idle': {
 | 
					            name: {
 | 
				
			||||||
                'command': '/opt/suspend_if_idle now',
 | 
					                'command': f'/opt/suspend_if_idle now {name}.service',
 | 
				
			||||||
                'when': 'minutely',
 | 
					                'when': 'minutely',
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue