On this page
Once you have finished setting up your first VPS from scratch and secured your login with SSH basics for beginners, the real stage begins: running software and keeping it alive. A server is no use to you as a silent box; its value lies in the services it provides: a website that works, a database that responds, a job that runs on schedule. This guide takes you from the basic concepts to writing a custom systemd unit and scheduling jobs, step by step and with real commands you can copy.
The difference between a service and a process
Before any command, we need to clear up a common confusion. A process is any program being executed at a given moment; it has a unique identifier called a PID, an owner (a user), memory and a share of the CPU. When you type a command in the terminal, the system creates a process to run it, and it may finish after a few seconds or keep running for days.
A service, sometimes called a daemon, is a program designed to run permanently in the background without direct intervention from you, and it usually starts automatically when the system boots. The Nginx server is a service, the MySQL database is a service, and the SSH server itself (sshd) is a service. At its core, a service is a process (or a group of processes), but the system manages it on your behalf: it starts it, monitors it and restarts it if it crashes.
The relationship between them is hierarchical: when you start the Nginx service, systemd creates a master process that may spawn worker processes. Managing the service means managing its high-level lifecycle (start/stop/enable), while managing a process means dealing with one specific running instance (monitoring it, ending it or lowering its priority).
| Concept | Definition | How you handle it | Example |
|---|---|---|---|
| Process | A program being executed, with a PID | ps, top, kill | A tar command compressing a file right now |
| Service (daemon) | A permanent background process managed by the system | systemctl, journalctl | Nginx, MySQL, sshd |
| Unit | systemd's definition of a manageable resource | .service and .timer files | nginx.service |
| Signal | A short message sent to a process to direct it | kill, pkill | SIGTERM, SIGKILL |
Grasping this distinction saves you costly mistakes. For example, "killing" a running Nginx process with kill may cause systemd to restart it immediately (because its job is to keep it alive), whereas the right way to actually stop it is through the service with systemctl stop.
What systemd is and why it dominates Linux
systemd is the first process that runs when a modern Linux system boots; it always has PID 1 and is the "parent" of all other processes. Its core job is to be the init system: it decides what runs, in what order, and how it is managed throughout the server's life. systemd replaced the old SysVinit system in most major distributions from around 2015, and today it is the de facto standard on Ubuntu, Debian, CentOS, AlmaLinux, Rocky Linux, Fedora and openSUSE.
It dominates because it is more than just a boot loader: it is an integrated framework for managing resources. It handles everything through a unified concept called a unit, which is a text file that describes a manageable resource. There are many unit types, but the most important ones for day-to-day operators are:
| Unit type | Extension | Purpose |
|---|---|---|
| service | .service | A service or daemon (the most commonly used) |
| socket | .socket | A network port or socket that activates a service on demand |
| timer | .timer | Schedules a unit to run (a modern alternative to cron) |
| target | .target | A group of units representing a system state (such as multi-user) |
| mount | .mount | A file system mount point |
| path | .path | Runs a unit when a file/folder changes |
The systemd features that matter to you directly: starting services in parallel (faster boot), automatic restarts of crashed services, unified central logging through journald, and precise dependency management (the database service doesn't start before the network is ready). Every command you type with systemctl is really a conversation with this central manager.
A note on old distributions: some very old systems or stripped-down containers may not use systemd (they rely on OpenRC or SysVinit). But any modern commercial VPS on Ubuntu 20.04+, Debian 11+ or AlmaLinux 8+ comes with systemd by default, which is what we assume throughout this guide.
Service states and the systemctl status command
Every service in systemd is in a specific state at any moment. Understanding these states is the starting point of any diagnosis, because the first question is always: "Is the service even running?" The command that answers it is systemctl status:
systemctl status nginxIt shows you rich output: the first line carries the overall state (such as active (running)), followed by whether the service is enabled at boot, when it started, the main process ID (Main PID), memory usage and the last few lines of its log. This output alone is often enough to diagnose 80% of problems.
The states you will see in the Active field:
| State | Meaning | What to do |
|---|---|---|
active (running) | The service is running normally right now | Nothing; everything is fine |
active (exited) | Ran once and finished successfully (a one-time job) | Normal for setup services |
active (waiting) | Running but waiting for an event (a socket, for example) | Normal |
inactive (dead) | Stopped, not running | Start it if you need it |
failed | Tried to run but crashed or exited with an error | Read the log immediately |
activating | Currently starting up | Wait a moment, then check |
deactivating | Currently stopping | Wait for the stop to complete |
The most important distinction here is between inactive and failed. The first means the service is quietly stopped (perhaps because you stopped it or it never started), while failed means it tried to run and failed, which is a red flag that calls for reading the log. Don't confuse a service being "enabled" with it being "active": enabling means it will start automatically at the next boot, but it doesn't start it now. A service can be enabled and inactive at the same time (enabled, but the system hasn't been rebooted yet, or you stopped it manually).
A service's lifecycle moves between these states through systemctl commands: from inactive to active with start, and back with stop, and from active to active (a restart) with restart. If it crashes while running, it moves to failed, and from there it goes back to active with restart after you fix the cause, or with reset-failed to clear the failure flag without starting it.
Essential systemctl commands
systemctl is your Swiss Army knife for managing services. Learning a handful of its commands is enough to run a whole server. Here is the reference you will keep coming back to:
| Command | What it does |
|---|---|
systemctl start nginx | Starts the service now (doesn't affect boot) |
systemctl stop nginx | Stops the service now |
systemctl restart nginx | Stops it, then starts it (to apply fundamental changes) |
systemctl reload nginx | Re-reads the configuration without stopping (doesn't cut connections) |
systemctl reload-or-restart nginx | Reloads if possible, otherwise restarts |
systemctl status nginx | Shows its detailed status and the latest log lines |
systemctl enable nginx | Makes it start automatically at boot |
systemctl disable nginx | Cancels its automatic start at boot |
systemctl enable --now nginx | Enables it and starts it now in one command |
systemctl disable --now nginx | Disables it and stops it now in one command |
systemctl is-active nginx | Prints only active or inactive (useful in scripts) |
systemctl is-enabled nginx | Prints enabled or disabled |
systemctl mask nginx | Prevents it from running at all, even manually (a strict lock) |
systemctl unmask nginx | Lifts the lock |
systemctl daemon-reload | Re-reads unit files after editing them |
The difference between restart and reload deserves a pause, because it is the most misunderstood. restart kills the process completely and starts from scratch, which cuts all ongoing connections for a few seconds. reload sends a signal to the service to re-read its configuration file without stopping, so the current connections stay alive. The practical rule: for simple configuration changes (such as adding a new site in Nginx), use reload; for upgrading the program itself or fundamental changes, use restart. But note: not all services support reload, which is why reload-or-restart exists to choose the right one automatically.
To see all services and their states at once:
systemctl list-units --type=serviceAnd to see only the services enabled at boot:
systemctl list-unit-files --type=service --state=enabledAnd to show only the failed services, the first thing I check when there is any problem:
systemctl --failedEnabling at boot: the crucial difference
A point where beginners often go wrong: starting a service with start doesn't make it start after a reboot. If you reboot the server, you'll find your site down because you forgot enable. The golden rule for any production service: always use enable --now to make sure it runs now and will run after every boot:
systemctl enable --now nginxThe reverse is also true: a service you don't need should be disabled with disable --now to free up resources and prevent it from starting at boot. But be careful about disabling services whose function you don't know: disabling a vital system service (such as the network service or log management) can make your server unreachable after the next boot. The rule: don't disable what you don't understand.
Reading logs with journalctl
When a service fails, the very next question is "why?", and the answer is always in the logs. In the systemd world, all service logs are collected in a central logging system called journald and read with the journalctl command. This is one of the most powerful diagnostic tools, and mastering it saves hours of searching.
The simplest use is to read a specific service's log with the -u (unit) option:
journalctl -u nginxBut the log can be huge. What is most useful in practice is following the log live while the problem is happening, by adding -f (follow), just like watching a constantly updating event feed:
journalctl -u nginx -fLeave this command running in one window, then restart the service or send a request to the site in another window, and watch the errors appear in real time. This is the fastest way to link a particular action to the error it causes.
A reference of the most important journalctl options:
| Option | What it does |
|---|---|
-u nginx | Limits the log to a specific unit |
-f | Follows the log live (live tail) |
-b | The current boot's log only |
-b -1 | The previous boot's log |
-p err | Errors only (priority = error and above) |
-n 50 | Only the last 50 lines |
--since "1 hour ago" | Since an hour ago |
--since today | Since the start of the day |
--since "2026-06-13 09:00" | Since a specific time |
-r | Reverse order (newest first) |
-k | Kernel messages only, like dmesg |
--no-pager | No pager, for copying and scripts |
--disk-usage | Disk size of the logs |
Common practical examples. To see all errors since the last boot, the first thing I check when the system behaves strangely:
journalctl -p err -bAnd to check what happened to a service in the last hour only, so you focus on the period that matters:
journalctl -u mysql --since "1 hour ago"The priority levels in -p go from most to least severe: emerg, then alert, crit, err, warning, notice, info and debug. When you write -p err, you are asking for everything at the err level or more severe.
Managing log size
journald keeps logs on disk, and over time they can grow until they eat up a considerable amount of space on a VPS with limited storage. To check the current size:
journalctl --disk-usageAnd to shrink them, for example keeping only the last 200 megabytes or deleting anything older than two weeks:
sudo journalctl --vacuum-size=200M
sudo journalctl --vacuum-time=2weeksFor a permanent setting, edit /etc/systemd/journald.conf and set SystemMaxUse=200M, then restart the journald service. This is a small step, but it saves you from the disk suddenly filling up, a common cause of failure on servers that weren't monitored well. Systematically monitoring disk space is an essential part of monitoring a VPS.
Monitoring processes: ps, top, htop and free
We now move from services (the high level) to processes (the low level). When your server slows down or uses up all its memory, you need to see what is actually happening: which process is devouring the CPU or memory? This is where the monitoring tools come in.
The snapshot tool: ps
ps takes an instant "snapshot" of the running processes. The most commonly used form is ps aux, which shows all processes for all users:
ps auxThe important output columns: USER (the owner), PID (the identifier), %CPU and %MEM (usage percentages), STAT (the process state) and COMMAND (the full command). The real power of ps shows up with sorting. To find the ten processes using the most memory, a very common question when RAM runs out:
ps aux --sort=-%mem | headAnd for the CPU instead of memory, switch the key to -%cpu:
ps aux --sort=-%cpu | headThe minus sign before %mem means descending order (largest first), and head keeps only the top ten. These two commands are among the ones you will repeat most in practice.
The live tool: top
While ps is a static snapshot, top is a dashboard that refreshes every two seconds, showing the system as it breathes:
topThe top line shows the load average (we explain it shortly), followed by a summary of memory and CPU, then the list of processes, sorted by default by CPU usage. Inside top you can press M to sort by memory, P for CPU, k to send a kill signal to a process, and q to quit. It comes preinstalled on almost every distribution, so there are no extra dependencies.
The favorite tool: htop
htop is top with a much nicer and easier interface: colors, usage bars for each CPU core, horizontal and vertical scrolling with the arrow keys, and ending processes at the press of a key without noting the PID. It isn't always preinstalled, so install it first:
sudo apt install htop # On Ubuntu/Debian
sudo dnf install htop # On AlmaLinux/CentOS/RHEL
htopInside htop: the arrow keys move between processes, F6 sorts by a column, F9 sends a signal (kill), F5 shows a tree view of the parent-child relationships between processes, and F10 or q quits. For most users, htop is the favorite day-to-day tool for monitoring resources visually.
Memory: free
To see the memory state alone clearly, use free with -h (human-readable) to show the numbers in readable units:
free -hYou will see the columns total (total memory), used, free and available (actually available to new applications). An important point that often confuses beginners: don't panic if you see a very low free. Linux uses spare memory as a cache to speed up the disk, but it releases it immediately when needed. The column that really matters to you is available, not free.
| Tool | Type | Strength | When to use it |
|---|---|---|---|
ps | Static snapshot | Fast, sortable and scriptable | A quick query or inside a script |
top | Live, refreshing | Installed everywhere, no dependencies | Quick monitoring when htop isn't available |
htop | Live, interactive | Colors, tree view, easy killing | Day-to-day visual monitoring |
free | A memory snapshot | Focused on RAM and swap | Checking memory pressure |
Understanding load average
At the top of the output of top, htop and uptime, you will find three numbers such as 0.52, 0.43, 0.38. This is the load average: the average number of processes waiting for the CPU (or using it) over the last minute, five minutes and fifteen minutes, respectively. Reading it is simple but crucial: compare the number with the number of CPU cores.
If your server has one core, a load of 1.0 means the CPU is 100% busy with nothing waiting (the ideal limit). Above 1.0 means processes are waiting their turn (congestion). If you have 4 cores, a load of 4.0 is the full limit, and 2.0 means half capacity. To find the number of cores:
nprocThe practical rule: a load average below the number of cores = healthy; equal to it = at the limit; persistently above it = the server is loaded beyond its capacity and needs optimization or an upgrade. Looking at the three numbers together reveals the trend: if the first number (one minute) is much higher than the third (15 minutes), the load is rising now; the reverse means a passing peak is subsiding.
Ending processes and signals
Sometimes a process freezes or consumes resources wildly, and you need to end it. In Linux we don't "kill" processes in the crude sense; we send them signals, short messages that ask them for a particular behavior. The main tool is kill, and its name is a little misleading, because it actually sends any signal, not just a kill.
The most important signals you will use:
| Signal | Number | Meaning | Behavior |
|---|---|---|---|
| SIGTERM | 15 | Polite termination (the default) | Asks the process to shut down cleanly |
| SIGKILL | 9 | Immediate forced kill | Ends it immediately without cleanup |
| SIGHUP | 1 | Re-read the configuration | Usually reloads the settings |
| SIGINT | 2 | Interrupt | Equivalent to Ctrl+C in the terminal |
| SIGSTOP | 19 | Pause | Freezes the process (cannot be ignored) |
| SIGCONT | 18 | Resume | Continues a process paused with SIGSTOP |
The golden rule: always start with SIGTERM. The kill command without an option sends SIGTERM by default, which asks the process to close itself cleanly: it saves its files, closes its connections and then exits:
kill 1234If the process is completely frozen and doesn't respond to SIGTERM, only then do you resort to SIGKILL (number 9), a forced termination that the process can neither ignore nor respond to gracefully:
kill -9 1234A common, dangerous mistake: rushing to kill -9 as if it were the default solution. SIGKILL gives the process no chance to save its data or close its files, and it can leave corrupted temporary files or a database in an inconsistent state. Use it only as a last resort after SIGTERM fails, and wait a few seconds between the two attempts to give the process a chance to respond.
Killing by name: killall and pkill
Sometimes you don't know the PID but you know the program's name. killall ends all processes with the exact full name, and pkill is more flexible because it accepts partial patterns:
killall firefox # Ends all processes named exactly firefox
pkill -f "python script" # Ends any process whose command line matches the pattern
pkill -u www-data # Ends all processes of the www-data userThe -f option in pkill matches the full command line, not just the name, which is useful for Python or Node processes that all carry the generic name python or node. But be very careful here: a loose pattern in pkill can end processes you didn't intend. The preventive rule: use pgrep first (the same syntax as pkill, but it only prints the matches without killing) to make sure you are targeting what you want:
pgrep -fa "python script" # Shows what will be killed before you kill itRemember the most important warning from the start of this guide: if the process belongs to a managed systemd service (such as Nginx), killing it with kill is usually pointless because systemd will restart it. The right way is systemctl stop, not chasing the PID.
Priorities: nice and renice
Not all processes are equally important. A heavy backup process should not slow down the web server serving your visitors. This is where the concept of priority (niceness) comes in: a value that tells the kernel scheduler how "nice" a process is toward others when sharing the CPU.
The niceness value ranges from -20 (highest priority, selfish) to +19 (lowest priority, generous), and the default is 0. The naming logic is inverted and can be confusing: the higher the value (the "nicer" the process), the lower the priority, because the process "yields" the CPU to others.
| nice value | Priority | Practical meaning |
|---|---|---|
| -20 | Highest | Hogs the CPU; rarely used |
| -10 | High | For time-sensitive tasks |
| 0 | Normal | The default for all processes |
| +10 | Low | For non-urgent background tasks |
| +19 | Lowest | Runs only when nobody else wants the CPU |
To start a process with low priority from the beginning, use nice (negative values require root privileges):
nice -n 15 tar -czf backup.tar.gz /var/wwwThis runs the backup command at priority +15, so it doesn't compete with important services and runs quietly in the background. To change the priority of a process that is already running, use renice with the PID:
renice -n 10 -p 1234Or for all processes of a particular user at once:
sudo renice -n 10 -u backupuserAn expert tip: lowering the priority (nice) of heavy recurring tasks, such as backups, log compression and virus scans, is an excellent habit that keeps your server responsive under pressure. Conversely, raising priority (negative values) is rarely the right fix; it is usually better to address the cause of the slowness or upgrade resources rather than forcing the kernel to favor one process at the expense of the rest. To secure the server under load, also see the practices in VPS security hardening to stop malicious processes from draining resources in the first place.
Writing a custom systemd unit
So far we have managed ready-made services. But the real power of systemd shows when you turn your own application into a managed service: it starts automatically, restarts on a crash and logs to journald. This is far cleaner than running the application with nohup or screen and leaving it to chance.
Suppose you have a Node.js application listening on a port. Create a unit file in /etc/systemd/system/:
sudo nano /etc/systemd/system/myapp.serviceAnd put the following definition in it:
[Unit]
Description=My Node.js Application
After=network.target
[Service]
Type=simple
User=www-data
WorkingDirectory=/var/www/myapp
ExecStart=/usr/bin/node /var/www/myapp/server.js
Restart=on-failure
RestartSec=5
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.targetLet's break this file down, because every line is deliberate:
- [Unit] describes the unit and its relationships.
Descriptionis text shown instatus.After=network.targetmakes sure your service doesn't start before the network is ready. - [Service] is the heart of the definition.
Type=simplemeansExecStartis the main process directly.Usersets the user the service runs as (don't run it as root unless necessary: the principle of least privilege).WorkingDirectoryis the working folder.ExecStartis the full command with absolute paths.Restart=on-failuremakes systemd restart it automatically if it crashes, andRestartSec=5waits 5 seconds between attempts.Environmentpasses environment variables. - [Install] specifies when it is activated on
enable.WantedBy=multi-user.targetmeans it starts in the normal multi-user operating mode.
After creating or editing the file, you must tell systemd to re-read the units, then enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable --now myapp
sudo systemctl status myappA very common mistake: forgetting daemon-reload after editing the unit file. systemd stores a copy of the definition in memory, so it won't see your changes until you force it to re-read. If you edited the file and the change seems not to have been applied, the first thing to check is whether you ran daemon-reload. Another mistake is relative paths in ExecStart; systemd doesn't assume a working directory, so always use full absolute paths for the program and its files.
The Restart values are worth knowing: no (no restart), on-failure (only on exiting with an error, the most common), always (always, even on a normal exit) and on-abnormal (on a crash or being killed by a signal). For most web applications, on-failure is the balanced choice.
Scheduling: cron vs. systemd timers
Many server tasks are recurring: a nightly backup, cleaning up temporary files, renewing SSL certificates. There are two ways to schedule them: the classic cron and the modern systemd timers.
Classic cron
cron is a scheduling service that has existed for decades, simple and reliable. You edit your job table with:
crontab -eEach job line consists of five time fields followed by the command. The five fields, in order:
| Field | Range | Meaning |
|---|---|---|
| First | 0-59 | Minute |
| Second | 0-23 | Hour |
| Third | 1-31 | Day of month |
| Fourth | 1-12 | Month |
| Fifth | 0-7 | Day of week (0 and 7 = Sunday) |
The * symbol means "every value." An example that runs a backup script every day at 3:30 a.m.:
30 3 * * * /usr/local/bin/backup.shOther common pattern examples: */15 * * * * every 15 minutes, 0 * * * * every hour on the hour, 0 0 * * 0 every Sunday at midnight, 0 2 1 * * on the first of every month at 2 a.m. A practical tip: redirect the script's output to a log file (>> /var/log/backup.log 2>&1), because cron runs silently, and without this you won't know whether the job failed.
Modern systemd timers
The modern alternative is timers, which are systemd units that run a service at specific times. You need two files: a service (.service) describing what runs, and a timer (.timer) describing when. First create /etc/systemd/system/backup.service:
[Unit]
Description=Daily Backup Job
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.shThen the timer /etc/systemd/system/backup.timer:
[Unit]
Description=Run backup daily at 3:30 AM
[Timer]
OnCalendar=*-*-* 03:30:00
Persistent=true
[Install]
WantedBy=timers.targetOnCalendar sets the schedule in systemd's time syntax (here: every day at 3:30 a.m.). Persistent=true is a powerful feature: if the server is off at the scheduled time, the job runs as soon as it next boots instead of being missed, which cron doesn't do. Enable the timer (note that you enable the .timer, not the .service):
sudo systemctl daemon-reload
sudo systemctl enable --now backup.timer
systemctl list-timersThe list-timers command shows all timers and when they will next run, an excellent tracking dashboard. When should you choose which? The comparison:
| Criterion | cron | systemd timer |
|---|---|---|
| Simplicity | Simpler, one line | More complex, two files |
| Missed jobs | Missed if the server is off | Run later with Persistent |
| Logging | Manual, to a file | Automatic, in journald |
| Dependencies | Not supported | Supports After/Requires |
| Monitoring | No unified tool | list-timers and status |
| Availability | Everywhere | Requires systemd |
The practical rule: for a simple, quick job, cron is enough and familiar. For an important job that needs reliable logging, must not be missed or depends on other services, choose a systemd timer. Both are valid; choose according to importance and complexity.
Diagnosing a failed service: a practical method
Let's bring everything together in a real-world scenario. You visit your site and find it down. Here is an organized, step-by-step method instead of floundering.
Step 1: Check the status. Always start with status to know where you stand:
systemctl status nginxIf you see failed, go straight to the log. Step 2: Read the cause. The last lines of status give hints, but the full log tells the whole story:
journalctl -u nginx -n 50 --no-pagerLook for words such as error, failed, permission denied or address already in use. These point directly to the cause: a configuration error, a missing permission, or a port taken by another process.
Step 3: Check the configuration before restarting. Many services provide a configuration test. Nginx, for example:
sudo nginx -tIf it reports an error on a particular line, fix it before any attempt to start: restarting a service with a broken configuration will not succeed.
Step 4: Look for port conflicts. If the error is "address already in use," find out what is occupying the port:
sudo ss -tlnp | grep :80Step 5: Restart and watch. After the fix, restart and follow the log live to confirm that it starts successfully this time:
sudo systemctl restart nginx
journalctl -u nginx -fIf it returns to active (running) and stays stable for a few seconds, you have succeeded. If it keeps entering a fail-and-restart loop, the cause hasn't been fixed yet, and you need to go back to the log in more depth. This method (status, log, configuration, port, restart while watching) solves the vast majority of service failures.
Frequently asked questions
What is the difference between systemctl restart and reload?
restart stops the service completely and then starts it again, cutting ongoing connections for a few seconds and applying any change, however fundamental. reload asks the service to re-read its configuration file without stopping, so connections stay alive, but it only suits configuration changes that support hot reloading. The rule: reload for simple changes, restart for upgrades and fundamental changes.
My service runs, but it doesn't start after a reboot. Why?
Because you only started it with systemctl start, and that doesn't make it permanent. start runs it in the current session only, while enable is what adds it to the list of services that start automatically at boot. The fix: run systemctl enable --now nginx to make sure it runs now and after every boot.
When should I use kill -9, and when should I avoid it?
Use it only as a last resort. Always start with a regular kill (which sends SIGTERM), which asks the process to shut down cleanly and save its data. If it stays frozen and doesn't respond after a few seconds, only then use kill -9 (SIGKILL), which ends it forcibly. Overusing -9 can corrupt files or leave databases in an inconsistent state, because it gives the process no chance to clean up.
How do I find the process that is eating all the memory?
Use ps aux --sort=-%mem | head to see the top ten memory-consuming processes instantly, or open htop and press F6 to sort by the MEM column. Remember that the column that matters in free -h is available, not free, because Linux uses spare memory as a cache that it releases when needed.
I edited a systemd unit file and nothing changed. Why?
Because you didn't run sudo systemctl daemon-reload after the edit. systemd keeps a copy of the unit definition in memory, so it doesn't see your changes to the file until you force it to re-read the units. After daemon-reload, run systemctl restart for the service to actually apply the new definition to the running instance.
What does load average mean, and how do I know my server is overloaded?
It is the average number of processes using or waiting for the CPU over the last one, five and fifteen minutes. Compare it with the number of cores (which you get with nproc): if it is lower than the number of cores, the server is healthy; if it is persistently higher, the server is loaded beyond its capacity and you need to optimize performance or upgrade resources. Comparing the three numbers shows whether the load is rising or falling.
What is the difference between cron and a systemd timer, and which should I choose?
cron is simpler (one line), familiar and available everywhere, but it misses jobs if the server is off at the scheduled time and doesn't log automatically. A systemd timer is more complex (it needs two files), but it logs to journald, supports running missed jobs through Persistent=true, and integrates with service dependencies. Choose cron for simple jobs, and a timer for critical jobs that must not be missed or that need reliable tracking.
How do I stop a system service properly instead of killing its processes?
Don't chase the PID with kill, because systemd will restart the service immediately, since its job is to keep it alive. The right way is systemctl stop nginx to stop it temporarily, or systemctl disable --now nginx to stop it and prevent it from starting at boot. To prevent it from running at all, even manually, use systemctl mask, and unmask to lift the lock.
Frequently asked questions
What is the difference between systemctl restart and reload?
restart stops the service completely and then starts it again, cutting ongoing connections for a few seconds and applying any change, however fundamental. reload asks the service to re-read its configuration file without stopping, so connections stay alive, but it only suits configuration changes that support hot reloading. The rule: reload for simple changes, restart for upgrades and fundamental changes.
My service runs, but it doesn't start after a reboot. Why?
Because you only started it with systemctl start, and that doesn't make it permanent. start runs it in the current session only, while enable is what adds it to the list of services that start automatically at boot. The fix: run systemctl enable --now nginx to make sure it runs now and after every boot.
When should I use kill -9, and when should I avoid it?
Use it only as a last resort. Always start with a regular kill (which sends SIGTERM), which asks the process to shut down cleanly and save its data. If it stays frozen and doesn't respond after a few seconds, only then use kill -9 (SIGKILL), which ends it forcibly. Overusing -9 can corrupt files or leave databases in an inconsistent state, because it gives the process no chance to clean up.
How do I find the process that is eating all the memory?
Use ps aux --sort=-%mem | head to see the top ten memory-consuming processes instantly, or open htop and press F6 to sort by the MEM column. Remember that the column that matters in free -h is available, not free, because Linux uses spare memory as a cache that it releases when needed.
I edited a systemd unit file and nothing changed. Why?
Because you didn't run sudo systemctl daemon-reload after the edit. systemd keeps a copy of the unit definition in memory, so it doesn't see your changes to the file until you force it to re-read the units. After daemon-reload, run systemctl restart for the service to actually apply the new definition to the running instance.
What does load average mean, and how do I know my server is overloaded?
It is the average number of processes using or waiting for the CPU over the last one, five and fifteen minutes. Compare it with the number of cores (which you get with nproc): if it is lower than the number of cores, the server is healthy; if it is persistently higher, the server is loaded beyond its capacity and you need to optimize performance or upgrade resources. Comparing the three numbers shows whether the load is rising or falling.
What is the difference between cron and a systemd timer, and which should I choose?
cron is simpler (one line), familiar and available everywhere, but it misses jobs if the server is off at the scheduled time and doesn't log automatically. A systemd timer is more complex (it needs two files), but it logs to journald, supports running missed jobs through Persistent=true, and integrates with service dependencies. Choose cron for simple jobs, and a timer for critical jobs that must not be missed or that need reliable tracking.
How do I stop a system service properly instead of killing its processes?
Don't chase the PID with kill, because systemd will restart the service immediately, since its job is to keep it alive. The right way is systemctl stop nginx to stop it temporarily, or systemctl disable --now nginx to stop it and prevent it from starting at boot. To prevent it from running at all, even manually, use systemctl mask, and unmask to lift the lock.