Skip to content

Instantly share code, notes, and snippets.

@iyusa
Last active March 21, 2020 04:29
Show Gist options
  • Save iyusa/827069c08d8c80ef627b828868515233 to your computer and use it in GitHub Desktop.
Save iyusa/827069c08d8c80ef627b828868515233 to your computer and use it in GitHub Desktop.
[SystemD] #linux #systemd #local

Journal Daemon

# simple list
journalctl -u mikroserver -o cat

# reversed
journalctl -u mikroserver -o cat -r

# interactive
journalctl -u mikroserver -o cat -f
# /usr/lib/systemd/system/logserver.service
# atau di ubuntu:
# /lib/systemd/system/logserver.service
[Unit]
Description=Log server daemon Service
After=network.target
[Service]
PrivateTmp=yes
WorkingDirectory=/opt/logserver/
ExecStart=/opt/logserver/logserver.bin
Restart=always
RestartSec=10s
[Install]
WantedBy=default.target

Managing services for non-root users with systemd

Configuring a user unit

$ mkdir -p ~/.config/systemd/user

# add *.service to that folder

$ systemctl --user daemon-reload

We can now manage this service with systemd:

$ systemctl --user start worker # starts the service
$ systemctl --user stop worker # stops the service
$ systemctl --user restart worker # restarts the workers
$ systemctl --user status worker # shows us the service status

# If we want this service to start automatically when our user logs in, we have to enable it:

$ systemctl --user enable worker
$ systemctl --user disable worker

Viewing logs

$ journalctl -u worker
# or on older version
$ journalctl --user-unit worker

Starting user services at boot

By default, systemd starts enabled user units when the user logs in, and stops them once the user has logged out

$ sudo loginctl enable-linger USERNAME

# You can check the status for each user by:

$ sudo loginctl user-status USERNAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment