mihaelisaev/swiftsystemd
#### Support this lib by giving a ⭐️
How to install
To install systemd as a SwiftPM plugin, first add the following line to your Package.swift file:
.package(url: "https://github.com/MihaelIsaev/SwiftSystemd.git", from:"1.0.0")Usage
The purpose of systemd is to run your app as a daemon and monitor it.
The first step is to generate the appropriate config file and save it.
🛠️ Install
swift run systemd installIt will prompt you with a few questions to generate and save the correct config file.
Or you could use parameters to predefine values
| Parameter | Description | |--------------|---------------------:| | -c,--config | Type of configuration: release or debug | | -t,--target | Executable target name | | -u,--user | User under which the service will run |
swift run systemd install -c release -t App -u mike It generates the following config file
[Unit]
Description="AppName"
After=network.target
[Service]
User={user}
EnvironmentFile=/path/to/AppName/.env
WorkingDirectory=/path/to/AppName
TimeoutStopSec=2
Restart=always
ExecStart=/path/to/AppName/.build/{config}/{target}
[Install]
WantedBy=multi-user.target💡 Please feel free to contribute your own config variations
🧹 Uninstall
swift run systemd uninstallDeletes the systemd configuration file and stops the service if it is active.
🍰 Start
swift run systemd startStarts your app using systemctl start
🔄 Restart
swift run systemd restartRestarts your app using systemctl restart
🛑 Stop
swift run systemd stopStops your app if it is running via systemd, using systemctl stop.
🟢 Enable
swift run systemd enableEnables the existing service configuration via systemctl enable.
🔴 Disable
swift run systemd disableDisables the existing service configuration via systemctl disable.
🔫 Kill
swift run systemd killSends kill signal to the running service via systemctl kill.
👀 Status
swift run systemd statusShows status of your app via systemctl status.
⚙️ Daemon Reload
swift run systemd daemon-reloadReloads all systemd services via systemctl daemon-reload.
📋 Logs
swift run systemd logsDisplays live logs of your app via journalctl.
swift run systemd logs --limit 100Displays the last 100 lines from your app's log via journalctl
Contributing
Please feel free to contribute!
Package Metadata
Repository: mihaelisaev/swiftsystemd
Default branch: master
README: README.md