nugetd
This commit is contained in:
111
contrib/nugetd
Normal file
111
contrib/nugetd
Normal file
@ -0,0 +1,111 @@
|
||||
#!/bin/bash
|
||||
### BEGIN INIT INFO
|
||||
# Provides: nugetd
|
||||
# Required-Start: $local_fs $network $named $time $syslog $postgresql
|
||||
# Required-Stop: $local_fs $network $named $time $syslog $postgresql
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Description: Script to run asp.net 5 application in background
|
||||
### END INIT INFO
|
||||
|
||||
# Author: Ivan Derevianko aka druss <drussilla7@gmail.com>
|
||||
# Modified by: Paul Schneider <redienhcs.luap@gmail.com>
|
||||
|
||||
. /lib/init/vars.sh
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
NAME=nugetd
|
||||
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
||||
CONFIGS="/etc/kestrel/*.webenv"
|
||||
|
||||
TMP_SAVE_runlevel_VAR=$runlevel
|
||||
unset runlevel
|
||||
|
||||
running() {
|
||||
if [ -f $PIDFILE ]
|
||||
then
|
||||
PID=$(cat $PIDFILE)
|
||||
if kill -0 $PID 2>/dev/null
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
export WWW_USER=www-data
|
||||
export ROOT=/srv/www/nuget
|
||||
export DESC="$NAME"
|
||||
export PIDFILE=/var/run/kestrel-${NAME}.pid
|
||||
export LOGDIR=/var/log
|
||||
export DOTNET_CLI_HOME=$ROOT
|
||||
export ASPDOTNETCORE_ENVIRONMENT=Production
|
||||
export ASPDOTNETCORE_LOGLEVEL=Information
|
||||
status() {
|
||||
if running;
|
||||
then
|
||||
echo "Service running $DESC ($NAME; pid: $PID)"
|
||||
else
|
||||
echo "Service stopped $DESC ($NAME)"
|
||||
fi
|
||||
echo WWW_USER: $WWW_USER ROOT:$ROOT DESC: $DESC NAME: $NAME PIDFILE: $PIDFILE LOGDIR=$LOGDIR
|
||||
}
|
||||
|
||||
|
||||
start() {
|
||||
if running; then
|
||||
echo "Service already running $DESC" "$NAME"
|
||||
log_end_msg 0
|
||||
else
|
||||
cd $ROOT
|
||||
log_daemon_msg "Starting service $NAME for user $WWW_USER"
|
||||
if ! start-stop-daemon -SbmCv -u $WWW_USER -p $PIDFILE -d $ROOT -g www-data -x /usr/bin/dotnet nuget-host.dll run > "${LOGDIR}/kestrel-${NAME}.log"
|
||||
then
|
||||
log_daemon_msg "Could not start $NAME : $?, see ${LOGDIR}/kestrel-${NAME}.log"
|
||||
log_end_msg 2
|
||||
else
|
||||
log_daemon_msg "Service $DESC started ($NAME), logs: ${LOGDIR}/kestrel-${NAME}.log"
|
||||
log_end_msg 0
|
||||
fi
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
stop() {
|
||||
if running
|
||||
then
|
||||
log_daemon_msg "Stopping service $NAME"
|
||||
start-stop-daemon -K -p "$PIDFILE"
|
||||
log_daemon_msg "$DESC stopped"
|
||||
log_end_msg 0
|
||||
else
|
||||
log_daemon_msg "$DESC Service not running"
|
||||
log_end_msg 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
restart)
|
||||
stop
|
||||
start
|
||||
;;
|
||||
status)
|
||||
status
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart}"
|
||||
esac
|
||||
|
||||
export runlevel=$TMP_SAVE_runlevel_VAR
|
||||
|
||||
|
@ -51,5 +51,9 @@ namespace nuget_host.Controllers
|
||||
return Ok(ViewData);
|
||||
}
|
||||
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,19 +87,18 @@ namespace nuget_host.Controllers
|
||||
string pkgpath = Path.Combine(pkgidpath, version.ToFullString());
|
||||
string name = $"{pkgid}-{version}.nupkg";
|
||||
string fullpath = Path.Combine(pkgpath, name);
|
||||
Package package;
|
||||
|
||||
var destpkgiddir = new DirectoryInfo(pkgidpath);
|
||||
if (destpkgiddir.Exists)
|
||||
Package package = dbContext.Packages.SingleOrDefault(p => p.Id == pkgid);
|
||||
if (package != null)
|
||||
{
|
||||
package = dbContext.Packages.SingleOrDefault(p => p.Id == pkgid);
|
||||
if (package != null) if (package.OwnerId != apikey.UserId)
|
||||
{
|
||||
return new ForbidResult();
|
||||
}
|
||||
if (package.OwnerId != apikey.UserId)
|
||||
{
|
||||
return new ForbidResult();
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
destpkgiddir.Create();
|
||||
package = new Package
|
||||
{
|
||||
Id = pkgid,
|
||||
@ -108,6 +107,7 @@ namespace nuget_host.Controllers
|
||||
};
|
||||
dbContext.Packages.Add(package);
|
||||
}
|
||||
if (!destpkgiddir.Exists) destpkgiddir.Create();
|
||||
|
||||
var source = new FileInfo(initpath);
|
||||
var dest = new FileInfo(fullpath);
|
||||
@ -137,6 +137,7 @@ namespace nuget_host.Controllers
|
||||
await dbContext.SaveChangesAsync();
|
||||
logger.LogInformation($"new package : {entry.Name}");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -146,7 +147,9 @@ namespace nuget_host.Controllers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ObjectResult(new { ViewData, ex.Message, ex.StackTrace })
|
||||
logger.LogError(ex.Message);
|
||||
logger.LogError("Stack Trace: "+ ex.StackTrace);
|
||||
return new ObjectResult(new { ViewData, ex.Message})
|
||||
{ StatusCode = 500 };
|
||||
}
|
||||
}
|
||||
|
@ -69,20 +69,22 @@ namespace nuget_host
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
// app.UseExceptionHandler("/Home/Error");
|
||||
app.UseDeveloperExceptionPage();
|
||||
dbContext.Database.Migrate();
|
||||
}
|
||||
|
||||
app.UseStatusCodePages();
|
||||
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseAuthentication();
|
||||
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
routes.MapRoute(
|
||||
name: "default",
|
||||
template: "{controller=Home}/{action=Index}/{id?}");
|
||||
template: "{controller=PackageVersion}/{action=Index}/{PackageId?}");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
4
src/nuget-host/Views/Home/Error.cshtml
Normal file
4
src/nuget-host/Views/Home/Error.cshtml
Normal file
@ -0,0 +1,4 @@
|
||||
@{
|
||||
ViewData["Title"] = "Error";
|
||||
}
|
||||
|
Reference in New Issue
Block a user