Run commands automatically at startup

I want my system to automatically connect to my VPN on startup.
Nordvpn has an autoconnect feature however I also have to run the command sudo systemctl start nordvpnd.service at startup otherwise nordvpn will error out.
How can I set my system up to run these commands automatically at start up?
Here are the results of my garuda-inxi

Kernel: 6.3.9-zen1-1-zen arch: x86_64 bits: 64 compiler: gcc v: 13.1.1
parameters: BOOT_IMAGE=/@/boot/vmlinuz-linux-zen
root=UUID=94978e7e-3bb8-49ab-b654-20a90c19d22c rw rootflags=subvol=@
quiet quiet splash rd.udev.log_priority=3 vt.global_cursor_default=0
loglevel=3 ibt=off
Desktop: KDE Plasma v: 5.27.6 tk: Qt v: 5.15.10 wm: kwin_x11 vt: 1
dm: SDDM Distro: Garuda Linux base: Arch Linux
Machine:
Type: Desktop Mobo: Micro-Star model: MAG B660M MORTAR WIFI DDR4 (MS-7D42)
v: 1.0 serial: <superuser required> UEFI: American Megatrends LLC. v: 1.C0
date: 05/19/2023
CPU:
Info: model: 12th Gen Intel Core i5-12400F bits: 64 type: MT MCP
arch: Alder Lake gen: core 12 level: v3 note: check built: 2021+
process: Intel 7 (10nm ESF) family: 6 model-id: 0x97 (151) stepping: 2
microcode: 0x2D
Topology: cpus: 1x cores: 6 tpc: 2 threads: 12 smt: enabled cache:
L1: 480 KiB desc: d-6x48 KiB; i-6x32 KiB L2: 7.5 MiB desc: 6x1.2 MiB
L3: 18 MiB desc: 1x18 MiB
Speed (MHz): avg: 1778 high: 3597 min/max: 800/5600 scaling:
driver: intel_pstate governor: powersave cores: 1: 1879 2: 1110 3: 3597
4: 2208 5: 1178 6: 1663 7: 800 8: 938 9: 2210 10: 2561 11: 799 12: 2404
bogomips: 59904
Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx
Vulnerabilities: <filter>
Graphics:
Device-1: AMD Navi 24 [Radeon RX 6400/6500 XT/6500M] vendor: XFX
driver: amdgpu v: kernel arch: RDNA-2 code: Navi-2x process: TSMC n7 (7nm)
built: 2020-22 pcie: gen: 4 speed: 16 GT/s lanes: 16 ports:
active: HDMI-A-1 empty: DP-1 bus-ID: 03:00.0 chip-ID: 1002:743f
class-ID: 0300
Display: x11 server: X.Org v: 21.1.8 with: Xwayland v: 23.1.2
compositor: kwin_x11 driver: X: loaded: amdgpu unloaded: modesetting,radeon
alternate: fbdev,vesa dri: radeonsi gpu: amdgpu display-ID: :0 screens: 1
Screen-1: 0 s-res: 1920x1080 s-dpi: 96 s-size: 508x285mm (20.00x11.22")
s-diag: 582mm (22.93")
Monitor-1: HDMI-A-1 mapped: HDMI-A-0 model: Dell P2219H serial: <filter>
built: 2021 res: 1920x1080 hz: 60 dpi: 102 gamma: 1.2
size: 476x267mm (18.74x10.51") diag: 546mm (21.5") ratio: 16:9 modes:
max: 1920x1080 min: 720x400
API: OpenGL v: 4.6 Mesa 23.1.3 renderer: AMD Radeon RX 6500 XT (navi24
LLVM 15.0.7 DRM 3.52 6.3.9-zen1-1-zen) direct-render: Yes
Audio:
Device-1: Intel Alder Lake-S HD Audio vendor: Micro-Star MSI
driver: snd_hda_intel v: kernel alternate: snd_sof_pci_intel_tgl
bus-ID: 00:1f.3 chip-ID: 8086:7ad0 class-ID: 0403
Device-2: AMD Navi 21/23 HDMI/DP Audio driver: snd_hda_intel v: kernel
pcie: gen: 4 speed: 16 GT/s lanes: 16 bus-ID: 03:00.1 chip-ID: 1002:ab28
class-ID: 0403
API: ALSA v: k6.3.9-zen1-1-zen status: kernel-api tools: N/A
Server-1: PipeWire v: 0.3.72 status: active with: 1: pipewire-pulse
status: active 2: wireplumber status: active 3: pipewire-alsa type: plugin
4: pw-jack type: plugin tools: pactl,pw-cat,pw-cli,wpctl
Network:
Device-1: Intel Alder Lake-S PCH CNVi WiFi driver: iwlwifi v: kernel
bus-ID: 00:14.3 chip-ID: 8086:7af0 class-ID: 0280
IF: wlo1 state: up mac: <filter>
Device-2: Realtek RTL8125 2.5GbE vendor: Micro-Star MSI driver: r8169
v: kernel pcie: gen: 2 speed: 5 GT/s lanes: 1 port: 4000 bus-ID: 06:00.0
chip-ID: 10ec:8125 class-ID: 0200
IF: enp6s0 state: down mac: <filter>
IF-ID-1: virbr0 state: down mac: <filter>
Bluetooth:
Device-1: Intel AX201 Bluetooth driver: btusb v: 0.8 type: USB rev: 2.0
speed: 12 Mb/s lanes: 1 mode: 1.1 bus-ID: 1-14:6 chip-ID: 8087:0026
class-ID: e001
Report: bt-adapter ID: hci0 rfk-id: 0 state: down
bt-service: enabled,running rfk-block: hardware: no software: yes
address: <filter>
Drives:
Local Storage: total: 931.51 GiB used: 97.32 GiB (10.4%)
SMART Message: Unable to run smartctl. Root privileges required.
ID-1: /dev/nvme0n1 maj-min: 259:0 vendor: Western Digital
model: WD BLACK SN750 SE 1TB size: 931.51 GiB block-size: physical: 512 B
logical: 512 B speed: 63.2 Gb/s lanes: 4 tech: SSD serial: <filter>
fw-rev: 711250WD temp: 35.9 C scheme: GPT
Partition:
ID-1: / raw-size: 931.22 GiB size: 931.22 GiB (100.00%)
used: 97.32 GiB (10.5%) fs: btrfs dev: /dev/nvme0n1p2 maj-min: 259:2
ID-2: /boot/efi raw-size: 300 MiB size: 299.4 MiB (99.80%)
used: 576 KiB (0.2%) fs: vfat dev: /dev/nvme0n1p1 maj-min: 259:1
ID-3: /home raw-size: 931.22 GiB size: 931.22 GiB (100.00%)
used: 97.32 GiB (10.5%) fs: btrfs dev: /dev/nvme0n1p2 maj-min: 259:2
ID-4: /var/log raw-size: 931.22 GiB size: 931.22 GiB (100.00%)
used: 97.32 GiB (10.5%) fs: btrfs dev: /dev/nvme0n1p2 maj-min: 259:2
ID-5: /var/tmp raw-size: 931.22 GiB size: 931.22 GiB (100.00%)
used: 97.32 GiB (10.5%) fs: btrfs dev: /dev/nvme0n1p2 maj-min: 259:2
Swap:
Kernel: swappiness: 133 (default 60) cache-pressure: 100 (default)
ID-1: swap-1 type: zram size: 31.2 GiB used: 489.5 MiB (1.5%)
priority: 100 dev: /dev/zram0
Sensors:
System Temperatures: cpu: 36.0 C mobo: N/A gpu: amdgpu temp: 40.0 C
mem: 40.0 C
Fan Speeds (RPM): N/A gpu: amdgpu fan: 0
Info:
Processes: 375 Uptime: 2h 2m wakeups: 0 Memory: available: 31.2 GiB
used: 3.94 GiB (12.6%) Init: systemd v: 253 default: graphical
tool: systemctl Compilers: gcc: 13.1.1 Packages: pm: pacman pkgs: 1381
libs: 385 tools: octopi,paru,yay Shell: fish v: 3.6.1 default: Bash
v: 5.1.16 running-in: konsole inxi: 3.3.27
Garuda (2.6.16-1):
System install date:     2023-06-24
Last full system update: 2023-07-02 ↻
Is partially upgraded:   No
Relevant software:       snapper NetworkManager dracut
Windows dual boot:       No/Undetected
Failed units:

Perhaps add a sleep time delay for your VPN startup of 5-10 seconds as a race condition could be responsible for the failure.

2 Likes

but how do I run the systemctl command? It's not a timing issue the service will not start on its own no matter how long the machine is on

sudo systemctl enable --now nordvpnd.service

Then it will automatically start at boot.

5 Likes

Thank you very much! I have just one follow up question, what would the syntax be for this command to start on boot? I have tried net-enable --now. but there's a part of the syntax I am not understanding.
sudo virsh net-start default

That command is specific to systemd services. If you want to use it for starting another command at boot, you first need to create a systemd service that runs your command.

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.