Score:0

Linux make file executable inside service

ch flag

I do have service looking like this:

[Unit]
Description=API environment service

[Service]
WorkingDirectory=/var/www/api
ExecStart=/var/www/api/api
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=apache
Environment=ASPNETCORE_ENVIRONMENT=Production 

[Install]

Service works but every time I copy new files to that folder through ftp I need to run sudo chmod +x /var/www/api/api to make that file executable and then do sudo systemctl restart api.service

My question is is it possible to somehow add line at top of this service which will make this file executable if it is not so i only need to run restart command?

Michael Hampton avatar
cz flag
Your FTP client should already make it executable for you.
Aleksa Ristic avatar
ch flag
Nope it doesnt. I tried deleting everything, adding files again and restarting service it does not work. Then i make it executable and restart service and it does indeed work
George Y avatar
vn flag
I can solve only part of your problem - do not run the executable directly, but run a bash script which runs it. Therefore even you need to retype `chmod +x /var/www/api/api` you do not need to restart the service.
in flag
Following @GeorgeY . For example, if `api` binary is `python` replace `ExecStart=/var/www/api/api` by `ExecStart=/bin/bash -c "/usr/bin/python3 /var/www/api/api"` so you don't need to have it executable.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.