systemd
user`s service
# enable user`s systemd units on boot (lingering)
export NONROOTUSER=galactica
loginctl enable-linger "$NONROOTUSER"
# check
loginctl list-users
# force to edit systemd unit file for user` service
su "$NONROOTUSER"
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$UID/bus"
export XDG_RUNTIME_DIR=/run/user/$(id -u)
echo 'export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$UID/bus"' >> ~/.bashrc
echo 'export XDG_RUNTIME_DIR=/run/user/$(id -u)' >> ~/.bashrc
systemctl edit --user --force --full some-service.service
# enter systemd unit file
systemctl --user start some-service.service
systemctl --user enable some-service.service
[Unit]
Description=My Custom Service
After=default.target
Wants=mnt-kingston.automount
[Service]
Type=simple
WorkingDirectory=/mnt/kingston/influxdb-1.8.10-1
ExecStart=/mnt/kingston/influxdb-1.8.10-1/usr/bin/influxd run -config /mnt/kingston/influxdb-1.8.10-1/etc/influxdb/influxdb.conf
Restart=always
[Install]
WantedBy=default.target
systemctl --user start some-service.service
in some cases
unit for github runner under non root user
[Unit]
Description=Github runner for galactica ci tests in repo https://github.com/boogeroccam/galactica/settings/actions/runners
After=default.target
[Service]
Type=simple
WorkingDirectory=/home/devops
ExecStart=/home/devops/run.sh
Restart=always
RestartSec=5
[Install]
WantedBy=default.target
action runner
[Unit]
Description=github runner service
After=default.target
[Service]
Type=simple
Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/home/chat/.local/bin"
Environment=XDG_RUNTIME_DIR=/run/user/30001
Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/30001/bus
Environment=HOME=/home/chat
WorkingDirectory= /home/deploy/actions-runner/
ExecStart= /home/chat/actions-runner/run.sh
Restart=always
RestartSec=5
[Install]
WantedBy=default.target
systemd automount
sudo mkfs.ext4 /dev/xvdh
sudo mkdir /data
tee -a ~/mnt-kingston.mount <<EOT
[Unit]
Description=Mount partition
[Mount]
What=/dev/sdb1
Where=/mnt/kingston
Type=ext4
Options=rw,noatime
[Install]
WantedBy=multi-user.target
EOT
sudo mv ~/mnt-kingston.mount /etc/systemd/system/
tee -a ~/mnt-kingston.automount <<EOT
[Unit]
Description=Automount partition
ConditionPathExists=/mnt/kingston
[Automount]
Where=/mnt/kingston
TimeoutIdleSec=10
[Install]
WantedBy=multi-user.target
EOT
sudo mv ~/mnt-kingston.mount /etc/systemd/system/
sudo chown root:root /etc/systemd/system/mnt-kingston.mount /etc/systemd/system/mnt-kingston.automount
sudo chmod 755 /etc/systemd/system/mnt-kingston.mount /etc/systemd/system/mnt-kingston.automount
sudo systemctl daemon-reload
sudo systemctl enable --now data.automount
automount exfat
#!/bin/bash
path=/home/booger/subdisk
disk=/dev/nvme0n1p3
unit_filename=`echo $path | tr '/' '-' | cut -c 2-`
tee -a $unit_filename.mount <<EOT
[Unit]
Description=Mount partition
[Mount]
What=$disk
Where=$path
Type=exfat
Options=defaults,uid=1000,gid=1000,umask=002
[Install]
WantedBy=multi-user.target
EOT
sudo mv $unit_filename.mount /etc/systemd/system/
tee -a $unit_filename.automount <<EOT
[Unit]
Description=Automount partition
ConditionPathExists=$path
[Automount]
Where=$path
TimeoutIdleSec=10
[Install]
WantedBy=multi-user.target
EOT
sudo mv $unit_filename.automount /etc/systemd/system/
sudo chown root:root /etc/systemd/system/$unit_filename.mount /etc/systemd/system/$unit_filename.automount
sudo chmod 755 /etc/systemd/system/$unit_filename.mount /etc/systemd/system/$unit_filename.automount
sudo systemctl daemon-reload
sudo systemctl enable --now $unit_filename.automount
systemd
some adv unit for service
[Unit]
Description=pg-cache-sync service
After=network.target
[Service]
Type=simple
WorkingDirectory=/srv/nodesale-app/packages/pg-cache-sync/
ExecStart=/srv/nodesale-app/packages/pg-cache-sync/pg-cache-sync
Environment=DB_URL="postgresql://nsale:pass@10.24.1.7:5433/nsale"
Environment=HOST=0.0.0.0
Environment=PORT=8080
Environment=LOG_LEVEL=debug
Environment=LOG_FORMAT=json
Environment=SECRET_KEY=key
Environment=NODE_OPTIONS=--max-old-space-size=2048
Restart=always
RestartSec=5
LimitNOFILE=65535
TimeoutStopSec=30
; ProtectSystem=full
; ProtectHome=yes
PrivateTmp=true
NoNewPrivileges=true
SyslogIdentifier=pg-cache-sync
StandardOutput=syslog
StandardError=syslog
; MemoryLimit=500M
; CPUQuota=50%
; ExecStartPre=/usr/bin/bash -c "until nc -z -v -w30 10.24.1.7 5433; do echo 'Waiting for DB...'; sleep 5; done"
[Install]
WantedBy=multi-user.target