summaryrefslogtreecommitdiff
path: root/posts
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2020-12-28 20:36:35 -0700
committerAaron Ball <nullspoon@oper.io>2020-12-28 20:37:40 -0700
commit009b53e1c047420262d4e435f1b080dc6a314782 (patch)
treed987abba3186bbc619a17b7d0e83534b461e5aeb /posts
parentcdecc1ee4fde0e3b7983df858163ee934f36debf (diff)
downloadoper.io-009b53e1c047420262d4e435f1b080dc6a314782.tar.gz
oper.io-009b53e1c047420262d4e435f1b080dc6a314782.tar.xz
Update linux:non-root suspend with syntax highlighting
Diffstat (limited to 'posts')
-rw-r--r--posts/linux:non-root-suspend.rst (renamed from posts/linux:non-root-suspend.adoc)131
1 files changed, 67 insertions, 64 deletions
diff --git a/posts/linux:non-root-suspend.adoc b/posts/linux:non-root-suspend.rst
index d994dba..00bbea9 100644
--- a/posts/linux:non-root-suspend.adoc
+++ b/posts/linux:non-root-suspend.rst
@@ -1,8 +1,5 @@
Linux:Non-root Suspend
-=======================
-:author: Aaron Ball
-:email: nullspoon@oper.io
-
+======================
Several years ago I switched to a significantly less user-friendly distro.
Since this distro did so little for the end user, I had to start learning how
@@ -31,13 +28,19 @@ filesystem. If you would like to know more about the details of this
filesystem, its purpose, and other uses, take a quick peek at its man page. I
promise, it makes for good bathroom reading.
+
+.. code-block:: sh
+
man 5 sysfs
+
For today's use, we'll be looking at **/sys/power/state**. This interface is
used for, you guessed it, controlling kernel power states. What fun.
First, let's take a look at what power states are available to us.
+.. code-block:: sh
+
$ cat /sys/power/state
freeze mem disk
@@ -55,13 +58,16 @@ Without getting into the details of acpi states, here's what those three do.
If you want to learn more about Linux kernel power states, have a look at the
kernel documentation over at
-link:https://www.kernel.org/doc/html/latest/admin-guide/pm/sleep-states.html[kernel.org].
+`kernel.org <https://www.kernel.org/doc/html/latest/admin-guide/pm/sleep-states.html>`_.
Suspending to Memory
--------------------
-Suspending to memory is actually very easy. You just need to execute the following command.
+Suspending to memory is actually very easy. You just need to execute the
+following command.
+
+.. code-block:: sh
echo mem > /sys/power/state
@@ -74,6 +80,8 @@ Permission denied?
If you aren't root when you run that command though, you'll see...
+.. code-block:: sh
+
echo mem > /sys/power/state
-bash: /sys/power/state: Permission denied
@@ -83,43 +91,44 @@ could control system state without being granted root privs through sudo (or
worse, su), was to write an init script that set permissions on the state file
on service start. Here's the one I wrote.
-----
-#!/usr/bin/env bash
+.. code-block:: sh
-start() {
- chmod 664 /sys/power/state
- chgrp power /sys/power/state
-}
+ #!/usr/bin/env bash
-stop() {
- chmod 644 /sys/power/state
- chgrp root /sys/power/state
-}
+ start() {
+ chmod 664 /sys/power/state
+ chgrp power /sys/power/state
+ }
+
+ stop() {
+ chmod 644 /sys/power/state
+ chgrp root /sys/power/state
+ }
+
+ status() {
+ if [ "$(stat -c '%a:%G' /sys/power/state)" = '664:power' ]; then
+ printf 'running\n'
+ else
+ printf 'stopped\n'
+ fi
+ }
-status() {
- if [ "$(stat -c '%a:%G' /sys/power/state)" = '664:power' ]; then
- printf 'running\n'
- else
- printf 'stopped\n'
- fi
-}
+ if [ -z "$(getent group power)" ]; then
+ printf "No 'power' group found. Cannot proceed\n"
+ exit 2
+ fi
-if [ -z "$(getent group power)" ]; then
- printf "No 'power' group found. Cannot proceed\n"
- exit 2
-fi
+ if [ -z "${1:-}" ]; then
+ printf "usage: %s [start|stop|status]\n" "${0}"
+ exit 1
+ elif [ $1 = 'start' ] || [ $1 = 'stop' ] || [ $1 = 'status' ]; then
+ ${1}
+ else
+ printf "Unknown action '%s'\n" "${1}"
+ exit 1
+ fi
-if [ -z "${1:-}" ]; then
- printf "usage: %s [start|stop|status]\n" "${0}"
- exit 1
-elif [ $1 = 'start' ] || [ $1 = 'stop' ] || [ $1 = 'status' ]; then
- ${1}
-else
- printf "Unknown action '%s'\n" "${1}"
- exit 1
-fi
-----
Note that this init script requires that a 'power' group exist. We only want
trusted users to be able to suspend the system. To achieve this, the init
@@ -133,36 +142,30 @@ often have only one user. Regardless, if you want to have more than one user,
this init script will do the trick for you! If you find you don't care, I've
written you a less safe variant of this script!
-----
-#!/usr/bin/env bash
+.. code-block:: sh
-start() { chmod 666 /sys/power/state; }
-stop() { chmod 644 /sys/power/state; }
+ #!/usr/bin/env bash
-status() {
- if [ "$(stat -c '%a' /sys/power/state)" = '666' ]; then
- printf 'running\n'
- else
- printf 'stopped\n'
- fi
-}
+ start() { chmod 666 /sys/power/state; }
-if [ -z "${1:-}" ]; then
- printf "usage: %s [start|stop|status]\n" "${0}"
- exit 1
-elif [ $1 = 'start' ] || [ $1 = 'stop' ] || [ $1 = 'status' ]; then
- ${1}
-else
- printf "Unknown action %s\n" "${1}"
- exit 1
-fi
-----
+ stop() { chmod 644 /sys/power/state; }
+ status() {
+ if [ "$(stat -c '%a' /sys/power/state)" = '666' ]; then
+ printf 'running\n'
+ else
+ printf 'stopped\n'
+ fi
+ }
-Autobots! ... Suspend! ........
-
-
-[role="datelastedit"]
-Last edited: {docdate} {doctime}
+ if [ -z "${1:-}" ]; then
+ printf "usage: %s [start|stop|status]\n" "${0}"
+ exit 1
+ elif [ $1 = 'start' ] || [ $1 = 'stop' ] || [ $1 = 'status' ]; then
+ ${1}
+ else
+ printf "Unknown action %s\n" "${1}"
+ exit 1
+ fi
-// vim:set syntax=asciidoc:
+Autobots! ... Suspend! ........

Generated by cgit