channel systemd
lachlan edited this page Mar 29, 2020
·
6 revisions
It's pretty simple to set up a systemd unit file as a service so you can keep your channels running.
- Copy the example unit file below and edit to match your web path, web user and channel ID.
- Create the unit file (e.g. /etc/systemd/system/ampache-channel7.service)
- Enable the service
sudo systemctl unmask ampache-channel7
sudo systemctl enable ampache-channel7
- Start the service
sudo systemctl start ampache-channel7
- Check the status
root@web:~# systemctl status ampache-channel7
● ampache-channel7.service - channel7
Loaded: loaded (/etc/systemd/system/ampache-channel7.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2019-12-09 15:39:34 AEST; 8min ago
Docs: https://github.com/ampache/ampache/wiki/channel-systemd
Main PID: 24091 (php)
Tasks: 6 (limit: 4915)
Memory: 42.1M
CGroup: /system.slice/ampache-channel7.service
├─24091 /usr/bin/php bin/channel_run.inc -- -c 7 -v
└─24313 ffmpeg -i /mnt/music/The Grid/(1994) Evolver/105 - Rise.mp3 -vn -b:a 128K -c:a libmp3lame -f mp3 pipe:1
Dec 09 15:39:34 web systemd[1]: Started rebelradio.
Dec 09 15:39:34 web php[24091]: Starting Channel...
Dec 09 15:39:34 web php[24091]: Channel 7
Dec 09 15:39:34 web php[24091]: Verbose
Dec 09 15:45:00 web php[24091]: Listening on 0.0.0.0:8202
Dec 09 15:45:00 web php[24091]: Client connected
Dec 09 15:45:00 web php[24091]: Client disconnected
- Enjoy!
This unit file will run channel 7 from the /var/www/html folder. Set your correct channel (and update the PID file to match)
[Unit]
Description=channel7
After=network.target remote-fs.target nss-lookup.target
Documentation=https://github.com/ampache/ampache/wiki/channel-systemd
[Service]
PrivateTmp=true
KillMode=mixed
Type=simple
User=www-data
Group=www-data
Restart=always
RestartSec=3
ExecStart= php bin/channel_run.inc -- -c 7 -v
PIDFile=/run/php/ampache7.pid
ExecReload=/bin/kill -HUP $MAINPID
WorkingDirectory=/var/www/html
ProtectSystem=yes
[Install]
WantedBy=multi-user.target
There is currently a few issues keeping channels from running continuously. an easy way around this is to just restart the channels each night using a timer and a restart service.
[Unit]
Description=restart channel_run.service
[Timer]
OnCalendar=23:23:00
Unit=channel_restart.service
[Install]
WantedBy=timer.target
[Unit]
Description=restart channel_run.service
[Service]
Type=oneshot
ExecStart=systemctl restart channel_run.service
To enable the service unmask the service and enable the timer
systemctl unmask channel_run.service
systemctl unmask channel_run.timer
systemctl enable channel_run.timer
systemctl start channel_run.timer