Intermediate LevelLinux Commands & SysAdmin
How do you create a custom systemd service unit file (/etc/systemd/system/myapp.service)?
❓ Interview Prompt: Explain systemd unit files, [Unit], [Service] (ExecStart, Restart=always, User, EnvironmentFile), [Install], and daemon-reload.
Custom background daemons are managed by creating a systemd unit file in '/etc/systemd/system/myapp.service':
Key Sections:
•
[Unit]: Description and dependencies ('After=network.target').
•
[Service]: Execution path ('ExecStart'), service user ('User=deploy'), environment variables, and auto-restart policy ('Restart=always').
•
[Install]: Boot target ('WantedBy=multi-user.target').
Code Implementation Example
ini
# /etc/systemd/system/node-app.service
[Unit]
Description=Node.js API Application
After=network.target postgresql.service
[Service]
Type=simple
User=deploy
WorkingDirectory=/var/www/node-app
ExecStart=/usr/bin/node server.js
Restart=always
RestartSec=5
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target💡Custom systemd service unit file configuration for background Node.js application.
🎯 Interview Key Takeaway
Create systemd service unit files under /etc/systemd/system/ and run systemctl daemon-reload to manage custom background daemons.
#systemd#Service Unit#sysadmin#Intermediate
Back to all Linux Commands & SysAdmin Questions→